|
|
|
@ -85,24 +85,25 @@ describe("compiler pass |generateBytecode|", function() {
|
|
|
|
|
|
|
|
|
|
describe("for action", function() {
|
|
|
|
|
describe("without labels", function() {
|
|
|
|
|
var grammar = 'start = { code }';
|
|
|
|
|
var grammar = 'start = "a" { code }';
|
|
|
|
|
|
|
|
|
|
it("generates correct bytecode", function() {
|
|
|
|
|
expect(pass).toChangeAST(grammar, bytecodeDetails([
|
|
|
|
|
1, // PUSH_CURR_POS
|
|
|
|
|
0, 0, // <expression>
|
|
|
|
|
14, 0, 2, 2, 18, 0, 19, 1, // <expression>
|
|
|
|
|
11, 6, 0, // IF_NOT_ERROR
|
|
|
|
|
20, 1, // * REPORT_SAVED_POS
|
|
|
|
|
22, 1, 1, 0, // CALL
|
|
|
|
|
22, 2, 1, 0, // CALL
|
|
|
|
|
5 // NIP
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("defines correct constants", function() {
|
|
|
|
|
expect(pass).toChangeAST(
|
|
|
|
|
grammar,
|
|
|
|
|
constsDetails(['[]', 'function() { code }'])
|
|
|
|
|
);
|
|
|
|
|
expect(pass).toChangeAST(grammar, constsDetails([
|
|
|
|
|
'"a"',
|
|
|
|
|
'{ type: "literal", value: "a", description: "\\"a\\"" }',
|
|
|
|
|
'function() { code }'
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -171,21 +172,6 @@ describe("compiler pass |generateBytecode|", function() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("for sequence", function() {
|
|
|
|
|
describe("empty", function() {
|
|
|
|
|
var grammar = 'start = ';
|
|
|
|
|
|
|
|
|
|
it("generates correct bytecode", function() {
|
|
|
|
|
expect(pass).toChangeAST(grammar, bytecodeDetails([
|
|
|
|
|
0, 0 // PUSH
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("defines correct constants", function() {
|
|
|
|
|
expect(pass).toChangeAST(grammar, constsDetails(['[]']));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("non-empty", function() {
|
|
|
|
|
var grammar = 'start = "a" "b" "c"';
|
|
|
|
|
|
|
|
|
|
it("generates correct bytecode", function() {
|
|
|
|
@ -223,7 +209,6 @@ describe("compiler pass |generateBytecode|", function() {
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("for labeled", function() {
|
|
|
|
|
it("generates correct bytecode", function() {
|
|
|
|
|