From f4fa712440f29da065cf3518c6cbdff6e6b7ffaf Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 20 May 2020 16:31:10 +0300 Subject: [PATCH] vm: make PUSH0 emit Integer --- pkg/compiler/binary_expr_test.go | 10 +++++----- pkg/compiler/for_test.go | 2 +- pkg/compiler/function_call_test.go | 2 +- pkg/compiler/if_test.go | 6 +++--- pkg/compiler/import_test.go | 2 +- pkg/compiler/struct_test.go | 2 +- pkg/vm/vm.go | 7 ++----- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pkg/compiler/binary_expr_test.go b/pkg/compiler/binary_expr_test.go index d3f5c0ab9..bf3f94c62 100644 --- a/pkg/compiler/binary_expr_test.go +++ b/pkg/compiler/binary_expr_test.go @@ -26,7 +26,7 @@ var binaryExprTestCases = []testCase{ return x } `, - []byte{}, + big.NewInt(0), }, { "simple div", @@ -97,7 +97,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - []byte{}, + big.NewInt(0), }, { "compare equal strings with eql", @@ -139,7 +139,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - []byte{}, + big.NewInt(0), }, { "compare equal ints with eql", @@ -167,7 +167,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - []byte{}, + big.NewInt(0), }, { "compare not equal ints with eql", @@ -181,7 +181,7 @@ var binaryExprTestCases = []testCase{ return 0 } `, - []byte{}, + big.NewInt(0), }, { "compare not equal ints with neq", diff --git a/pkg/compiler/for_test.go b/pkg/compiler/for_test.go index 71160a41f..f3ea262f3 100644 --- a/pkg/compiler/for_test.go +++ b/pkg/compiler/for_test.go @@ -276,7 +276,7 @@ func TestIfUnaryInvert(t *testing.T) { return 0 } ` - eval(t, src, []byte{}) + eval(t, src, big.NewInt(0)) } func TestAppendByte(t *testing.T) { diff --git a/pkg/compiler/function_call_test.go b/pkg/compiler/function_call_test.go index 8851078f0..c9d9ca04c 100644 --- a/pkg/compiler/function_call_test.go +++ b/pkg/compiler/function_call_test.go @@ -39,7 +39,7 @@ func TestNotAssignedFunctionCall(t *testing.T) { // disable stack checks because it is hard right now // to distinguish between simple function call traversal // and the same traversal inside an assignment. - evalWithoutStackChecks(t, src, []byte{}) + evalWithoutStackChecks(t, src, big.NewInt(0)) } func TestMultipleFunctionCalls(t *testing.T) { diff --git a/pkg/compiler/if_test.go b/pkg/compiler/if_test.go index 91731460d..23077ecf9 100644 --- a/pkg/compiler/if_test.go +++ b/pkg/compiler/if_test.go @@ -30,7 +30,7 @@ func TestGT(t *testing.T) { return 0 } ` - eval(t, src, []byte{}) + eval(t, src, big.NewInt(0)) } func TestGTE(t *testing.T) { @@ -44,7 +44,7 @@ func TestGTE(t *testing.T) { return 0 } ` - eval(t, src, []byte{}) + eval(t, src, big.NewInt(0)) } func TestLAND(t *testing.T) { @@ -89,5 +89,5 @@ func TestNestedIF(t *testing.T) { return 0 } ` - eval(t, src, []byte{}) + eval(t, src, big.NewInt(0)) } diff --git a/pkg/compiler/import_test.go b/pkg/compiler/import_test.go index 7c635be3e..def752427 100644 --- a/pkg/compiler/import_test.go +++ b/pkg/compiler/import_test.go @@ -32,7 +32,7 @@ func TestImportStruct(t *testing.T) { return b.Y } ` - eval(t, src, []byte{}) + eval(t, src, big.NewInt(0)) } func TestMultipleDirFileImport(t *testing.T) { diff --git a/pkg/compiler/struct_test.go b/pkg/compiler/struct_test.go index 6646f877d..208f6a11b 100644 --- a/pkg/compiler/struct_test.go +++ b/pkg/compiler/struct_test.go @@ -255,7 +255,7 @@ var structTestCases = []testCase{ return t.y } `, - []byte{}, + big.NewInt(0), }, { "test return struct from func", diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 3a084d55a..b860cec42 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -518,17 +518,14 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro } switch op { - case opcode.PUSHM1, opcode.PUSH1, opcode.PUSH2, opcode.PUSH3, + case opcode.PUSHM1, opcode.PUSH0, opcode.PUSH1, opcode.PUSH2, opcode.PUSH3, opcode.PUSH4, opcode.PUSH5, opcode.PUSH6, opcode.PUSH7, opcode.PUSH8, opcode.PUSH9, opcode.PUSH10, opcode.PUSH11, opcode.PUSH12, opcode.PUSH13, opcode.PUSH14, opcode.PUSH15, opcode.PUSH16: - val := int(op) - int(opcode.PUSH1) + 1 + val := int(op) - int(opcode.PUSH0) v.estack.PushVal(val) - case opcode.PUSH0: - v.estack.PushVal([]byte{}) - case opcode.PUSHDATA1, opcode.PUSHDATA2, opcode.PUSHDATA4: v.estack.PushVal(parameter)