vm: implement NEWBUFFER opcode
This commit is contained in:
parent
a3a3a77431
commit
a5f6e0e53d
4 changed files with 78 additions and 61 deletions
|
@ -146,10 +146,11 @@ const (
|
||||||
STARG Opcode = 0x87
|
STARG Opcode = 0x87
|
||||||
|
|
||||||
// Splice
|
// Splice
|
||||||
CAT Opcode = 0x8B
|
NEWBUFFER Opcode = 0x88
|
||||||
SUBSTR Opcode = 0x8C
|
CAT Opcode = 0x8B
|
||||||
LEFT Opcode = 0x8D
|
SUBSTR Opcode = 0x8C
|
||||||
RIGHT Opcode = 0x8E
|
LEFT Opcode = 0x8D
|
||||||
|
RIGHT Opcode = 0x8E
|
||||||
|
|
||||||
// Bitwise logic
|
// Bitwise logic
|
||||||
INVERT Opcode = 0x90
|
INVERT Opcode = 0x90
|
||||||
|
|
|
@ -132,6 +132,7 @@ func _() {
|
||||||
_ = x[STARG5-133]
|
_ = x[STARG5-133]
|
||||||
_ = x[STARG6-134]
|
_ = x[STARG6-134]
|
||||||
_ = x[STARG-135]
|
_ = x[STARG-135]
|
||||||
|
_ = x[NEWBUFFER-136]
|
||||||
_ = x[CAT-139]
|
_ = x[CAT-139]
|
||||||
_ = x[SUBSTR-140]
|
_ = x[SUBSTR-140]
|
||||||
_ = x[LEFT-141]
|
_ = x[LEFT-141]
|
||||||
|
@ -190,7 +191,7 @@ func _() {
|
||||||
_ = x[CONVERT-219]
|
_ = x[CONVERT-219]
|
||||||
}
|
}
|
||||||
|
|
||||||
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHAPUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLCALLAABORTASSERTTHROWRETSYSCALLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLREVERSE3REVERSE4REVERSENINITSSLOTINITSLOTLDSFLD0LDSFLD1LDSFLD2LDSFLD3LDSFLD4LDSFLD5LDSFLD6LDSFLDSTSFLD0STSFLD1STSFLD2STSFLD3STSFLD4STSFLD5STSFLD6STSFLDLDLOC0LDLOC1LDLOC2LDLOC3LDLOC4LDLOC5LDLOC6LDLOCSTLOC0STLOC1STLOC2STLOC3STLOC4STLOC5STLOC6STLOCLDARG0LDARG1LDARG2LDARG3LDARG4LDARG5LDARG6LDARGSTARG0STARG1STARG2STARG3STARG4STARG5STARG6STARGCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERT"
|
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHAPUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLCALLAABORTASSERTTHROWRETSYSCALLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLREVERSE3REVERSE4REVERSENINITSSLOTINITSLOTLDSFLD0LDSFLD1LDSFLD2LDSFLD3LDSFLD4LDSFLD5LDSFLD6LDSFLDSTSFLD0STSFLD1STSFLD2STSFLD3STSFLD4STSFLD5STSFLD6STSFLDLDLOC0LDLOC1LDLOC2LDLOC3LDLOC4LDLOC5LDLOC6LDLOCSTLOC0STLOC1STLOC2STLOC3STLOC4STLOC5STLOC6STLOCLDARG0LDARG1LDARG2LDARG3LDARG4LDARG5LDARG6LDARGSTARG0STARG1STARG2STARG3STARG4STARG5STARG6STARGNEWBUFFERCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERT"
|
||||||
|
|
||||||
var _Opcode_map = map[Opcode]string{
|
var _Opcode_map = map[Opcode]string{
|
||||||
0: _Opcode_name[0:8],
|
0: _Opcode_name[0:8],
|
||||||
|
@ -314,62 +315,63 @@ var _Opcode_map = map[Opcode]string{
|
||||||
133: _Opcode_name[712:718],
|
133: _Opcode_name[712:718],
|
||||||
134: _Opcode_name[718:724],
|
134: _Opcode_name[718:724],
|
||||||
135: _Opcode_name[724:729],
|
135: _Opcode_name[724:729],
|
||||||
139: _Opcode_name[729:732],
|
136: _Opcode_name[729:738],
|
||||||
140: _Opcode_name[732:738],
|
139: _Opcode_name[738:741],
|
||||||
141: _Opcode_name[738:742],
|
140: _Opcode_name[741:747],
|
||||||
142: _Opcode_name[742:747],
|
141: _Opcode_name[747:751],
|
||||||
144: _Opcode_name[747:753],
|
142: _Opcode_name[751:756],
|
||||||
145: _Opcode_name[753:756],
|
144: _Opcode_name[756:762],
|
||||||
146: _Opcode_name[756:758],
|
145: _Opcode_name[762:765],
|
||||||
147: _Opcode_name[758:761],
|
146: _Opcode_name[765:767],
|
||||||
151: _Opcode_name[761:766],
|
147: _Opcode_name[767:770],
|
||||||
152: _Opcode_name[766:774],
|
151: _Opcode_name[770:775],
|
||||||
153: _Opcode_name[774:778],
|
152: _Opcode_name[775:783],
|
||||||
154: _Opcode_name[778:781],
|
153: _Opcode_name[783:787],
|
||||||
155: _Opcode_name[781:787],
|
154: _Opcode_name[787:790],
|
||||||
156: _Opcode_name[787:790],
|
155: _Opcode_name[790:796],
|
||||||
157: _Opcode_name[790:793],
|
156: _Opcode_name[796:799],
|
||||||
158: _Opcode_name[793:796],
|
157: _Opcode_name[799:802],
|
||||||
159: _Opcode_name[796:799],
|
158: _Opcode_name[802:805],
|
||||||
160: _Opcode_name[799:802],
|
159: _Opcode_name[805:808],
|
||||||
161: _Opcode_name[802:805],
|
160: _Opcode_name[808:811],
|
||||||
162: _Opcode_name[805:808],
|
161: _Opcode_name[811:814],
|
||||||
168: _Opcode_name[808:811],
|
162: _Opcode_name[814:817],
|
||||||
169: _Opcode_name[811:814],
|
168: _Opcode_name[817:820],
|
||||||
170: _Opcode_name[814:817],
|
169: _Opcode_name[820:823],
|
||||||
171: _Opcode_name[817:824],
|
170: _Opcode_name[823:826],
|
||||||
172: _Opcode_name[824:830],
|
171: _Opcode_name[826:833],
|
||||||
177: _Opcode_name[830:832],
|
172: _Opcode_name[833:839],
|
||||||
179: _Opcode_name[832:840],
|
177: _Opcode_name[839:841],
|
||||||
180: _Opcode_name[840:851],
|
179: _Opcode_name[841:849],
|
||||||
181: _Opcode_name[851:853],
|
180: _Opcode_name[849:860],
|
||||||
182: _Opcode_name[853:856],
|
181: _Opcode_name[860:862],
|
||||||
183: _Opcode_name[856:858],
|
182: _Opcode_name[862:865],
|
||||||
184: _Opcode_name[858:861],
|
183: _Opcode_name[865:867],
|
||||||
185: _Opcode_name[861:864],
|
184: _Opcode_name[867:870],
|
||||||
186: _Opcode_name[864:867],
|
185: _Opcode_name[870:873],
|
||||||
187: _Opcode_name[867:873],
|
186: _Opcode_name[873:876],
|
||||||
192: _Opcode_name[873:877],
|
187: _Opcode_name[876:882],
|
||||||
193: _Opcode_name[877:883],
|
192: _Opcode_name[882:886],
|
||||||
194: _Opcode_name[883:892],
|
193: _Opcode_name[886:892],
|
||||||
195: _Opcode_name[892:900],
|
194: _Opcode_name[892:901],
|
||||||
196: _Opcode_name[900:909],
|
195: _Opcode_name[901:909],
|
||||||
197: _Opcode_name[909:919],
|
196: _Opcode_name[909:918],
|
||||||
198: _Opcode_name[919:928],
|
197: _Opcode_name[918:928],
|
||||||
200: _Opcode_name[928:934],
|
198: _Opcode_name[928:937],
|
||||||
202: _Opcode_name[934:938],
|
200: _Opcode_name[937:943],
|
||||||
203: _Opcode_name[938:944],
|
202: _Opcode_name[943:947],
|
||||||
204: _Opcode_name[944:948],
|
203: _Opcode_name[947:953],
|
||||||
205: _Opcode_name[948:954],
|
204: _Opcode_name[953:957],
|
||||||
206: _Opcode_name[954:962],
|
205: _Opcode_name[957:963],
|
||||||
207: _Opcode_name[962:968],
|
206: _Opcode_name[963:971],
|
||||||
208: _Opcode_name[968:975],
|
207: _Opcode_name[971:977],
|
||||||
209: _Opcode_name[975:987],
|
208: _Opcode_name[977:984],
|
||||||
210: _Opcode_name[987:993],
|
209: _Opcode_name[984:996],
|
||||||
211: _Opcode_name[993:1003],
|
210: _Opcode_name[996:1002],
|
||||||
216: _Opcode_name[1003:1009],
|
211: _Opcode_name[1002:1012],
|
||||||
217: _Opcode_name[1009:1015],
|
216: _Opcode_name[1012:1018],
|
||||||
219: _Opcode_name[1015:1022],
|
217: _Opcode_name[1018:1024],
|
||||||
|
219: _Opcode_name[1024:1031],
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Opcode) String() string {
|
func (i Opcode) String() string {
|
||||||
|
|
|
@ -635,6 +635,13 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
||||||
item := v.estack.Pop().Item()
|
item := v.estack.Pop().Item()
|
||||||
ctx.arguments.Set(int(parameter[0]), item)
|
ctx.arguments.Set(int(parameter[0]), item)
|
||||||
|
|
||||||
|
case opcode.NEWBUFFER:
|
||||||
|
n := toInt(v.estack.Pop().BigInt())
|
||||||
|
if n < 0 || n > MaxItemSize {
|
||||||
|
panic("invalid size")
|
||||||
|
}
|
||||||
|
v.estack.PushVal(NewBufferItem(make([]byte, n)))
|
||||||
|
|
||||||
case opcode.CAT:
|
case opcode.CAT:
|
||||||
b := v.estack.Pop().Bytes()
|
b := v.estack.Pop().Bytes()
|
||||||
a := v.estack.Pop().Bytes()
|
a := v.estack.Pop().Bytes()
|
||||||
|
|
|
@ -1154,6 +1154,13 @@ func TestDECBigResult(t *testing.T) {
|
||||||
checkVMFailed(t, vm)
|
checkVMFailed(t, vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNEWBUFFER(t *testing.T) {
|
||||||
|
prog := makeProgram(opcode.NEWBUFFER)
|
||||||
|
t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte{0, 0, 0}), 3))
|
||||||
|
t.Run("Negative", getTestFuncForVM(prog, nil, -1))
|
||||||
|
t.Run("TooBig", getTestFuncForVM(prog, nil, MaxItemSize+1))
|
||||||
|
}
|
||||||
|
|
||||||
func TestNEWARRAY0(t *testing.T) {
|
func TestNEWARRAY0(t *testing.T) {
|
||||||
prog := makeProgram(opcode.NEWARRAY0)
|
prog := makeProgram(opcode.NEWARRAY0)
|
||||||
runWithArgs(t, prog, []StackItem{})
|
runWithArgs(t, prog, []StackItem{})
|
||||||
|
|
Loading…
Reference in a new issue