vm

class Opcode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: bytes, Enum

Opcodes are similar to instructions in assembly language.

PUSHINT8

Pushes a 1-byte signed integer onto the stack.

PUSHINT16

Pushes a 2-byte signed integer onto the stack.

PUSHINT32

Pushes a 4-byte signed integer onto the stack.

PUSHINT64

Pushes a 8-byte signed integer onto the stack.

PUSHINT128

Pushes a 16-byte signed integer onto the stack.

PUSHINT256

Pushes a 32-byte signed integer onto the stack.

PUSHT

Pushes the boolean value True onto the stack.

PUSHF

Pushes the boolean value False onto the stack.

PUSHA

Converts the 4-bytes offset to a Pointer, and pushes it onto the stack.

PUSHNULL

The item null is pushed onto the stack.

PUSHDATA1

The next byte contains the number of bytes to be pushed onto the stack.

PUSHDATA2

The next two bytes contain the number of bytes to be pushed onto the stack.

PUSHDATA4

The next four bytes contain the number of bytes to be pushed onto the stack.

PUSHM1

The number -1 is pushed onto the stack.

PUSH0

The number 0 is pushed onto the stack.

PUSH1

The number 1 is pushed onto the stack.

PUSH2

The number 2 is pushed onto the stack.

PUSH3

The number 3 is pushed onto the stack.

PUSH4

The number 4 is pushed onto the stack.

PUSH5

The number 5 is pushed onto the stack.

PUSH6

The number 6 is pushed onto the stack.

PUSH7

The number 7 is pushed onto the stack.

PUSH8

The number 8 is pushed onto the stack.

PUSH9

The number 9 is pushed onto the stack.

PUSH10

The number 10 is pushed onto the stack.

PUSH11

The number 11 is pushed onto the stack.

PUSH12

The number 12 is pushed onto the stack.

PUSH13

The number 13 is pushed onto the stack.

PUSH14

The number 14 is pushed onto the stack.

PUSH15

The number 15 is pushed onto the stack.

PUSH16

The number 16 is pushed onto the stack.

NOP

The NOP operation does nothing. It is intended to fill in space if opcodes are patched.

JMP

Unconditionally transfers control to a target instruction. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMP_L

Unconditionally transfers control to a target instruction. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPIF

Transfers control to a target instruction if the value is True, not null, or non-zero. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPIF_L

Transfers control to a target instruction if the value is True, not null, or non-zero. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPIFNOT

Transfers control to a target instruction if the value is False, a null reference, or zero. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPIFNOT_L

Transfers control to a target instruction if the value is False, a null reference, or zero. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPEQ

Transfers control to a target instruction if two values are equal. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPEQ_L

Transfers control to a target instruction if two values are equal. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPNE

Transfers control to a target instruction when two values are not equal. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPNE_L

Transfers control to a target instruction when two values are not equal. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPGT

Transfers control to a target instruction if the first value is greater than the second value. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPGT_L

Transfers control to a target instruction if the first value is greater than the second value. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPGE

Transfers control to a target instruction if the first value is greater than or equal to the second value. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPGE_L

Transfers control to a target instruction if the first value is greater than or equal to the second value. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPLT

Transfers control to a target instruction if the first value is less than the second value. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPLT_L

Transfers control to a target instruction if the first value is less than the second value. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

JMPLE

Transfers control to a target instruction if the first value is less than or equal to the second value. The target instruction is represented as a 1-byte signed offset from the beginning of the current instruction.

JMPLE_L

Transfers control to a target instruction if the first value is less than or equal to the second value. The target instruction is represented as a 4-bytes signed offset from the beginning of the current instruction.

CALL

Calls the function at the target address which is represented as a 1-byte signed offset from the beginning of the current instruction.

CALL_L

Calls the function at the target address which is represented as a 4-bytes signed offset from the beginning of the current instruction.

CALLA

Pop the address of a function from the stack, and call the function.

CALLT

Calls the function which is described by the token.

ABORT

It turns the vm state to FAULT immediately, and cannot be caught.

ASSERT

Pop the top value of the stack, if it false, then exit vm execution and set vm state to FAULT.

THROW

Pop the top value of the stack, and throw it.

TRY

TRY CatchOffset(sbyte) FinallyOffset(sbyte). If there’s no catch body, set CatchOffset 0. If there’s no finally body, set FinallyOffset 0.

TRY_L

TRY_L CatchOffset(int) FinallyOffset(int). If there’s no catch body, set CatchOffset 0. If there’s no finally body, set FinallyOffset 0.

ENDTRY

Ensures that the appropriate surrounding finally blocks are executed. And then unconditionally transfers control to the specific target instruction, represented as a 1-byte signed offset from the beginning of the current instruction.

ENDTRY_L

Ensures that the appropriate surrounding finally blocks are executed. And then unconditionally transfers control to the specific target instruction, represented as a 4-byte signed offset from the beginning of the current instruction.

ENDFINALLY

End finally, If no exception happen or be catched, vm will jump to the target instruction of ENDTRY/ENDTRY_L. Otherwise vm will rethrow the exception to upper layer.

