Introduce JumpLabels instead of manually correct jump positions
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
e64256b65f
commit
7182024342
12 changed files with 485 additions and 381 deletions
|
|
@ -3,46 +3,60 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/condition.nomo
|
||||
---
|
||||
[
|
||||
LoadFromContextToSlot {
|
||||
name: "test" (6..10),
|
||||
slot: VariableSlot {
|
||||
VMInstructions {
|
||||
labels: {
|
||||
LabelSlot {
|
||||
index: 2,
|
||||
}: 7,
|
||||
LabelSlot {
|
||||
index: 0,
|
||||
}: 7,
|
||||
},
|
||||
instructions: [
|
||||
LoadFromContextToSlot {
|
||||
name: "test" (6..10),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 0,
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
jump: LabelSlot {
|
||||
index: 2,
|
||||
},
|
||||
},
|
||||
jump: 5,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
AppendContent {
|
||||
content: "Hello World!" (18..30),
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (30..31),
|
||||
},
|
||||
Jump {
|
||||
jump: 2,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n\n" (40..42),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "stuff" (46..51),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: "Hello World!" (18..30),
|
||||
},
|
||||
},
|
||||
]
|
||||
AppendContent {
|
||||
content: "\n" (30..31),
|
||||
},
|
||||
Jump {
|
||||
jump: LabelSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n\n" (40..42),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "stuff" (46..51),
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,86 +3,89 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/identifiers.nomo
|
||||
---
|
||||
[
|
||||
LoadFromContextToSlot {
|
||||
name: "_name" (4..9),
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
instructions: [
|
||||
LoadFromContextToSlot {
|
||||
name: "_name" (4..9),
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (12..13),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "a_name" (17..23),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: "\n" (12..13),
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
LoadFromContextToSlot {
|
||||
name: "a_name" (17..23),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (26..27),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "1name" (31..36),
|
||||
slot: VariableSlot {
|
||||
index: 2,
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 2,
|
||||
AppendContent {
|
||||
content: "\n" (26..27),
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (39..40),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "_name1" (44..50),
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
LoadFromContextToSlot {
|
||||
name: "1name" (31..36),
|
||||
slot: VariableSlot {
|
||||
index: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (53..54),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "_namE" (58..63),
|
||||
slot: VariableSlot {
|
||||
index: 4,
|
||||
AppendContent {
|
||||
content: "\n" (39..40),
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 4,
|
||||
LoadFromContextToSlot {
|
||||
name: "_name1" (44..50),
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (66..67),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "name1" (71..76),
|
||||
slot: VariableSlot {
|
||||
index: 5,
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 5,
|
||||
AppendContent {
|
||||
content: "\n" (53..54),
|
||||
},
|
||||
},
|
||||
]
|
||||
LoadFromContextToSlot {
|
||||
name: "_namE" (58..63),
|
||||
slot: VariableSlot {
|
||||
index: 4,
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 4,
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (66..67),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "name1" (71..76),
|
||||
slot: VariableSlot {
|
||||
index: 5,
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 5,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,60 +3,81 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
[
|
||||
LoadFromContextToSlot {
|
||||
name: "test" (6..10),
|
||||
slot: VariableSlot {
|
||||
VMInstructions {
|
||||
labels: {
|
||||
LabelSlot {
|
||||
index: 2,
|
||||
}: 7,
|
||||
LabelSlot {
|
||||
index: 4,
|
||||
}: 14,
|
||||
LabelSlot {
|
||||
index: 0,
|
||||
}: 14,
|
||||
},
|
||||
instructions: [
|
||||
LoadFromContextToSlot {
|
||||
name: "test" (6..10),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 0,
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
jump: LabelSlot {
|
||||
index: 2,
|
||||
},
|
||||
},
|
||||
jump: 5,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
AppendContent {
|
||||
content: "Not Hello World! :C" (18..37),
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (37..38),
|
||||
},
|
||||
Jump {
|
||||
jump: 9,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "another_test" (49..61),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
},
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: "Not Hello World! :C" (18..37),
|
||||
},
|
||||
jump: 5,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (64..69),
|
||||
},
|
||||
AppendContent {
|
||||
content: "Hello World!" (69..81),
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (81..82),
|
||||
},
|
||||
Jump {
|
||||
jump: 2,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (64..69),
|
||||
},
|
||||
NoOp,
|
||||
]
|
||||
AppendContent {
|
||||
content: "\n" (37..38),
|
||||
},
|
||||
Jump {
|
||||
jump: LabelSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "another_test" (49..61),
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
jump: LabelSlot {
|
||||
index: 4,
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (64..69),
|
||||
},
|
||||
AppendContent {
|
||||
content: "Hello World!" (69..81),
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n" (81..82),
|
||||
},
|
||||
Jump {
|
||||
jump: LabelSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (64..69),
|
||||
},
|
||||
NoOp,
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,25 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/interpolation.nomo
|
||||
---
|
||||
[
|
||||
AppendContent {
|
||||
content: "Hello! I'm" (0..10),
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (10..11),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "name" (15..19),
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
instructions: [
|
||||
AppendContent {
|
||||
content: "Hello! I'm" (0..10),
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
AppendContent {
|
||||
content: " " (10..11),
|
||||
},
|
||||
},
|
||||
]
|
||||
LoadFromContextToSlot {
|
||||
name: "name" (15..19),
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,36 +3,39 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/multiple.nomo
|
||||
---
|
||||
[
|
||||
AppendContent {
|
||||
content: "Hi there! My name is" (0..20),
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (20..21),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "name" (25..29),
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
instructions: [
|
||||
AppendContent {
|
||||
content: "Hi there! My name is" (0..20),
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
AppendContent {
|
||||
content: " " (20..21),
|
||||
},
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (32..33),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "lastname" (37..45),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
LoadFromContextToSlot {
|
||||
name: "name" (25..29),
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
AppendContent {
|
||||
content: " " (32..33),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "lastname" (37..45),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/simple.nomo
|
||||
---
|
||||
[
|
||||
AppendContent {
|
||||
content: "Hello World!" (0..12),
|
||||
},
|
||||
]
|
||||
VMInstructions {
|
||||
labels: {},
|
||||
instructions: [
|
||||
AppendContent {
|
||||
content: "Hello World!" (0..12),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,38 +3,52 @@ source: tests/file_tests.rs
|
|||
expression: emit
|
||||
input_file: tests/cases/trim_whitespace.nomo
|
||||
---
|
||||
[
|
||||
LoadFromContextToSlot {
|
||||
name: "test" (6..10),
|
||||
slot: VariableSlot {
|
||||
VMInstructions {
|
||||
labels: {
|
||||
LabelSlot {
|
||||
index: 2,
|
||||
}: 7,
|
||||
LabelSlot {
|
||||
index: 0,
|
||||
}: 7,
|
||||
},
|
||||
instructions: [
|
||||
LoadFromContextToSlot {
|
||||
name: "test" (6..10),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 0,
|
||||
JumpIfNotTrue {
|
||||
emit_slot: VariableSlot {
|
||||
index: 1,
|
||||
},
|
||||
jump: LabelSlot {
|
||||
index: 2,
|
||||
},
|
||||
},
|
||||
jump: 5,
|
||||
},
|
||||
AppendContent {
|
||||
content: "Hello" (19..24),
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (24..25),
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: "stuff" (29..34),
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: "Hello" (19..24),
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 1,
|
||||
AppendContent {
|
||||
content: " " (24..25),
|
||||
},
|
||||
},
|
||||
Jump {
|
||||
jump: 1,
|
||||
},
|
||||
NoOp,
|
||||
]
|
||||
LoadFromContextToSlot {
|
||||
name: "stuff" (29..34),
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot {
|
||||
index: 3,
|
||||
},
|
||||
},
|
||||
Jump {
|
||||
jump: LabelSlot {
|
||||
index: 0,
|
||||
},
|
||||
},
|
||||
NoOp,
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ source: tests/file_tests.rs
|
|||
expression: output
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
"\n \n Hello World!\n"
|
||||
"\n Hello World!\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue