Skip to content

Commit 6ee86f8

Browse files
committed
core/asm: Allow JUMP with no argument
This way, a label can be pushed explicitly, or loaded from memory to implement a jump table.
1 parent 7c35300 commit 6ee86f8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/asm/compiler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ func (c *Compiler) compileElement(element token) error {
186186
pos := big.NewInt(int64(c.labels[rvalue.text])).Bytes()
187187
pos = append(make([]byte, 4-len(pos)), pos...)
188188
c.pushBin(pos)
189+
case lineEnd:
190+
c.pos--
189191
default:
190192
return compileErr(rvalue, rvalue.text, "number, string or label")
191193
}

core/asm/compiler_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ func TestCompiler(t *testing.T) {
3939
`,
4040
output: "63000000055b",
4141
},
42+
{
43+
input: `
44+
PUSH @label
45+
JUMP
46+
label:
47+
`,
48+
output: "6300000006565b",
49+
},
50+
{
51+
input: `
52+
JUMP @label
53+
label:
54+
`,
55+
output: "6300000006565b",
56+
},
4257
}
4358
for _, test := range tests {
4459
ch := Lex([]byte(test.input), false)

0 commit comments

Comments
 (0)