RET

Returns from the current method.

SYSCALL

Calls to an interop service.

DEPTH

Puts the number of stack items onto the stack.

DROP

Removes the top stack item.

NIP

Removes the second-to-top stack item.

XDROP

The item n back in the main stack is removed.

CLEAR

Clear the stack

DUP

Duplicates the top stack item.

OVER

Copies the second-to-top stack item to the top.

PICK

The item n back in the stack is copied to the top.

TUCK

The item at the top of the stack is copied and inserted before the second-to-top item.

SWAP

The top two items on the stack are swapped.

ROT

The top three items on the stack are rotated to the left.

ROLL

The item n back in the stack is moved to the top.

REVERSE3

Reverse the order of the top 3 items on the stack.

REVERSE4

Reverse the order of the top 4 items on the stack.

REVERSEN

Pop the number N on the stack, and reverse the order of the top N items on the stack.

INITSSLOT

Initialize the static field list for the current execution context.

INITSLOT

Initialize the argument slot and the local variable list for the current execution context.

LDSFLD0

Loads the static field at index 0 onto the evaluation stack.

LDSFLD1

Loads the static field at index 1 onto the evaluation stack.

LDSFLD2

Loads the static field at index 2 onto the evaluation stack.

LDSFLD3

Loads the static field at index 3 onto the evaluation stack.

LDSFLD4

Loads the static field at index 4 onto the evaluation stack.

LDSFLD5

Loads the static field at index 5 onto the evaluation stack.

LDSFLD6

Loads the static field at index 6 onto the evaluation stack.

LDSFLD

Loads the static field at a specified index onto the evaluation stack. The index is represented as a 1-byte unsigned integer.

STSFLD0

Stores the value on top of the evaluation stack in the static field list at index 0.

STSFLD1

Stores the value on top of the evaluation stack in the static field list at index 1.

STSFLD2

Stores the value on top of the evaluation stack in the static field list at index 2.

STSFLD3

Stores the value on top of the evaluation stack in the static field list at index 3.

STSFLD4

Stores the value on top of the evaluation stack in the static field list at index 4.

STSFLD5

Stores the value on top of the evaluation stack in the static field list at index 5.

STSFLD6

Stores the value on top of the evaluation stack in the static field list at index 6.

STSFLD

Stores the value on top of the evaluation stack in the static field list at a specified index. The index is represented as a 1-byte unsigned integer.

LDLOC0

Loads the local variable at index 0 onto the evaluation stack.

LDLOC1

Loads the local variable at index 1 onto the evaluation stack.

LDLOC2

Loads the local variable at index 2 onto the evaluation stack.

LDLOC3

Loads the local variable at index 3 onto the evaluation stack.

LDLOC4

Loads the local variable at index 4 onto the evaluation stack.

LDLOC5

Loads the local variable at index 5 onto the evaluation stack.

LDLOC6

Loads the local variable at index 6 onto the evaluation stack.

LDLOC

Loads the local variable at a specified index onto the evaluation stack. The index is represented as a 1-byte unsigned integer.

STLOC0

Stores the value on top of the evaluation stack in the local variable list at index 0.

STLOC1

Stores the value on top of the evaluation stack in the local variable list at index 1.

STLOC2

Stores the value on top of the evaluation stack in the local variable list at index 2.

STLOC3

Stores the value on top of the evaluation stack in the local variable list at index 3.

STLOC4

Stores the value on top of the evaluation stack in the local variable list at index 4.

STLOC5

Stores the value on top of the evaluation stack in the local variable list at index 5.

STLOC6

Stores the value on top of the evaluation stack in the local variable list at index 6.

STLOC

Stores the value on top of the evaluation stack in the local variable list at a specified index. The index is represented as a 1-byte unsigned integer.

LDARG0

Loads the argument at index 0 onto the evaluation stack.

LDARG1

Loads the argument at index 1 onto the evaluation stack.

LDARG2

Loads the argument at index 2 onto the evaluation stack.

LDARG3

Loads the argument at index 3 onto the evaluation stack.

LDARG4

Loads the argument at index 4 onto the evaluation stack.

LDARG5

Loads the argument at index 5 onto the evaluation stack.

LDARG6

Loads the argument at index 6 onto the evaluation stack.

LDARG

Loads the argument at a specified index onto the evaluation stack. The index is represented as a 1-byte unsigned integer.

STARG0

Stores the value on top of the evaluation stack in the argument slot at index 0.

STARG1

Stores the value on top of the evaluation stack in the argument slot at index 1.

STARG2

Stores the value on top of the evaluation stack in the argument slot at index 2.

STARG3

Stores the value on top of the evaluation stack in the argument slot at index 3.

STARG4

Stores the value on top of the evaluation stack in the argument slot at index 4.

STARG5

Stores the value on top of the evaluation stack in the argument slot at index 5.

STARG6

Stores the value on top of the evaluation stack in the argument slot at index 6.

STARG

Stores the value on top of the evaluation stack in the argument slot at a specified index. The index is represented as a 1-byte unsigned integer.

