97 lines
4.1 KiB
Plaintext
97 lines
4.1 KiB
Plaintext
Operations
|
|
----------
|
|
|
|
Operations take either 0 or 1 parameter. The ones that take a parameter, it can be either a int8, int16 or int32.
|
|
|
|
Instructions follow this logic:
|
|
|
|
00 ~ 9F : no parameter
|
|
A0 ~ BF : int8 (1 byte)
|
|
C0 ~ DF : int16 (2 bytes)
|
|
E0 ~ FF : int32 (4 bytes)
|
|
|
|
The operations of 1, 2 and 4 bytes are always interchangeable by adding/subtracting 0x20.
|
|
|
|
,----------- no parameter
|
|
| ,-------- int8
|
|
| | ,----- int16
|
|
| | | ,-- int32
|
|
NP I8 I16 I32 Opc Instruction Description
|
|
|
|
Stack operations:
|
|
a0 c0 e0 pushi [int] Push int
|
|
a1 c1 e1 pushc [index] Push constant
|
|
a2 c2 e2 pushf [function] Push function id
|
|
00 pushn Push nil
|
|
01 pushz Push zero (or false)
|
|
02 pusht Push true
|
|
03 newa Push (create) empty array
|
|
04 newt Push (create) empty table
|
|
05 pop
|
|
06 dup
|
|
|
|
Local variables:
|
|
a3 c3 e3 pushv [int] Push n nil values into the stack (used to init local vars)
|
|
ab cb eb set [index] Set value in stack position (set local variable)
|
|
a4 c4 e4 dupv [index] Duplicate stack value (load local variable)
|
|
a5 c5 e5 setg [int] Set global variable
|
|
a6 c6 e6 getg [int] Get global variable
|
|
|
|
Function operations:
|
|
a7 c7 e7 call [n_pars] Enter function on stack toplevel (passing n next stack values as parameters)
|
|
10 ret Leave a function (return value in stack)
|
|
11 retn Leave a function (return nil)
|
|
|
|
Table and array operations:
|
|
16 getkv Get table's value based on key (pull 1 value, push 1 value)
|
|
17 setkv Set table's key and value (pull 2 values from stack)
|
|
a8 c8 e8 geti Get array's position value
|
|
a9 c9 e9 seti Set array's position value
|
|
18 appnd Add value to the end of array
|
|
19 next Push the next pair into the stack (for loops)
|
|
1a smt Set value metatable
|
|
1b mt Get value metatable
|
|
|
|
Logical/arithmetic:
|
|
20 sum Sum top 2 values in stack
|
|
21 sub Subtract top 2 values in stack
|
|
22 mul Multiply top 2 values in stack
|
|
23 div Float division
|
|
24 idiv Integer division
|
|
25 mod Modulo
|
|
26 eq Equality
|
|
27 neq Inequality
|
|
28 lt Less than
|
|
29 lte Less than or equals
|
|
2a gt Greater than
|
|
2b gte Greater than or equals
|
|
2c and Bitwise AND
|
|
2d or Bitwise OR
|
|
2e xor Bitwise XOR
|
|
2f pow Power
|
|
30 shl Shift left
|
|
31 shr Shift right
|
|
|
|
Other value operations:
|
|
40 len Get table, array or string size
|
|
41 type Get type from value at the top of the stack
|
|
aa cast [type] Cast type to another type
|
|
42 ver Return VM version
|
|
|
|
External code:
|
|
48 cmpl Compile code to assembly
|
|
49 asmbl Assemble code to bytecode format
|
|
4a load Load bytecode as function (will place function on stack)
|
|
|
|
Control flow (the destination is always a 16-bit field):
|
|
ca bz [pc] Branch if zero
|
|
cb bnz [pc] Branch if not zero
|
|
cc jmp [pc] Unconditional jump
|
|
* Jumps can only happen within the same function.
|
|
|
|
Memory management:
|
|
4b gc Call garbage collector
|
|
|
|
Error handling: (0xa0~0xaf)
|
|
???
|