From 8f8484b1a15cc4ad4a505f4723c5e474cda10019 Mon Sep 17 00:00:00 2001 From: David Majda Date: Wed, 14 Sep 2016 09:41:02 +0200 Subject: [PATCH] Don't use "arrays" in lib/compiler/passes/generate-js.js The "arrays" module will be removed. See #442. --- lib/compiler/passes/generate-js.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index b4ef9b2..b7563ee 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -1,7 +1,6 @@ "use strict"; -let arrays = require("../../utils/arrays"), - objects = require("../../utils/objects"), +let objects = require("../../utils/objects"), asts = require("../asts"), op = require("../opcodes"), js = require("../js"); @@ -408,7 +407,9 @@ function generateJS(ast, options) { } function generateRuleFunction(rule) { - let parts = [], code; + let parts = [], + stackVars = [], + code; function c(i) { return "peg$c" + i; } // |consts[i]| of the abstract machine function s(i) { return "s" + i; } // |stack[i]| of the abstract machine @@ -429,7 +430,12 @@ function generateJS(ast, options) { if (n === undefined) { return s(this.sp--); } else { - let values = arrays.range(this.sp - n + 1, this.sp + 1).map(s); + let values = Array(n); + + for (var i = 0; i < n; i++) { + values[i] = s(this.sp - n + 1 + i); + } + this.sp -= n; return values; @@ -714,14 +720,18 @@ function generateJS(ast, options) { parts.push('function peg$parse' + rule.name + '() {'); + for (let i = 0; i <= stack.maxSp; i++) { + stackVars[i] = s(i); + } + if (options.trace) { parts.push([ - ' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ',', + ' var ' + stackVars.join(', ') + ',', ' startPos = peg$currPos;' ].join('\n')); } else { parts.push( - ' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ';' + ' var ' + stackVars.join(', ') + ';' ); }