NEWBUFFER

Creates a new Buffer and pushes it onto the stack.

MEMCPY

Copies a range of bytes from one Buffer to another.

CAT

Concatenates two strings.

SUBSTR

Returns a section of a string.

LEFT

Keeps only characters left of the specified point in a string.

RIGHT

Keeps only characters right of the specified point in a string.

INVERT

Flips all of the bits in the input.

AND

Boolean and between each bit in the inputs.

OR

Boolean or between each bit in the inputs.

XOR

Boolean exclusive or between each bit in the inputs.

EQUAL

Returns 1 if the inputs are exactly equal, 0 otherwise.

NOTEQUAL

Returns 1 if the inputs are not equal, 0 otherwise.

SIGN

Puts the sign of top stack item on top of the main stack. If value is negative, put -1; if positive, put 1; if value is zero, put 0.

ABS

The input is made positive.

NEGATE

The sign of the input is flipped.

INC

1 is added to the input.

DEC

1 is subtracted from the input.

ADD

a is added to b.

SUB

b is subtracted from a.

MUL

a is multiplied by b.

DIV

a is divided by b.

MOD

Returns the remainder after dividing a by b.

POW

The result of raising value to the exponent power.

SQRT

Returns the square root of a specified number.

MODMUL

Performs modulus division on a number multiplied by another number.

MODPOW

Performs modulus division on a number raised to the power of another number. If the exponent is -1, it will have the calculation of the modular inverse.

SHL

Shifts a left b bits, preserving sign.

SHR

Shifts a right b bits, preserving sign.

NOT

If the input is 0 or 1, it is flipped. Otherwise the output will be 0.

BOOLAND

If both a and b are not 0, the output is 1. Otherwise 0.

BOOLOR

If a or b is not 0, the output is 1. Otherwise 0.

NZ

Returns 0 if the input is 0. 1 otherwise.

NUMEQUAL

Returns 1 if the numbers are equal, 0 otherwise.

NUMNOTEQUAL

Returns 1 if the numbers are not equal, 0 otherwise.

LT

Returns 1 if a is less than b, 0 otherwise.

LE

Returns 1 if a is less than or equal to b, 0 otherwise.

GT

Returns 1 if a is greater than b, 0 otherwise.

GE

Returns 1 if a is greater than or equal to b, 0 otherwise.

MIN

Returns the smaller of a and b.

MAX

Returns the larger of a and b.

WITHIN

Returns 1 if x is within the specified range (left-inclusive), 0 otherwise.

PACKMAP

A value n is taken from top of main stack. The next n*2 items on main stack are removed, put inside n-sized map and this map is put on top of the main stack.

PACKSTRUCT

A value n is taken from top of main stack. The next n items on main stack are removed, put inside n-sized struct and this struct is put on top of the main stack.

PACK

A value n is taken from top of main stack. The next n items on main stack are removed, put inside n-sized array and this array is put on top of the main stack.

UNPACK

A collection is removed from top of the main stack. Its elements are put on top of the main stack (in reverse order) and the collection size is also put on main stack.

NEWARRAY0

An empty array (with size 0) is put on top of the main stack.

NEWARRAY

A value n is taken from top of main stack. A null-filled array with size n is put on top of the main stack.

NEWARRAY_T

A value n is taken from top of main stack. An array of type T with size n is put on top of the main stack.

NEWSTRUCT0

An empty struct (with size 0) is put on top of the main stack.

NEWSTRUCT

A value n is taken from top of main stack. A zero-filled struct with size n is put on top of the main stack.

NEWMAP

A Map is created and put on top of the main stack.

SIZE

An array is removed from top of the main stack. Its size is put on top of the main stack.

HASKEY

An input index n (or key) and an array (or map) are removed from the top of the main stack. Puts True on top of main stack if array[n] (or map[n]) exist, and False otherwise.

KEYS

A map is taken from top of the main stack. The keys of this map are put on top of the main stack.

VALUES

A map is taken from top of the main stack. The values of this map are put on top of the main stack.

PICKITEM

An input index n (or key) and an array (or map) are taken from main stack. Element array[n] (or map[n]) is put on top of the main stack.

APPEND

The item on top of main stack is removed and appended to the second item on top of the main stack.

SETITEM

A value v, index n (or key) and an array (or map) are taken from main stack. Attribution array[n]=v (or map[n]=v) is performed.

REVERSEITEMS

An array is removed from the top of the main stack and its elements are reversed.

REMOVE

An input index n (or key) and an array (or map) are removed from the top of the main stack. Element array[n] (or map[n]) is removed.

CLEARITEMS

Remove all the items from the compound-type.

POPITEM

Remove the last element from an array, and push it onto the stack.

ISNULL

Returns true if the input is null;

ISTYPE

Returns true if the top item of the stack is of the specified type;

CONVERT

Returns true if the input is null;

ABORTMSG

Turns the vm state to FAULT immediately, and cannot be caught. Includes a reason.

ASSERTMSG

Pop the top value of the stack, if it false, then exit vm execution and set vm state to FAULT. Includes a reason.