mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
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:
parent
7c353009d5
commit
6ee86f8680
2 changed files with 17 additions and 0 deletions
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue