Simplify bytecode: remove unnecessary opcode.

Now generated sources looks little better :)
master
Mingun 7 years ago
parent 03912dc761
commit 575db38d1f

@ -407,11 +407,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]);

@ -688,8 +688,7 @@ function peg$parse(input, options) {
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s2, s3);
s0 = s1;
s0 = peg$c0(s2, s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -715,8 +714,7 @@ function peg$parse(input, options) {
s2 = peg$parseEOS();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c1(s1);
s0 = s1;
s0 = peg$c1(s1);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -771,8 +769,7 @@ function peg$parse(input, options) {
s7 = peg$parseEOS();
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c4(s1, s3, s6);
s0 = s1;
s0 = peg$c4(s1, s3, s6);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -883,8 +880,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c7(s1, s2);
s0 = s1;
s0 = peg$c7(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -923,8 +919,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c8(s1, s2);
s0 = s1;
s0 = peg$c8(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -979,8 +974,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c9(s1, s2);
s0 = s1;
s0 = peg$c9(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1014,8 +1008,7 @@ function peg$parse(input, options) {
s5 = peg$parsePrefixedExpression();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c12(s1, s5);
s0 = s1;
s0 = peg$c12(s1, s5);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1054,8 +1047,7 @@ function peg$parse(input, options) {
s3 = peg$parseSuffixedExpression();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c13(s1, s3);
s0 = s1;
s0 = peg$c13(s1, s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1118,8 +1110,7 @@ function peg$parse(input, options) {
s3 = peg$parseSuffixedOperator();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c20(s1, s3);
s0 = s1;
s0 = peg$c20(s1, s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1208,8 +1199,7 @@ function peg$parse(input, options) {
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c31(s3);
s0 = s1;
s0 = peg$c31(s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1300,8 +1290,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c32(s1);
s0 = s1;
s0 = peg$c32(s1);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1325,8 +1314,7 @@ function peg$parse(input, options) {
s3 = peg$parseCodeBlock();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c33(s1, s3);
s0 = s1;
s0 = peg$c33(s1, s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1844,8 +1832,7 @@ function peg$parse(input, options) {
s2 = peg$parseIdentifierName();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c68(s2);
s0 = s1;
s0 = peg$c68(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1873,8 +1860,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c70(s1, s2);
s0 = s1;
s0 = peg$c70(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -1925,8 +1911,7 @@ function peg$parse(input, options) {
s2 = peg$parseUnicodeEscapeSequence();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c75(s2);
s0 = s1;
s0 = peg$c75(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2167,8 +2152,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c83(s1, s2);
s0 = s1;
s0 = peg$c83(s1, s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2215,8 +2199,7 @@ function peg$parse(input, options) {
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c87(s2);
s0 = s1;
s0 = peg$c87(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2255,8 +2238,7 @@ function peg$parse(input, options) {
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c87(s2);
s0 = s1;
s0 = peg$c87(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2315,8 +2297,7 @@ function peg$parse(input, options) {
s2 = peg$parseSourceCharacter();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c90();
s0 = s1;
s0 = peg$c90();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2338,8 +2319,7 @@ function peg$parse(input, options) {
s2 = peg$parseEscapeSequence();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c75(s2);
s0 = s1;
s0 = peg$c75(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2392,8 +2372,7 @@ function peg$parse(input, options) {
s2 = peg$parseSourceCharacter();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c90();
s0 = s1;
s0 = peg$c90();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2415,8 +2394,7 @@ function peg$parse(input, options) {
s2 = peg$parseEscapeSequence();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c75(s2);
s0 = s1;
s0 = peg$c75(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2490,8 +2468,7 @@ function peg$parse(input, options) {
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c98(s2, s3, s5);
s0 = s1;
s0 = peg$c98(s2, s3, s5);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2538,8 +2515,7 @@ function peg$parse(input, options) {
s3 = peg$parseClassCharacter();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c101(s1, s3);
s0 = s1;
s0 = peg$c101(s1, s3);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2592,8 +2568,7 @@ function peg$parse(input, options) {
s2 = peg$parseSourceCharacter();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c90();
s0 = s1;
s0 = peg$c90();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2615,8 +2590,7 @@ function peg$parse(input, options) {
s2 = peg$parseEscapeSequence();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c75(s2);
s0 = s1;
s0 = peg$c75(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2648,8 +2622,7 @@ function peg$parse(input, options) {
s2 = peg$parseLineTerminatorSequence();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c102();
s0 = s1;
s0 = peg$c102();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2688,8 +2661,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c105();
s0 = s1;
s0 = peg$c105();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2863,8 +2835,7 @@ function peg$parse(input, options) {
s2 = peg$parseSourceCharacter();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c90();
s0 = s1;
s0 = peg$c90();
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -2941,8 +2912,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c128(s2);
s0 = s1;
s0 = peg$c128(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -3002,8 +2972,7 @@ function peg$parse(input, options) {
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c128(s2);
s0 = s1;
s0 = peg$c128(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
@ -3088,8 +3057,7 @@ function peg$parse(input, options) {
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c141(s2);
s0 = s1;
s0 = peg$c141(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;

@ -146,14 +146,13 @@ describe("compiler pass |generateBytecode|", function() {
expect(pass).to.changeAST(grammar, bytecodeDetails([
5, // PUSH_CURR_POS
18, 0, 2, 2, 22, 0, 23, 1, // <elements[0]>
15, 40, 3, // IF_NOT_ERROR
15, 39, 3, // IF_NOT_ERROR
18, 2, 2, 2, 22, 2, 23, 3, // * <elements[1]>
15, 25, 4, // IF_NOT_ERROR
15, 24, 4, // IF_NOT_ERROR
18, 4, 2, 2, 22, 4, 23, 5, // * <elements[2]>
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

Loading…
Cancel
Save