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";
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(', ') + ';'
);
}

Loading…
Cancel
Save