Expand description
VibeScript bytecode opcodes (vibe-bc-0.1).
Stack-based bytecode for the VibeScript 0.1 language. Each opcode is a single byte, optionally followed by operand bytes. The VM is a simple stack machine: expressions push values onto the stack, statements consume them.
§Encoding
┌─────────────────────────────────────────────────────────────┐
│ Chunk │
│ ┌──────────┬──────────────┬───────────────────────────────┐ │
│ │ magic │ version │ constants + code + functions │ │
│ │ 4 bytes │ 2 bytes │ ... │ │
│ └──────────┴──────────────┴───────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘§Opcode table
| Opcode | Hex | Operand | Stack effect |
|---|---|---|---|
PUSH_NULL | 0x00 | — | → null |
PUSH_BOOL | 0x01 | u8 (0 or 1) | → bool |
PUSH_INT | 0x02 | i64 LE | → i64 |
PUSH_UINT | 0x03 | u64 LE | → u64 |
PUSH_FLOAT | 0x04 | f64 LE bits | → f64 |
PUSH_STRING | 0x05 | u16 const_idx | → string |
PUSH_IRI | 0x06 | u16 const_idx | → iri |
LOAD_VAR | 0x07 | u16 slot | → value |
STORE_VAR | 0x08 | u16 slot | value → |
POP | 0x09 | — | value → |
DUP | 0x0A | — | value → value value |
ADD | 0x10 | — | a b → a+b |
SUB | 0x11 | — | a b → a-b |
MUL | 0x12 | — | a b → a*b |
DIV | 0x13 | — | a b → a/b |
REM | 0x14 | — | a b → a%b |
NEG | 0x15 | — | a → -a |
NOT | 0x16 | — | a → !a |
EQ | 0x17 | — | a b → a==b |
NE | 0x18 | — | a b → a!=b |
LT | 0x19 | — | a b → a<b |
LE | 0x1A | — | a b → a<=b |
GT | 0x1B | — | a b → a>b |
GE | 0x1C | — | a b → a>=b |
AND | 0x1D | — | a b → a&&b |
OR | 0x1E | — | a b → a |
JUMP | 0x20 | u16 offset | — |
JUMP_IF_FALSE | 0x21 | u16 offset | bool → |
JUMP_IF_TRUE | 0x22 | u16 offset | bool → |
CALL_FN | 0x30 | u16 fn_idx | args… → result |
CALL_HOST | 0x31 | u16 path_idx u8 | args… → result |
CALL_USER | 0x32 | u16 fn_idx u8 | args… → result |
RETURN | 0x33 | — | value → (return) |
MAKE_LIST | 0x40 | u16 count | values… → list |
MAKE_RECORD | 0x41 | u16 count | kv… → record |
GET_MEMBER | 0x42 | u16 name_idx | record → value |
GET_INDEX | 0x43 | — | list index → value |
TRY | 0x44 | u16 catch_off | value → unwrapped |
EFFECT | 0x45 | — | value → |
HALT | 0xFF | — | — |
Structs§
- Chunk
- A compiled bytecode chunk — the unit of compilation and execution.
- Func
Meta - Metadata for a compiled user-defined function.
Enums§
Constants§
- MAGIC
- Magic bytes identifying a
vibe-bc-0.1chunk. - MAX_
CODE - Maximum code size in bytes.
- MAX_
CONSTANTS - Maximum number of constants in a chunk.
- MAX_
FUNCTIONS - Maximum number of user-defined functions.
- MAX_
LOCALS - Maximum number of local variable slots.
- VERSION
- Bytecode format version.