104 lines
4.1 KiB
Plaintext
104 lines
4.1 KiB
Plaintext
VM data types:
|
|
| Type name | C type/Description |
|
|
|-----------+---------------------|
|
|
| i8 | int8_t |
|
|
| u8 | uint8_t |
|
|
| i16 | int16_t |
|
|
| u16 | uint16_t |
|
|
| i32 | int32_t |
|
|
| u32 | uint32_t |
|
|
| i64 | int64_t |
|
|
| u64 | uint64_t |
|
|
| ref | VM object reference |
|
|
|-----------+---------------------|
|
|
|
|
Each instruction is 4 bytes:
|
|
| Offset | Meaning |
|
|
|--------+----------|
|
|
| 0x00 | Opcode |
|
|
| 0x01 | Argument |
|
|
|--------+----------|
|
|
|
|
Integer opcodes:
|
|
| Opcode | Mnemonic | Argument count | Description |
|
|
|--------+----------+----------------+------------------|
|
|
| 0x04 | add | 2 | push (x + y) |
|
|
| 0x05 | sub | 2 | push (x - y) |
|
|
| 0x06 | mul | 2 | push (x * y) |
|
|
| 0x07 | div | 2 | push (x / y) |
|
|
| 0x08 | mod | 2 | push (x % y) |
|
|
| 0x09 | neg | 1 | push (-x) |
|
|
| 0x0A | and | 2 | push (x and y) |
|
|
| 0x0B | or | 2 | push (x or y) |
|
|
| 0x0C | not | 1 | push (~x) |
|
|
| 0x0D | xor | 2 | push (x xor y) |
|
|
| 0x0E | shl | 1 | push (x << imm) |
|
|
| 0x0F | shr | 1 | push (x >> imm) |
|
|
| 0x10 | addi | 1 | push (x + imm) |
|
|
| 0x11 | ud | - | undefined |
|
|
| 0x12 | eq | 2 | push (x == y) |
|
|
| 0x13 | neq | 2 | push (x != y) |
|
|
| 0x14 | gt | 2 | push (x > y) |
|
|
| 0x15 | ge | 2 | push (x >= y) |
|
|
| 0x16 | lt | 2 | push (x < y) |
|
|
| 0x17 | le | 2 | push (x <= y) |
|
|
| 0x18 | ori | 1 | push (x or imm) |
|
|
| 0x19 | andi | 1 | push (x and imm) |
|
|
| 0x1A | xori | 1 | push (x xor imm) |
|
|
| 0x1B | eqi | 1 | push (x == imm) |
|
|
|--------+----------+----------------+------------------|
|
|
|
|
Integer casts:
|
|
| Opcode | Mnemonic | Description |
|
|
|--------+----------+---------------------------|
|
|
| 0x20 | cvt_i8 | |
|
|
| 0x21 | cvt_u8 | |
|
|
| 0x22 | cvt_i16 | |
|
|
| 0x23 | cvt_u16 | |
|
|
| 0x24 | cvt_i32 | |
|
|
| 0x25 | cvt_u32 | |
|
|
| 0x26 | cvt_i64 | |
|
|
| 0x27 | cvt_u64 | |
|
|
| 0x28 | bnorm | Normalize integer to bool |
|
|
|--------+----------+---------------------------|
|
|
|
|
Constant loads:
|
|
| Opcode | Mnemonic | Description |
|
|
|--------+----------+----------------------|
|
|
| 0x30 | ldc | push constant |
|
|
| 0x31 | ldnil | push null ref |
|
|
| 0x32 | ldi | push immediate value |
|
|
|--------+----------+----------------------|
|
|
|
|
List operations:
|
|
| Opcode | Mnemonic |
|
|
|--------+----------|
|
|
| 0x40 | car |
|
|
| 0x41 | cdr |
|
|
| 0x42 | cadr |
|
|
| 0x43 | cdar |
|
|
| 0x44 | cddr |
|
|
| 0x45 | cons |
|
|
|--------+----------|
|
|
|
|
Reference operations:
|
|
| Opcode | Mnemonic | Description |
|
|
|--------+----------+-----------------|
|
|
| 0x46 | test | push (x == nil) |
|
|
| 0x47 | dup | push x; push x |
|
|
| 0x48 | drop | x; |
|
|
| 0x49 | typeid | push (typeid x) |
|
|
| 0x4A | sizeof | push (sizeof x) |
|
|
|--------+----------+-----------------|
|
|
|
|
Debug operations:
|
|
| Opcode | Mnemonic | Description |
|
|
|--------+----------+--------------------------------------------------|
|
|
| 0xF0 | abort | Abort VM execution |
|
|
| 0xF1 | break | Pause VM for external examination |
|
|
| 0xF2 | peek1 | Trace information about stack head |
|
|
| 0xF3 | peek2 | Trace information about a pair of stack elements |
|
|
|--------+----------+--------------------------------------------------|
|
|
|
|
TBD: variable operations
|