forked from TrueCloudLab/neoneo-go
vm: implement CLEAR opcode
This commit is contained in:
parent
525527f750
commit
c8a1188ee1
4 changed files with 94 additions and 80 deletions
|
@ -66,11 +66,11 @@ const (
|
||||||
CALLL Opcode = 0x35
|
CALLL Opcode = 0x35
|
||||||
|
|
||||||
// Stack
|
// Stack
|
||||||
DEPTH Opcode = 0x43
|
DEPTH Opcode = 0x43
|
||||||
DROP Opcode = 0x45
|
DROP Opcode = 0x45
|
||||||
NIP Opcode = 0x46
|
NIP Opcode = 0x46
|
||||||
XDROP Opcode = 0x48
|
XDROP Opcode = 0x48
|
||||||
// CLEAR Opcode = 0x49
|
CLEAR Opcode = 0x49
|
||||||
DUP Opcode = 0x4A
|
DUP Opcode = 0x4A
|
||||||
OVER Opcode = 0x4B
|
OVER Opcode = 0x4B
|
||||||
PICK Opcode = 0x4D
|
PICK Opcode = 0x4D
|
||||||
|
|
|
@ -63,6 +63,7 @@ func _() {
|
||||||
_ = x[DROP-69]
|
_ = x[DROP-69]
|
||||||
_ = x[NIP-70]
|
_ = x[NIP-70]
|
||||||
_ = x[XDROP-72]
|
_ = x[XDROP-72]
|
||||||
|
_ = x[CLEAR-73]
|
||||||
_ = x[DUP-74]
|
_ = x[DUP-74]
|
||||||
_ = x[OVER-75]
|
_ = x[OVER-75]
|
||||||
_ = x[PICK-77]
|
_ = x[PICK-77]
|
||||||
|
@ -140,7 +141,7 @@ func _() {
|
||||||
_ = x[THROWIFNOT-241]
|
_ = x[THROWIFNOT-241]
|
||||||
}
|
}
|
||||||
|
|
||||||
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLDEPTHDROPNIPXDROPDUPOVERPICKTUCKSWAPOLDPUSH1ROLLRETAPPCALLSYSCALLTAILCALLDUPFROMALTSTACKTOALTSTACKFROMALTSTACKXSWAPXTUCKCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERTTHROWTHROWIFNOT"
|
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLRETAPPCALLSYSCALLTAILCALLDUPFROMALTSTACKTOALTSTACKFROMALTSTACKXSWAPXTUCKCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERTTHROWTHROWIFNOT"
|
||||||
|
|
||||||
var _Opcode_map = map[Opcode]string{
|
var _Opcode_map = map[Opcode]string{
|
||||||
0: _Opcode_name[0:8],
|
0: _Opcode_name[0:8],
|
||||||
|
@ -196,80 +197,81 @@ var _Opcode_map = map[Opcode]string{
|
||||||
69: _Opcode_name[306:310],
|
69: _Opcode_name[306:310],
|
||||||
70: _Opcode_name[310:313],
|
70: _Opcode_name[310:313],
|
||||||
72: _Opcode_name[313:318],
|
72: _Opcode_name[313:318],
|
||||||
74: _Opcode_name[318:321],
|
73: _Opcode_name[318:323],
|
||||||
75: _Opcode_name[321:325],
|
74: _Opcode_name[323:326],
|
||||||
77: _Opcode_name[325:329],
|
75: _Opcode_name[326:330],
|
||||||
78: _Opcode_name[329:333],
|
77: _Opcode_name[330:334],
|
||||||
80: _Opcode_name[333:337],
|
78: _Opcode_name[334:338],
|
||||||
81: _Opcode_name[337:345],
|
80: _Opcode_name[338:342],
|
||||||
82: _Opcode_name[345:349],
|
81: _Opcode_name[342:350],
|
||||||
102: _Opcode_name[349:352],
|
82: _Opcode_name[350:354],
|
||||||
103: _Opcode_name[352:359],
|
102: _Opcode_name[354:357],
|
||||||
104: _Opcode_name[359:366],
|
103: _Opcode_name[357:364],
|
||||||
105: _Opcode_name[366:374],
|
104: _Opcode_name[364:371],
|
||||||
106: _Opcode_name[374:389],
|
105: _Opcode_name[371:379],
|
||||||
107: _Opcode_name[389:399],
|
106: _Opcode_name[379:394],
|
||||||
108: _Opcode_name[399:411],
|
107: _Opcode_name[394:404],
|
||||||
114: _Opcode_name[411:416],
|
108: _Opcode_name[404:416],
|
||||||
115: _Opcode_name[416:421],
|
114: _Opcode_name[416:421],
|
||||||
126: _Opcode_name[421:424],
|
115: _Opcode_name[421:426],
|
||||||
127: _Opcode_name[424:430],
|
126: _Opcode_name[426:429],
|
||||||
128: _Opcode_name[430:434],
|
127: _Opcode_name[429:435],
|
||||||
129: _Opcode_name[434:439],
|
128: _Opcode_name[435:439],
|
||||||
144: _Opcode_name[439:445],
|
129: _Opcode_name[439:444],
|
||||||
145: _Opcode_name[445:448],
|
144: _Opcode_name[444:450],
|
||||||
146: _Opcode_name[448:450],
|
145: _Opcode_name[450:453],
|
||||||
147: _Opcode_name[450:453],
|
146: _Opcode_name[453:455],
|
||||||
151: _Opcode_name[453:458],
|
147: _Opcode_name[455:458],
|
||||||
152: _Opcode_name[458:466],
|
151: _Opcode_name[458:463],
|
||||||
153: _Opcode_name[466:470],
|
152: _Opcode_name[463:471],
|
||||||
154: _Opcode_name[470:473],
|
153: _Opcode_name[471:475],
|
||||||
155: _Opcode_name[473:479],
|
154: _Opcode_name[475:478],
|
||||||
156: _Opcode_name[479:482],
|
155: _Opcode_name[478:484],
|
||||||
157: _Opcode_name[482:485],
|
156: _Opcode_name[484:487],
|
||||||
158: _Opcode_name[485:488],
|
157: _Opcode_name[487:490],
|
||||||
159: _Opcode_name[488:491],
|
158: _Opcode_name[490:493],
|
||||||
160: _Opcode_name[491:494],
|
159: _Opcode_name[493:496],
|
||||||
161: _Opcode_name[494:497],
|
160: _Opcode_name[496:499],
|
||||||
162: _Opcode_name[497:500],
|
161: _Opcode_name[499:502],
|
||||||
168: _Opcode_name[500:503],
|
162: _Opcode_name[502:505],
|
||||||
169: _Opcode_name[503:506],
|
168: _Opcode_name[505:508],
|
||||||
170: _Opcode_name[506:509],
|
169: _Opcode_name[508:511],
|
||||||
171: _Opcode_name[509:516],
|
170: _Opcode_name[511:514],
|
||||||
172: _Opcode_name[516:522],
|
171: _Opcode_name[514:521],
|
||||||
177: _Opcode_name[522:524],
|
172: _Opcode_name[521:527],
|
||||||
179: _Opcode_name[524:532],
|
177: _Opcode_name[527:529],
|
||||||
180: _Opcode_name[532:543],
|
179: _Opcode_name[529:537],
|
||||||
181: _Opcode_name[543:545],
|
180: _Opcode_name[537:548],
|
||||||
182: _Opcode_name[545:548],
|
181: _Opcode_name[548:550],
|
||||||
183: _Opcode_name[548:550],
|
182: _Opcode_name[550:553],
|
||||||
184: _Opcode_name[550:553],
|
183: _Opcode_name[553:555],
|
||||||
185: _Opcode_name[553:556],
|
184: _Opcode_name[555:558],
|
||||||
186: _Opcode_name[556:559],
|
185: _Opcode_name[558:561],
|
||||||
187: _Opcode_name[559:565],
|
186: _Opcode_name[561:564],
|
||||||
192: _Opcode_name[565:569],
|
187: _Opcode_name[564:570],
|
||||||
193: _Opcode_name[569:575],
|
192: _Opcode_name[570:574],
|
||||||
194: _Opcode_name[575:584],
|
193: _Opcode_name[574:580],
|
||||||
195: _Opcode_name[584:592],
|
194: _Opcode_name[580:589],
|
||||||
196: _Opcode_name[592:601],
|
195: _Opcode_name[589:597],
|
||||||
197: _Opcode_name[601:611],
|
196: _Opcode_name[597:606],
|
||||||
198: _Opcode_name[611:620],
|
197: _Opcode_name[606:616],
|
||||||
200: _Opcode_name[620:626],
|
198: _Opcode_name[616:625],
|
||||||
202: _Opcode_name[626:630],
|
200: _Opcode_name[625:631],
|
||||||
203: _Opcode_name[630:636],
|
202: _Opcode_name[631:635],
|
||||||
204: _Opcode_name[636:640],
|
203: _Opcode_name[635:641],
|
||||||
205: _Opcode_name[640:646],
|
204: _Opcode_name[641:645],
|
||||||
206: _Opcode_name[646:654],
|
205: _Opcode_name[645:651],
|
||||||
207: _Opcode_name[654:660],
|
206: _Opcode_name[651:659],
|
||||||
208: _Opcode_name[660:667],
|
207: _Opcode_name[659:665],
|
||||||
209: _Opcode_name[667:679],
|
208: _Opcode_name[665:672],
|
||||||
210: _Opcode_name[679:685],
|
209: _Opcode_name[672:684],
|
||||||
211: _Opcode_name[685:695],
|
210: _Opcode_name[684:690],
|
||||||
216: _Opcode_name[695:701],
|
211: _Opcode_name[690:700],
|
||||||
217: _Opcode_name[701:707],
|
216: _Opcode_name[700:706],
|
||||||
219: _Opcode_name[707:714],
|
217: _Opcode_name[706:712],
|
||||||
240: _Opcode_name[714:719],
|
219: _Opcode_name[712:719],
|
||||||
241: _Opcode_name[719:729],
|
240: _Opcode_name[719:724],
|
||||||
|
241: _Opcode_name[724:734],
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Opcode) String() string {
|
func (i Opcode) String() string {
|
||||||
|
|
|
@ -679,6 +679,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
panic("bad index")
|
panic("bad index")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case opcode.CLEAR:
|
||||||
|
v.estack.Clear()
|
||||||
|
|
||||||
case opcode.DUP:
|
case opcode.DUP:
|
||||||
v.estack.Push(v.estack.Dup(0))
|
v.estack.Push(v.estack.Dup(0))
|
||||||
|
|
||||||
|
|
|
@ -1700,6 +1700,15 @@ func TestXDROPgood(t *testing.T) {
|
||||||
assert.Equal(t, int64(1), vm.estack.Peek(1).BigInt().Int64())
|
assert.Equal(t, int64(1), vm.estack.Peek(1).BigInt().Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCLEAR(t *testing.T) {
|
||||||
|
prog := makeProgram(opcode.CLEAR)
|
||||||
|
v := load(prog)
|
||||||
|
v.estack.PushVal(123)
|
||||||
|
require.Equal(t, 1, v.estack.Len())
|
||||||
|
require.NoError(t, v.Run())
|
||||||
|
require.Equal(t, 0, v.estack.Len())
|
||||||
|
}
|
||||||
|
|
||||||
func TestINVERTbadNoitem(t *testing.T) {
|
func TestINVERTbadNoitem(t *testing.T) {
|
||||||
prog := makeProgram(opcode.INVERT)
|
prog := makeProgram(opcode.INVERT)
|
||||||
runWithArgs(t, prog, nil)
|
runWithArgs(t, prog, nil)
|
||||||
|
|
Loading…
Reference in a new issue