mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: adjust init/_deploy method offsets during optimization
Because `_initialize` and `_deploy` methods encompass multiple Go functions, their offsets are stored differently and need special treatment.
This commit is contained in:
parent
2ee755e09f
commit
560aff6155
3 changed files with 71 additions and 15 deletions
|
@ -286,6 +286,16 @@ func TestVariadicMethod(t *testing.T) {
|
|||
|
||||
func TestJumpOptimize(t *testing.T) {
|
||||
src := `package foo
|
||||
func init() {
|
||||
if true {} else {}
|
||||
var a int
|
||||
_ = a
|
||||
}
|
||||
func _deploy(_ interface{}, upd bool) {
|
||||
if true {} else {}
|
||||
t := upd
|
||||
_ = t
|
||||
}
|
||||
func Get1() int { return 1 }
|
||||
func Get2() int { Get1(); Get1(); Get1(); Get1(); return Get1() }
|
||||
func Get3() int { return Get2() }
|
||||
|
@ -294,6 +304,7 @@ func TestJumpOptimize(t *testing.T) {
|
|||
}`
|
||||
b, di, err := compiler.CompileWithDebugInfo("", strings.NewReader(src))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 6, len(di.Methods))
|
||||
for _, mi := range di.Methods {
|
||||
require.Equal(t, b[mi.Range.Start], byte(opcode.INITSLOT))
|
||||
require.Equal(t, b[mi.Range.End], byte(opcode.RET))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue