Skip to content

Commit

Permalink
Merge pull request #113 from Mingun/simplify-bc
Browse files Browse the repository at this point in the history
Simplify bytecode: remove unnecessary opcode
  • Loading branch information
hildjj authored Apr 23, 2021
2 parents 3d8ff0c + 8996c73 commit 375a8f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 70 deletions.
5 changes: 2 additions & 3 deletions lib/compiler/passes/generate-bytecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
93 changes: 31 additions & 62 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions test/unit/compiler/passes/generate-bytecode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, // <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
Expand Down

0 comments on commit 375a8f1

Please sign in to comment.