vm: implement CALLT opcode

This commit is contained in:
Evgenii Stratonikov 2020-12-29 12:04:53 +03:00 committed by Evgeniy Stratonikov
parent 8fad05c5bb
commit bb706aa55b
2 changed files with 10 additions and 1 deletions

View file

@ -144,7 +144,7 @@ func (c *Context) Next() (opcode.Opcode, []byte, error) {
opcode.ENDTRY,
opcode.INITSSLOT, opcode.LDSFLD, opcode.STSFLD, opcode.LDARG, opcode.STARG, opcode.LDLOC, opcode.STLOC:
numtoread = 1
case opcode.INITSLOT, opcode.TRY:
case opcode.INITSLOT, opcode.TRY, opcode.CALLT:
numtoread = 2
case opcode.JMPL, opcode.JMPIFL, opcode.JMPIFNOTL, opcode.JMPEQL, opcode.JMPNEL,
opcode.JMPGTL, opcode.JMPGEL, opcode.JMPLTL, opcode.JMPLEL,

View file

@ -80,6 +80,9 @@ type VM struct {
// SyscallHandler handles SYSCALL opcode.
SyscallHandler func(v *VM, id uint32) error
// LoadToken handles CALLT opcode.
LoadToken func(id int32) error
trigger trigger.Type
// Invocations is a script invocation counter.
@ -1276,6 +1279,12 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
v.call(ctx, ptr.Position())
case opcode.CALLT:
id := int32(binary.LittleEndian.Uint16(parameter))
if err := v.LoadToken(id); err != nil {
panic(err)
}
case opcode.SYSCALL:
interopID := GetInteropID(parameter)
err := v.SyscallHandler(v, interopID)