core/asm: Allow JUMP with no argument

This way, a label can be pushed explicitly, or loaded from memory to
implement a jump table.
This commit is contained in:
Michael Forney 2019-10-26 14:54:07 -07:00
parent 7c353009d5
commit 6ee86f8680
2 changed files with 17 additions and 0 deletions

View file

@ -186,6 +186,8 @@ func (c *Compiler) compileElement(element token) error {
pos := big.NewInt(int64(c.labels[rvalue.text])).Bytes() pos := big.NewInt(int64(c.labels[rvalue.text])).Bytes()
pos = append(make([]byte, 4-len(pos)), pos...) pos = append(make([]byte, 4-len(pos)), pos...)
c.pushBin(pos) c.pushBin(pos)
case lineEnd:
c.pos--
default: default:
return compileErr(rvalue, rvalue.text, "number, string or label") return compileErr(rvalue, rvalue.text, "number, string or label")
} }

View file

@ -39,6 +39,21 @@ func TestCompiler(t *testing.T) {
`, `,
output: "63000000055b", output: "63000000055b",
}, },
{
input: `
PUSH @label
JUMP
label:
`,
output: "6300000006565b",
},
{
input: `
JUMP @label
label:
`,
output: "6300000006565b",
},
} }
for _, test := range tests { for _, test := range tests {
ch := Lex([]byte(test.input), false) ch := Lex([]byte(test.input), false)