diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index ff0a467e..a1edc9a6 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -427,11 +427,10 @@ function generateBytecode(ast) { [op.LOAD_SAVED_POS, node.elements.length], buildCall( functionIndex, - node.elements.length, + node.elements.length + 1, context.env, context.sp - ), - [op.NIP] + ) ); } else { return buildSequence([op.WRAP, node.elements.length], [op.NIP]); diff --git a/lib/parser.js b/lib/parser.js index 4aa2f01d..7ffbe47e 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -756,8 +756,7 @@ function peg$parse(input, options) { } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c0(s2, s3, s4); - s0 = s1; + s0 = peg$c0(s2, s3, s4); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -803,8 +802,7 @@ function peg$parse(input, options) { s4 = peg$parseEOS(); if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c5(s2); - s0 = s1; + s0 = peg$c5(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -834,8 +832,7 @@ function peg$parse(input, options) { s2 = peg$parseEOS(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c6(s1); - s0 = s1; + s0 = peg$c6(s1); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -890,8 +887,7 @@ function peg$parse(input, options) { s7 = peg$parseEOS(); if (s7 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c9(s1, s3, s6); - s0 = s1; + s0 = peg$c9(s1, s3, s6); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1002,8 +998,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c12(s1, s2); - s0 = s1; + s0 = peg$c12(s1, s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1042,8 +1037,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c13(s1, s2); - s0 = s1; + s0 = peg$c13(s1, s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1098,8 +1092,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c14(s1, s2); - s0 = s1; + s0 = peg$c14(s1, s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1132,8 +1125,7 @@ function peg$parse(input, options) { s3 = peg$parsePrefixedExpression(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c17(s2, s3); - s0 = s1; + s0 = peg$c17(s2, s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1155,8 +1147,7 @@ function peg$parse(input, options) { s3 = peg$parsePrefixedExpression(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c18(s1, s3); - s0 = s1; + s0 = peg$c18(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1221,8 +1212,7 @@ function peg$parse(input, options) { s3 = peg$parseSuffixedExpression(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c21(s1, s3); - s0 = s1; + s0 = peg$c21(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1285,8 +1275,7 @@ function peg$parse(input, options) { s3 = peg$parseSuffixedOperator(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c28(s1, s3); - s0 = s1; + s0 = peg$c28(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1375,8 +1364,7 @@ function peg$parse(input, options) { } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c39(s3); - s0 = s1; + s0 = peg$c39(s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1467,8 +1455,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c40(s1); - s0 = s1; + s0 = peg$c40(s1); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1492,8 +1479,7 @@ function peg$parse(input, options) { s3 = peg$parseCodeBlock(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c41(s1, s3); - s0 = s1; + s0 = peg$c41(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2038,8 +2024,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c77(s1, s2); - s0 = s1; + s0 = peg$c77(s1, s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2090,8 +2075,7 @@ function peg$parse(input, options) { s2 = peg$parseUnicodeEscapeSequence(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c82(s2); - s0 = s1; + s0 = peg$c82(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2332,8 +2316,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c90(s1, s2); - s0 = s1; + s0 = peg$c90(s1, s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2380,8 +2363,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c94(s2); - s0 = s1; + s0 = peg$c94(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2420,8 +2402,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c94(s2); - s0 = s1; + s0 = peg$c94(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2480,8 +2461,7 @@ function peg$parse(input, options) { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c97(); - s0 = s1; + s0 = peg$c97(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2503,8 +2483,7 @@ function peg$parse(input, options) { s2 = peg$parseEscapeSequence(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c82(s2); - s0 = s1; + s0 = peg$c82(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2557,8 +2536,7 @@ function peg$parse(input, options) { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c97(); - s0 = s1; + s0 = peg$c97(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2580,8 +2558,7 @@ function peg$parse(input, options) { s2 = peg$parseEscapeSequence(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c82(s2); - s0 = s1; + s0 = peg$c82(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2655,8 +2632,7 @@ function peg$parse(input, options) { } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c105(s2, s3, s5); - s0 = s1; + s0 = peg$c105(s2, s3, s5); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2703,8 +2679,7 @@ function peg$parse(input, options) { s3 = peg$parseClassCharacter(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c108(s1, s3); - s0 = s1; + s0 = peg$c108(s1, s3); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2757,8 +2732,7 @@ function peg$parse(input, options) { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c97(); - s0 = s1; + s0 = peg$c97(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2811,8 +2785,7 @@ function peg$parse(input, options) { s2 = peg$parseLineTerminatorSequence(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c109(); - s0 = s1; + s0 = peg$c109(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -2851,8 +2824,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c112(); - s0 = s1; + s0 = peg$c112(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -3026,8 +2998,7 @@ function peg$parse(input, options) { s2 = peg$parseSourceCharacter(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c97(); - s0 = s1; + s0 = peg$c97(); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -3104,8 +3075,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c135(s2); - s0 = s1; + s0 = peg$c135(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -3165,8 +3135,7 @@ function peg$parse(input, options) { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c135(s2); - s0 = s1; + s0 = peg$c135(s2); } else { peg$currPos = s0; s0 = peg$FAILED; diff --git a/test/unit/compiler/passes/generate-bytecode.spec.js b/test/unit/compiler/passes/generate-bytecode.spec.js index 38495b13..f12362ad 100644 --- a/test/unit/compiler/passes/generate-bytecode.spec.js +++ b/test/unit/compiler/passes/generate-bytecode.spec.js @@ -188,14 +188,13 @@ describe("compiler pass |generateBytecode|", function() { expect(pass).to.changeAST(grammar, bytecodeDetails([ 5, // PUSH_CURR_POS 18, 0, 2, 2, 22, 0, 23, 1, // - 15, 40, 3, // IF_NOT_ERROR + 15, 39, 3, // IF_NOT_ERROR 18, 2, 2, 2, 22, 2, 23, 3, // * - 15, 25, 4, // IF_NOT_ERROR + 15, 24, 4, // IF_NOT_ERROR 18, 4, 2, 2, 22, 4, 23, 5, // * - 15, 10, 4, // IF_NOT_ERROR + 15, 9, 4, // IF_NOT_ERROR 24, 3, // * LOAD_SAVED_POS - 26, 6, 3, 3, 2, 1, 0, // CALL - 9, // NIP + 26, 6, 4, 3, 2, 1, 0, // CALL <6> 8, 3, // * POP_N 7, // POP_CURR_POS 3, // PUSH_FAILED