From 6ee86f8680c834582b79ff06888de3133a7ad9b5 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 26 Oct 2019 14:54:07 -0700 Subject: [PATCH] core/asm: Allow JUMP with no argument This way, a label can be pushed explicitly, or loaded from memory to implement a jump table. --- core/asm/compiler.go | 2 ++ core/asm/compiler_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/core/asm/compiler.go b/core/asm/compiler.go index 00da650913..7997099298 100644 --- a/core/asm/compiler.go +++ b/core/asm/compiler.go @@ -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") } diff --git a/core/asm/compiler_test.go b/core/asm/compiler_test.go index 684ca574b0..ce9df436bd 100644 --- a/core/asm/compiler_test.go +++ b/core/asm/compiler_test.go @@ -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)