compiler: count local variables on the go

Create local variables as they are needed and remove `INITSLOT`
if there were no locals. This helps to eliminate a whole class
of bugs when calculated and real amount mismatched.
This commit is contained in:
Evgeniy Stratonikov 2021-04-28 16:10:44 +03:00
parent bfa2bafb04
commit b693d54282
9 changed files with 181 additions and 230 deletions

View file

@ -306,7 +306,10 @@ func TestJumpOptimize(t *testing.T) {
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))
// only _deploy and init have locals here
if mi.Name.Name == "_deploy" || mi.Name.Name == "init" {
require.Equal(t, b[mi.Range.Start], byte(opcode.INITSLOT))
}
require.Equal(t, b[mi.Range.End], byte(opcode.RET))
}
}