From a4772376fbbb79127bb6c36852e2d54ee13dfd34 Mon Sep 17 00:00:00 2001 From: David Majda Date: Tue, 18 Aug 2015 10:57:50 +0200 Subject: [PATCH] Renumber bytecode instructions sequentially --- lib/compiler/opcodes.js | 58 +-- lib/compiler/passes/generate-bytecode.js | 58 +-- .../compiler/passes/generate-bytecode.spec.js | 398 +++++++++--------- 3 files changed, 257 insertions(+), 257 deletions(-) diff --git a/lib/compiler/opcodes.js b/lib/compiler/opcodes.js index 5d88242..7b89496 100644 --- a/lib/compiler/opcodes.js +++ b/lib/compiler/opcodes.js @@ -5,50 +5,50 @@ var opcodes = { /* Stack Manipulation */ PUSH: 0, // PUSH c - PUSH_UNDEFINED: 26, // PUSH_UNDEFINED - PUSH_NULL: 27, // PUSH_NULL - PUSH_FAILED: 28, // PUSH_FAILED - PUSH_EMPTY_ARRAY: 29, // PUSH_EMPTY_ARRAY - PUSH_CURR_POS: 1, // PUSH_CURR_POS - POP: 2, // POP - POP_CURR_POS: 3, // POP_CURR_POS - POP_N: 4, // POP_N n - NIP: 5, // NIP - APPEND: 6, // APPEND - WRAP: 7, // WRAP n - TEXT: 8, // TEXT + PUSH_UNDEFINED: 1, // PUSH_UNDEFINED + PUSH_NULL: 2, // PUSH_NULL + PUSH_FAILED: 3, // PUSH_FAILED + PUSH_EMPTY_ARRAY: 4, // PUSH_EMPTY_ARRAY + PUSH_CURR_POS: 5, // PUSH_CURR_POS + POP: 6, // POP + POP_CURR_POS: 7, // POP_CURR_POS + POP_N: 8, // POP_N n + NIP: 9, // NIP + APPEND: 10, // APPEND + WRAP: 11, // WRAP n + TEXT: 12, // TEXT /* Conditions and Loops */ - IF: 9, // IF t, f - IF_ERROR: 10, // IF_ERROR t, f - IF_NOT_ERROR: 11, // IF_NOT_ERROR t, f - WHILE_NOT_ERROR: 12, // WHILE_NOT_ERROR b + IF: 13, // IF t, f + IF_ERROR: 14, // IF_ERROR t, f + IF_NOT_ERROR: 15, // IF_NOT_ERROR t, f + WHILE_NOT_ERROR: 16, // WHILE_NOT_ERROR b /* Matching */ - MATCH_ANY: 13, // MATCH_ANY a, f, ... - MATCH_STRING: 14, // MATCH_STRING s, a, f, ... - MATCH_STRING_IC: 15, // MATCH_STRING_IC s, a, f, ... - MATCH_REGEXP: 16, // MATCH_REGEXP r, a, f, ... - ACCEPT_N: 17, // ACCEPT_N n - ACCEPT_STRING: 18, // ACCEPT_STRING s - FAIL: 19, // FAIL e + MATCH_ANY: 17, // MATCH_ANY a, f, ... + MATCH_STRING: 18, // MATCH_STRING s, a, f, ... + MATCH_STRING_IC: 19, // MATCH_STRING_IC s, a, f, ... + MATCH_REGEXP: 20, // MATCH_REGEXP r, a, f, ... + ACCEPT_N: 21, // ACCEPT_N n + ACCEPT_STRING: 22, // ACCEPT_STRING s + FAIL: 23, // FAIL e /* Calls */ - LOAD_SAVED_POS: 20, // LOAD_SAVED_POS p - UPDATE_SAVED_POS: 21, // UPDATE_SAVED_POS - CALL: 22, // CALL f, n, pc, p1, p2, ..., pN + LOAD_SAVED_POS: 24, // LOAD_SAVED_POS p + UPDATE_SAVED_POS: 25, // UPDATE_SAVED_POS + CALL: 26, // CALL f, n, pc, p1, p2, ..., pN /* Rules */ - RULE: 23, // RULE r + RULE: 27, // RULE r /* Failure Reporting */ - SILENT_FAILS_ON: 24, // SILENT_FAILS_ON - SILENT_FAILS_OFF: 25 // SILENT_FAILS_FF + SILENT_FAILS_ON: 28, // SILENT_FAILS_ON + SILENT_FAILS_OFF: 29 // SILENT_FAILS_FF }; module.exports = opcodes; diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index eb41383..4aa401f 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -19,63 +19,63 @@ var arrays = require("../../utils/arrays"), * * stack.push(consts[c]); * - * [26] PUSH_UNDEFINED + * [1] PUSH_UNDEFINED * * stack.push(undefined); * - * [27] PUSH_NULL + * [2] PUSH_NULL * * stack.push(null); * - * [28] PUSH_FAILED + * [3] PUSH_FAILED * * stack.push(FAILED); * - * [29] PUSH_EMPTY_ARRAY + * [4] PUSH_EMPTY_ARRAY * * stack.push([]); * - * [1] PUSH_CURR_POS + * [5] PUSH_CURR_POS * * stack.push(currPos); * - * [2] POP + * [6] POP * * stack.pop(); * - * [3] POP_CURR_POS + * [7] POP_CURR_POS * * currPos = stack.pop(); * - * [4] POP_N n + * [8] POP_N n * * stack.pop(n); * - * [5] NIP + * [9] NIP * * value = stack.pop(); * stack.pop(); * stack.push(value); * - * [6] APPEND + * [10] APPEND * * value = stack.pop(); * array = stack.pop(); * array.push(value); * stack.push(array); * - * [7] WRAP n + * [11] WRAP n * * stack.push(stack.pop(n)); * - * [8] TEXT + * [12] TEXT * * stack.push(input.substring(stack.pop(), currPos)); * * Conditions and Loops * -------------------- * - * [9] IF t, f + * [13] IF t, f * * if (stack.top()) { * interpret(ip + 3, ip + 3 + t); @@ -83,7 +83,7 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 3 + t, ip + 3 + t + f); * } * - * [10] IF_ERROR t, f + * [14] IF_ERROR t, f * * if (stack.top() === FAILED) { * interpret(ip + 3, ip + 3 + t); @@ -91,7 +91,7 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 3 + t, ip + 3 + t + f); * } * - * [11] IF_NOT_ERROR t, f + * [15] IF_NOT_ERROR t, f * * if (stack.top() !== FAILED) { * interpret(ip + 3, ip + 3 + t); @@ -99,7 +99,7 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 3 + t, ip + 3 + t + f); * } * - * [12] WHILE_NOT_ERROR b + * [16] WHILE_NOT_ERROR b * * while(stack.top() !== FAILED) { * interpret(ip + 2, ip + 2 + b); @@ -108,7 +108,7 @@ var arrays = require("../../utils/arrays"), * Matching * -------- * - * [13] MATCH_ANY a, f, ... + * [17] MATCH_ANY a, f, ... * * if (input.length > currPos) { * interpret(ip + 3, ip + 3 + a); @@ -116,7 +116,7 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 3 + a, ip + 3 + a + f); * } * - * [14] MATCH_STRING s, a, f, ... + * [18] MATCH_STRING s, a, f, ... * * if (input.substr(currPos, consts[s].length) === consts[s]) { * interpret(ip + 4, ip + 4 + a); @@ -124,7 +124,7 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 4 + a, ip + 4 + a + f); * } * - * [15] MATCH_STRING_IC s, a, f, ... + * [19] MATCH_STRING_IC s, a, f, ... * * if (input.substr(currPos, consts[s].length).toLowerCase() === consts[s]) { * interpret(ip + 4, ip + 4 + a); @@ -132,7 +132,7 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 4 + a, ip + 4 + a + f); * } * - * [16] MATCH_REGEXP r, a, f, ... + * [20] MATCH_REGEXP r, a, f, ... * * if (consts[r].test(input.charAt(currPos))) { * interpret(ip + 4, ip + 4 + a); @@ -140,17 +140,17 @@ var arrays = require("../../utils/arrays"), * interpret(ip + 4 + a, ip + 4 + a + f); * } * - * [17] ACCEPT_N n + * [21] ACCEPT_N n * * stack.push(input.substring(currPos, n)); * currPos += n; * - * [18] ACCEPT_STRING s + * [22] ACCEPT_STRING s * * stack.push(consts[s]); * currPos += consts[s].length; * - * [19] FAIL e + * [23] FAIL e * * stack.push(FAILED); * fail(consts[e]); @@ -158,15 +158,15 @@ var arrays = require("../../utils/arrays"), * Calls * ----- * - * [20] LOAD_SAVED_POS p + * [24] LOAD_SAVED_POS p * * savedPos = stack[p]; * - * [21] UPDATE_SAVED_POS + * [25] UPDATE_SAVED_POS * * savedPos = currPos; * - * [22] CALL f, n, pc, p1, p2, ..., pN + * [26] CALL f, n, pc, p1, p2, ..., pN * * value = consts[f](stack[p1], ..., stack[pN]); * stack.pop(n); @@ -175,18 +175,18 @@ var arrays = require("../../utils/arrays"), * Rules * ----- * - * [23] RULE r + * [27] RULE r * * stack.push(parseRule(r)); * * Failure Reporting * ----------------- * - * [24] SILENT_FAILS_ON + * [28] SILENT_FAILS_ON * * silentFails++; * - * [25] SILENT_FAILS_OFF + * [29] SILENT_FAILS_OFF * * silentFails--; */ diff --git a/spec/unit/compiler/passes/generate-bytecode.spec.js b/spec/unit/compiler/passes/generate-bytecode.spec.js index 710ed60..492285f 100644 --- a/spec/unit/compiler/passes/generate-bytecode.spec.js +++ b/spec/unit/compiler/passes/generate-bytecode.spec.js @@ -21,9 +21,9 @@ describe("compiler pass |generateBytecode|", function() { 'c = "c"' ].join("\n"), { rules: [ - { bytecode: [14, 0, 2, 2, 18, 0, 19, 1] }, - { bytecode: [14, 2, 2, 2, 18, 2, 19, 3] }, - { bytecode: [14, 4, 2, 2, 18, 4, 19, 5] } + { bytecode: [18, 0, 2, 2, 22, 0, 23, 1] }, + { bytecode: [18, 2, 2, 2, 22, 2, 23, 3] }, + { bytecode: [18, 4, 2, 2, 22, 4, 23, 5] } ] }); }); @@ -47,7 +47,7 @@ describe("compiler pass |generateBytecode|", function() { describe("for rule", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST('start = "a"', bytecodeDetails([ - 14, 0, 2, 2, 18, 0, 19, 1 // + 18, 0, 2, 2, 22, 0, 23, 1 // ])); }); }); @@ -57,11 +57,11 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 24, // SILENT_FAILS_ON - 14, 1, 2, 2, 18, 1, 19, 2, // - 25, // SILENT_FAILS_OFF - 10, 2, 0, // IF_ERROR - 19, 0 // * FAIL + 28, // SILENT_FAILS_ON + 18, 1, 2, 2, 22, 1, 23, 2, // + 29, // SILENT_FAILS_OFF + 14, 2, 0, // IF_ERROR + 23, 0 // * FAIL ])); }); @@ -77,13 +77,13 @@ describe("compiler pass |generateBytecode|", function() { describe("for choice", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST('start = "a" / "b" / "c"', bytecodeDetails([ - 14, 0, 2, 2, 18, 0, 19, 1, // - 10, 21, 0, // IF_ERROR - 2, // * POP - 14, 2, 2, 2, 18, 2, 19, 3, // - 10, 9, 0, // IF_ERROR - 2, // * POP - 14, 4, 2, 2, 18, 4, 19, 5 // + 18, 0, 2, 2, 22, 0, 23, 1, // + 14, 21, 0, // IF_ERROR + 6, // * POP + 18, 2, 2, 2, 22, 2, 23, 3, // + 14, 9, 0, // IF_ERROR + 6, // * POP + 18, 4, 2, 2, 22, 4, 23, 5 // ])); }); }); @@ -94,12 +94,12 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 6, 0, // IF_NOT_ERROR - 20, 1, // * LOAD_SAVED_POS - 22, 2, 1, 0, // CALL - 5 // NIP + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 6, 0, // IF_NOT_ERROR + 24, 1, // * LOAD_SAVED_POS + 26, 2, 1, 0, // CALL + 9 // NIP ])); }); @@ -117,12 +117,12 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 7, 0, // IF_NOT_ERROR - 20, 1, // * LOAD_SAVED_POS - 22, 2, 1, 1, 0, // CALL - 5 // NIP + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 7, 0, // IF_NOT_ERROR + 24, 1, // * LOAD_SAVED_POS + 26, 2, 1, 1, 0, // CALL + 9 // NIP ])); }); @@ -140,25 +140,25 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 40, 3, // IF_NOT_ERROR - 14, 2, 2, 2, 18, 2, 19, 3, // * - 11, 25, 4, // IF_NOT_ERROR - 14, 4, 2, 2, 18, 4, 19, 5, // * - 11, 10, 4, // IF_NOT_ERROR - 20, 3, // * LOAD_SAVED_POS - 22, 6, 3, 3, 2, 1, 0, // CALL - 5, // NIP - 4, 3, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 4, 2, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 2, // * POP - 3, // POP_CURR_POS - 28 // PUSH_FAILED + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 40, 3, // IF_NOT_ERROR + 18, 2, 2, 2, 22, 2, 23, 3, // * + 15, 25, 4, // IF_NOT_ERROR + 18, 4, 2, 2, 22, 4, 23, 5, // * + 15, 10, 4, // IF_NOT_ERROR + 24, 3, // * LOAD_SAVED_POS + 26, 6, 3, 3, 2, 1, 0, // CALL + 9, // NIP + 8, 3, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 8, 2, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 6, // * POP + 7, // POP_CURR_POS + 3 // PUSH_FAILED ])); }); @@ -181,24 +181,24 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 33, 3, // IF_NOT_ERROR - 14, 2, 2, 2, 18, 2, 19, 3, // * - 11, 18, 4, // IF_NOT_ERROR - 14, 4, 2, 2, 18, 4, 19, 5, // * - 11, 3, 4, // IF_NOT_ERROR - 7, 3, // * WRAP - 5, // NIP - 4, 3, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 4, 2, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 2, // * POP - 3, // POP_CURR_POS - 28 // PUSH_FAILED + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 33, 3, // IF_NOT_ERROR + 18, 2, 2, 2, 22, 2, 23, 3, // * + 15, 18, 4, // IF_NOT_ERROR + 18, 4, 2, 2, 22, 4, 23, 5, // * + 15, 3, 4, // IF_NOT_ERROR + 11, 3, // * WRAP + 9, // NIP + 8, 3, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 8, 2, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 6, // * POP + 7, // POP_CURR_POS + 3 // PUSH_FAILED ])); }); @@ -217,7 +217,7 @@ describe("compiler pass |generateBytecode|", function() { describe("for labeled", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST('start = a:"a"', bytecodeDetails([ - 14, 0, 2, 2, 18, 0, 19, 1 // + 18, 0, 2, 2, 22, 0, 23, 1 // ])); }); }); @@ -225,12 +225,12 @@ describe("compiler pass |generateBytecode|", function() { describe("for text", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST('start = $"a"', bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 2, 1, // IF_NOT_ERROR - 2, // * POP - 8, // TEXT - 5 // * NIP + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 2, 1, // IF_NOT_ERROR + 6, // * POP + 12, // TEXT + 9 // * NIP ])); }); }); @@ -240,17 +240,17 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 24, // SILENT_FAILS_ON - 14, 0, 2, 2, 18, 0, 19, 1, // - 25, // SILENT_FAILS_OFF - 11, 3, 3, // IF_NOT_ERROR - 2, // * POP - 3, // POP_CURR_POS - 26, // PUSH_UNDEFINED - 2, // * POP - 2, // POP - 28 // PUSH_FAILED + 5, // PUSH_CURR_POS + 28, // SILENT_FAILS_ON + 18, 0, 2, 2, 22, 0, 23, 1, // + 29, // SILENT_FAILS_OFF + 15, 3, 3, // IF_NOT_ERROR + 6, // * POP + 7, // POP_CURR_POS + 1, // PUSH_UNDEFINED + 6, // * POP + 6, // POP + 3 // PUSH_FAILED ])); }); @@ -267,17 +267,17 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 24, // SILENT_FAILS_ON - 14, 0, 2, 2, 18, 0, 19, 1, // - 25, // SILENT_FAILS_OFF - 10, 3, 3, // IF_ERROR - 2, // * POP - 2, // POP - 26, // PUSH_UNDEFINED - 2, // * POP - 3, // POP_CURR_POS - 28 // PUSH_FAILED + 5, // PUSH_CURR_POS + 28, // SILENT_FAILS_ON + 18, 0, 2, 2, 22, 0, 23, 1, // + 29, // SILENT_FAILS_OFF + 14, 3, 3, // IF_ERROR + 6, // * POP + 6, // POP + 1, // PUSH_UNDEFINED + 6, // * POP + 7, // POP_CURR_POS + 3 // PUSH_FAILED ])); }); @@ -294,10 +294,10 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 14, 0, 2, 2, 18, 0, 19, 1, // - 10, 2, 0, // IF_ERROR - 2, // * POP - 27 // PUSH_NULL + 18, 0, 2, 2, 22, 0, 23, 1, // + 14, 2, 0, // IF_ERROR + 6, // * POP + 2 // PUSH_NULL ])); }); @@ -314,12 +314,12 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 29, // PUSH_EMPTY_ARRAY - 14, 0, 2, 2, 18, 0, 19, 1, // - 12, 9, // WHILE_NOT_ERROR - 6, // * APPEND - 14, 0, 2, 2, 18, 0, 19, 1, // - 2 // POP + 4, // PUSH_EMPTY_ARRAY + 18, 0, 2, 2, 22, 0, 23, 1, // + 16, 9, // WHILE_NOT_ERROR + 10, // * APPEND + 18, 0, 2, 2, 22, 0, 23, 1, // + 6 // POP ])); }); @@ -336,16 +336,16 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 29, // PUSH_EMPTY_ARRAY - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 12, 3, // IF_NOT_ERROR - 12, 9, // * WHILE_NOT_ERROR - 6, // * APPEND - 14, 0, 2, 2, 18, 0, 19, 1, // - 2, // POP - 2, // * POP - 2, // POP - 28 // PUSH_FAILED + 4, // PUSH_EMPTY_ARRAY + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 12, 3, // IF_NOT_ERROR + 16, 9, // * WHILE_NOT_ERROR + 10, // * APPEND + 18, 0, 2, 2, 22, 0, 23, 1, // + 6, // POP + 6, // * POP + 6, // POP + 3 // PUSH_FAILED ])); }); @@ -363,13 +363,13 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 21, // UPDATE_SAVED_POS - 22, 0, 0, 0, // CALL - 9, 2, 2, // IF - 2, // * POP - 26, // PUSH_UNDEFINED - 2, // * POP - 28 // PUSH_FAILED + 25, // UPDATE_SAVED_POS + 26, 0, 0, 0, // CALL + 13, 2, 2, // IF + 6, // * POP + 1, // PUSH_UNDEFINED + 6, // * POP + 3 // PUSH_FAILED ])); }); @@ -386,35 +386,35 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 55, 3, // IF_NOT_ERROR - 14, 2, 2, 2, 18, 2, 19, 3, // * - 11, 40, 4, // IF_NOT_ERROR - 14, 4, 2, 2, 18, 4, 19, 5, // * - 11, 25, 4, // IF_NOT_ERROR - 21, // * UPDATE_SAVED_POS - 22, 6, 0, 3, 2, 1, 0, // CALL - 9, 2, 2, // IF - 2, // * POP - 26, // PUSH_UNDEFINED - 2, // * POP - 28, // PUSH_FAILED - 11, 3, 4, // IF_NOT_ERROR - 7, 4, // * WRAP - 5, // NIP - 4, 4, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 4, 3, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 4, 2, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 2, // * POP - 3, // POP_CURR_POS - 28 // PUSH_FAILED + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 55, 3, // IF_NOT_ERROR + 18, 2, 2, 2, 22, 2, 23, 3, // * + 15, 40, 4, // IF_NOT_ERROR + 18, 4, 2, 2, 22, 4, 23, 5, // * + 15, 25, 4, // IF_NOT_ERROR + 25, // * UPDATE_SAVED_POS + 26, 6, 0, 3, 2, 1, 0, // CALL + 13, 2, 2, // IF + 6, // * POP + 1, // PUSH_UNDEFINED + 6, // * POP + 3, // PUSH_FAILED + 15, 3, 4, // IF_NOT_ERROR + 11, 4, // * WRAP + 9, // NIP + 8, 4, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 8, 3, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 8, 2, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 6, // * POP + 7, // POP_CURR_POS + 3 // PUSH_FAILED ])); }); @@ -438,13 +438,13 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 21, // UPDATE_SAVED_POS - 22, 0, 0, 0, // CALL - 9, 2, 2, // IF - 2, // * POP - 28, // PUSH_FAILED - 2, // * POP - 26 // PUSH_UNDEFINED + 25, // UPDATE_SAVED_POS + 26, 0, 0, 0, // CALL + 13, 2, 2, // IF + 6, // * POP + 3, // PUSH_FAILED + 6, // * POP + 1 // PUSH_UNDEFINED ])); }); @@ -461,35 +461,35 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 1, // PUSH_CURR_POS - 14, 0, 2, 2, 18, 0, 19, 1, // - 11, 55, 3, // IF_NOT_ERROR - 14, 2, 2, 2, 18, 2, 19, 3, // * - 11, 40, 4, // IF_NOT_ERROR - 14, 4, 2, 2, 18, 4, 19, 5, // * - 11, 25, 4, // IF_NOT_ERROR - 21, // * UPDATE_SAVED_POS - 22, 6, 0, 3, 2, 1, 0, // CALL - 9, 2, 2, // IF - 2, // * POP - 28, // PUSH_FAILED - 2, // * POP - 26, // PUSH_UNDEFINED - 11, 3, 4, // IF_NOT_ERROR - 7, 4, // * WRAP - 5, // NIP - 4, 4, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 4, 3, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 4, 2, // * POP_N - 3, // POP_CURR_POS - 28, // PUSH_FAILED - 2, // * POP - 3, // POP_CURR_POS - 28 // PUSH_FAILED + 5, // PUSH_CURR_POS + 18, 0, 2, 2, 22, 0, 23, 1, // + 15, 55, 3, // IF_NOT_ERROR + 18, 2, 2, 2, 22, 2, 23, 3, // * + 15, 40, 4, // IF_NOT_ERROR + 18, 4, 2, 2, 22, 4, 23, 5, // * + 15, 25, 4, // IF_NOT_ERROR + 25, // * UPDATE_SAVED_POS + 26, 6, 0, 3, 2, 1, 0, // CALL + 13, 2, 2, // IF + 6, // * POP + 3, // PUSH_FAILED + 6, // * POP + 1, // PUSH_UNDEFINED + 15, 3, 4, // IF_NOT_ERROR + 11, 4, // * WRAP + 9, // NIP + 8, 4, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 8, 3, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 8, 2, // * POP_N + 7, // POP_CURR_POS + 3, // PUSH_FAILED + 6, // * POP + 7, // POP_CURR_POS + 3 // PUSH_FAILED ])); }); @@ -515,7 +515,7 @@ describe("compiler pass |generateBytecode|", function() { ].join("\n"), { rules: [ { - bytecode: [23, 1] // RULE + bytecode: [27, 1] // RULE }, { } ] @@ -543,9 +543,9 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 14, 0, 2, 2, // MATCH_STRING - 18, 0, // * ACCEPT_STRING - 19, 1 // * FAIL + 18, 0, 2, 2, // MATCH_STRING + 22, 0, // * ACCEPT_STRING + 23, 1 // * FAIL ])); }); @@ -562,9 +562,9 @@ describe("compiler pass |generateBytecode|", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 15, 0, 2, 2, // MATCH_STRING_IC - 17, 1, // * ACCEPT_N - 19, 1 // * FAIL + 19, 0, 2, 2, // MATCH_STRING_IC + 21, 1, // * ACCEPT_N + 23, 1 // * FAIL ])); }); @@ -580,9 +580,9 @@ describe("compiler pass |generateBytecode|", function() { describe("for class", function() { it("generates correct bytecode", function() { expect(pass).toChangeAST('start = [a]', bytecodeDetails([ - 16, 0, 2, 2, // MATCH_REGEXP - 17, 1, // * ACCEPT_N - 19, 1 // * FAIL + 20, 0, 2, 2, // MATCH_REGEXP + 21, 1, // * ACCEPT_N + 23, 1 // * FAIL ])); }); @@ -646,9 +646,9 @@ describe("compiler pass |generateBytecode|", function() { it("generates bytecode", function() { expect(pass).toChangeAST(grammar, bytecodeDetails([ - 13, 2, 2, // MATCH_ANY - 17, 1, // * ACCEPT_N - 19, 0 // * FAIL + 17, 2, 2, // MATCH_ANY + 21, 1, // * ACCEPT_N + 23, 0 // * FAIL ])); });