Skip to content

Commit

Permalink
pegjs#30: remove usage of BREAK opcode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Sep 20, 2013
1 parent 8997f19 commit 292a4bf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/compiler/passes/generate-bytecode.js
Expand Up @@ -571,19 +571,19 @@ module.exports = function(ast, options) {
[op.PUSH, maxIndex], // stack:[ [elem...], min ]
buildCondition( // if (max !== undefined && result.length >= max)
[op.IF_ARRLEN_MAX], // stack:[ [elem...] ]
[op.BREAK, 0], [] // break;
),
expressionCode // elem = expr(); stack:[ [elem...], elem ]
[op.PUSH, nullIndex], // elem = null; stack:[ [elem...], null ]
expressionCode // else
) // elem = expr(); stack:[ [elem...], elem ]
)
); // } stack:[ [elem...], elem ]
var placeholderOffset = 2 + 1 + 2 + 3;
// var placeholderOffset = 2 + 1 + 2 + 3;
// ^ ^ ^ ^
// | | | '- op.IF_ARRLEN_MAX + `then` len + `else` len
// | | '----- op.PUSH, maxIndex
// | '--------- op.APPEND
// '------------- op.WHILE_NOT_ERROR + loop body len
// Replace placeholder after op.BREAK to offset to breakable instruction.
loopCode[placeholderOffset+1] = -placeholderOffset;// Go to op.WHILE_NOT_ERROR
// loopCode[placeholderOffset+1] = -placeholderOffset;// Go to op.WHILE_NOT_ERROR

return buildSequence(
[op.PUSH, emptyArrayIndex], // var result = [] stack:[ [] ]
Expand Down

0 comments on commit 292a4bf

Please sign in to comment.