Renumber bytecode instructions sequentially
This commit is contained in:
parent
ad27a300a8
commit
a4772376fb
|
@ -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;
|
||||
|
|
|
@ -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--;
|
||||
*/
|
||||
|
|
|
@ -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 // <expression>
|
||||
18, 0, 2, 2, 22, 0, 23, 1 // <expression>
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
@ -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, // <expression>
|
||||
25, // SILENT_FAILS_OFF
|
||||
10, 2, 0, // IF_ERROR
|
||||
19, 0 // * FAIL
|
||||
28, // SILENT_FAILS_ON
|
||||
18, 1, 2, 2, 22, 1, 23, 2, // <expression>
|
||||
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, // <alternatives[0]>
|
||||
10, 21, 0, // IF_ERROR
|
||||
2, // * POP
|
||||
14, 2, 2, 2, 18, 2, 19, 3, // <alternatives[1]>
|
||||
10, 9, 0, // IF_ERROR
|
||||
2, // * POP
|
||||
14, 4, 2, 2, 18, 4, 19, 5 // <alternatives[2]>
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <alternatives[0]>
|
||||
14, 21, 0, // IF_ERROR
|
||||
6, // * POP
|
||||
18, 2, 2, 2, 22, 2, 23, 3, // <alternatives[1]>
|
||||
14, 9, 0, // IF_ERROR
|
||||
6, // * POP
|
||||
18, 4, 2, 2, 22, 4, 23, 5 // <alternatives[2]>
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
@ -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, // <expression>
|
||||
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, // <expression>
|
||||
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, // <expression>
|
||||
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, // <expression>
|
||||
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, // <elements[0]>
|
||||
11, 40, 3, // IF_NOT_ERROR
|
||||
14, 2, 2, 2, 18, 2, 19, 3, // * <elements[1]>
|
||||
11, 25, 4, // IF_NOT_ERROR
|
||||
14, 4, 2, 2, 18, 4, 19, 5, // * <elements[2]>
|
||||
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, // <elements[0]>
|
||||
15, 40, 3, // IF_NOT_ERROR
|
||||
18, 2, 2, 2, 22, 2, 23, 3, // * <elements[1]>
|
||||
15, 25, 4, // IF_NOT_ERROR
|
||||
18, 4, 2, 2, 22, 4, 23, 5, // * <elements[2]>
|
||||
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, // <elements[0]>
|
||||
11, 33, 3, // IF_NOT_ERROR
|
||||
14, 2, 2, 2, 18, 2, 19, 3, // * <elements[1]>
|
||||
11, 18, 4, // IF_NOT_ERROR
|
||||
14, 4, 2, 2, 18, 4, 19, 5, // * <elements[2]>
|
||||
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, // <elements[0]>
|
||||
15, 33, 3, // IF_NOT_ERROR
|
||||
18, 2, 2, 2, 22, 2, 23, 3, // * <elements[1]>
|
||||
15, 18, 4, // IF_NOT_ERROR
|
||||
18, 4, 2, 2, 22, 4, 23, 5, // * <elements[2]>
|
||||
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 // <expression>
|
||||
18, 0, 2, 2, 22, 0, 23, 1 // <expression>
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
@ -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, // <expression>
|
||||
11, 2, 1, // IF_NOT_ERROR
|
||||
2, // * POP
|
||||
8, // TEXT
|
||||
5 // * NIP
|
||||
5, // PUSH_CURR_POS
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <expression>
|
||||
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, // <expression>
|
||||
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, // <expression>
|
||||
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, // <expression>
|
||||
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, // <expression>
|
||||
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, // <expression>
|
||||
10, 2, 0, // IF_ERROR
|
||||
2, // * POP
|
||||
27 // PUSH_NULL
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <expression>
|
||||
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, // <expression>
|
||||
12, 9, // WHILE_NOT_ERROR
|
||||
6, // * APPEND
|
||||
14, 0, 2, 2, 18, 0, 19, 1, // <expression>
|
||||
2 // POP
|
||||
4, // PUSH_EMPTY_ARRAY
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <expression>
|
||||
16, 9, // WHILE_NOT_ERROR
|
||||
10, // * APPEND
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <expression>
|
||||
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, // <expression>
|
||||
11, 12, 3, // IF_NOT_ERROR
|
||||
12, 9, // * WHILE_NOT_ERROR
|
||||
6, // * APPEND
|
||||
14, 0, 2, 2, 18, 0, 19, 1, // <expression>
|
||||
2, // POP
|
||||
2, // * POP
|
||||
2, // POP
|
||||
28 // PUSH_FAILED
|
||||
4, // PUSH_EMPTY_ARRAY
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <expression>
|
||||
15, 12, 3, // IF_NOT_ERROR
|
||||
16, 9, // * WHILE_NOT_ERROR
|
||||
10, // * APPEND
|
||||
18, 0, 2, 2, 22, 0, 23, 1, // <expression>
|
||||
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, // <elements[0]>
|
||||
11, 55, 3, // IF_NOT_ERROR
|
||||
14, 2, 2, 2, 18, 2, 19, 3, // * <elements[1]>
|
||||
11, 40, 4, // IF_NOT_ERROR
|
||||
14, 4, 2, 2, 18, 4, 19, 5, // * <elements[2]>
|
||||
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, // <elements[0]>
|
||||
15, 55, 3, // IF_NOT_ERROR
|
||||
18, 2, 2, 2, 22, 2, 23, 3, // * <elements[1]>
|
||||
15, 40, 4, // IF_NOT_ERROR
|
||||
18, 4, 2, 2, 22, 4, 23, 5, // * <elements[2]>
|
||||
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, // <elements[0]>
|
||||
11, 55, 3, // IF_NOT_ERROR
|
||||
14, 2, 2, 2, 18, 2, 19, 3, // * <elements[1]>
|
||||
11, 40, 4, // IF_NOT_ERROR
|
||||
14, 4, 2, 2, 18, 4, 19, 5, // * <elements[2]>
|
||||
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, // <elements[0]>
|
||||
15, 55, 3, // IF_NOT_ERROR
|
||||
18, 2, 2, 2, 22, 2, 23, 3, // * <elements[1]>
|
||||
15, 40, 4, // IF_NOT_ERROR
|
||||
18, 4, 2, 2, 22, 4, 23, 5, // * <elements[2]>
|
||||
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
|
||||
]));
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue