Skip to content

Commit

Permalink
core/asm: Allow JUMP with no argument
Browse files Browse the repository at this point in the history
This way, a label can be pushed explicitly, or loaded from memory to
implement a jump table.
  • Loading branch information
michaelforney committed Oct 28, 2019
1 parent 7c35300 commit 6ee86f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/asm/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func (c *Compiler) compileElement(element token) error {
pos := big.NewInt(int64(c.labels[rvalue.text])).Bytes()
pos = append(make([]byte, 4-len(pos)), pos...)
c.pushBin(pos)
case lineEnd:
c.pos--
default:
return compileErr(rvalue, rvalue.text, "number, string or label")
}
Expand Down
15 changes: 15 additions & 0 deletions core/asm/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ func TestCompiler(t *testing.T) {
`,
output: "63000000055b",
},
{
input: `
PUSH @label
JUMP
label:
`,
output: "6300000006565b",
},
{
input: `
JUMP @label
label:
`,
output: "6300000006565b",
},
}
for _, test := range tests {
ch := Lex([]byte(test.input), false)
Expand Down

0 comments on commit 6ee86f8

Please sign in to comment.