vm: make PUSH0 emit Integer

This commit is contained in:
Evgenii Stratonikov 2020-05-20 16:31:10 +03:00
parent 820b050b18
commit f4fa712440
7 changed files with 14 additions and 17 deletions

View file

@ -26,7 +26,7 @@ var binaryExprTestCases = []testCase{
return x return x
} }
`, `,
[]byte{}, big.NewInt(0),
}, },
{ {
"simple div", "simple div",
@ -97,7 +97,7 @@ var binaryExprTestCases = []testCase{
return 0 return 0
} }
`, `,
[]byte{}, big.NewInt(0),
}, },
{ {
"compare equal strings with eql", "compare equal strings with eql",
@ -139,7 +139,7 @@ var binaryExprTestCases = []testCase{
return 0 return 0
} }
`, `,
[]byte{}, big.NewInt(0),
}, },
{ {
"compare equal ints with eql", "compare equal ints with eql",
@ -167,7 +167,7 @@ var binaryExprTestCases = []testCase{
return 0 return 0
} }
`, `,
[]byte{}, big.NewInt(0),
}, },
{ {
"compare not equal ints with eql", "compare not equal ints with eql",
@ -181,7 +181,7 @@ var binaryExprTestCases = []testCase{
return 0 return 0
} }
`, `,
[]byte{}, big.NewInt(0),
}, },
{ {
"compare not equal ints with neq", "compare not equal ints with neq",

View file

@ -276,7 +276,7 @@ func TestIfUnaryInvert(t *testing.T) {
return 0 return 0
} }
` `
eval(t, src, []byte{}) eval(t, src, big.NewInt(0))
} }
func TestAppendByte(t *testing.T) { func TestAppendByte(t *testing.T) {

View file

@ -39,7 +39,7 @@ func TestNotAssignedFunctionCall(t *testing.T) {
// disable stack checks because it is hard right now // disable stack checks because it is hard right now
// to distinguish between simple function call traversal // to distinguish between simple function call traversal
// and the same traversal inside an assignment. // and the same traversal inside an assignment.
evalWithoutStackChecks(t, src, []byte{}) evalWithoutStackChecks(t, src, big.NewInt(0))
} }
func TestMultipleFunctionCalls(t *testing.T) { func TestMultipleFunctionCalls(t *testing.T) {

View file

@ -30,7 +30,7 @@ func TestGT(t *testing.T) {
return 0 return 0
} }
` `
eval(t, src, []byte{}) eval(t, src, big.NewInt(0))
} }
func TestGTE(t *testing.T) { func TestGTE(t *testing.T) {
@ -44,7 +44,7 @@ func TestGTE(t *testing.T) {
return 0 return 0
} }
` `
eval(t, src, []byte{}) eval(t, src, big.NewInt(0))
} }
func TestLAND(t *testing.T) { func TestLAND(t *testing.T) {
@ -89,5 +89,5 @@ func TestNestedIF(t *testing.T) {
return 0 return 0
} }
` `
eval(t, src, []byte{}) eval(t, src, big.NewInt(0))
} }

View file

@ -32,7 +32,7 @@ func TestImportStruct(t *testing.T) {
return b.Y return b.Y
} }
` `
eval(t, src, []byte{}) eval(t, src, big.NewInt(0))
} }
func TestMultipleDirFileImport(t *testing.T) { func TestMultipleDirFileImport(t *testing.T) {

View file

@ -255,7 +255,7 @@ var structTestCases = []testCase{
return t.y return t.y
} }
`, `,
[]byte{}, big.NewInt(0),
}, },
{ {
"test return struct from func", "test return struct from func",

View file

@ -518,17 +518,14 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
} }
switch op { 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.PUSH4, opcode.PUSH5, opcode.PUSH6, opcode.PUSH7,
opcode.PUSH8, opcode.PUSH9, opcode.PUSH10, opcode.PUSH11, opcode.PUSH8, opcode.PUSH9, opcode.PUSH10, opcode.PUSH11,
opcode.PUSH12, opcode.PUSH13, opcode.PUSH14, opcode.PUSH15, opcode.PUSH12, opcode.PUSH13, opcode.PUSH14, opcode.PUSH15,
opcode.PUSH16: opcode.PUSH16:
val := int(op) - int(opcode.PUSH1) + 1 val := int(op) - int(opcode.PUSH0)
v.estack.PushVal(val) v.estack.PushVal(val)
case opcode.PUSH0:
v.estack.PushVal([]byte{})
case opcode.PUSHDATA1, opcode.PUSHDATA2, opcode.PUSHDATA4: case opcode.PUSHDATA1, opcode.PUSHDATA2, opcode.PUSHDATA4:
v.estack.PushVal(parameter) v.estack.PushVal(parameter)