Don't use "arrays" in lib/compiler/passes/generate-js.js

The "arrays" module will be removed.

See #442.
redux
David Majda 8 years ago
parent 33f23ee4be
commit 8f8484b1a1

@ -1,7 +1,6 @@
"use strict"; "use strict";
let arrays = require("../../utils/arrays"), let objects = require("../../utils/objects"),
objects = require("../../utils/objects"),
asts = require("../asts"), asts = require("../asts"),
op = require("../opcodes"), op = require("../opcodes"),
js = require("../js"); js = require("../js");
@ -408,7 +407,9 @@ function generateJS(ast, options) {
} }
function generateRuleFunction(rule) { function generateRuleFunction(rule) {
let parts = [], code; let parts = [],
stackVars = [],
code;
function c(i) { return "peg$c" + i; } // |consts[i]| of the abstract machine 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 function s(i) { return "s" + i; } // |stack[i]| of the abstract machine
@ -429,7 +430,12 @@ function generateJS(ast, options) {
if (n === undefined) { if (n === undefined) {
return s(this.sp--); return s(this.sp--);
} else { } 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; this.sp -= n;
return values; return values;
@ -714,14 +720,18 @@ function generateJS(ast, options) {
parts.push('function peg$parse' + rule.name + '() {'); parts.push('function peg$parse' + rule.name + '() {');
for (let i = 0; i <= stack.maxSp; i++) {
stackVars[i] = s(i);
}
if (options.trace) { if (options.trace) {
parts.push([ parts.push([
' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ',', ' var ' + stackVars.join(', ') + ',',
' startPos = peg$currPos;' ' startPos = peg$currPos;'
].join('\n')); ].join('\n'));
} else { } else {
parts.push( parts.push(
' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ';' ' var ' + stackVars.join(', ') + ';'
); );
} }

Loading…
Cancel
Save