Skip to main content

Module op

Module op 

Source
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

OpcodeHexOperandStack effect
PUSH_NULL0x00—→ null
PUSH_BOOL0x01u8 (0 or 1)→ bool
PUSH_INT0x02i64 LE→ i64
PUSH_UINT0x03u64 LE→ u64
PUSH_FLOAT0x04f64 LE bits→ f64
PUSH_STRING0x05u16 const_idx→ string
PUSH_IRI0x06u16 const_idx→ iri
LOAD_VAR0x07u16 slot→ value
STORE_VAR0x08u16 slotvalue →
POP0x09—value →
DUP0x0A—value → value value
ADD0x10—a b → a+b
SUB0x11—a b → a-b
MUL0x12—a b → a*b
DIV0x13—a b → a/b
REM0x14—a b → a%b
NEG0x15—a → -a
NOT0x16—a → !a
EQ0x17—a b → a==b
NE0x18—a b → a!=b
LT0x19—a b → a<b
LE0x1A—a b → a<=b
GT0x1B—a b → a>b
GE0x1C—a b → a>=b
AND0x1D—a b → a&&b
OR0x1E—a b → a
JUMP0x20u16 offset—
JUMP_IF_FALSE0x21u16 offsetbool →
JUMP_IF_TRUE0x22u16 offsetbool →
CALL_FN0x30u16 fn_idxargs… → result
CALL_HOST0x31u16 path_idx u8args… → result
CALL_USER0x32u16 fn_idx u8args… → result
RETURN0x33—value → (return)
MAKE_LIST0x40u16 countvalues… → list
MAKE_RECORD0x41u16 countkv… → record
GET_MEMBER0x42u16 name_idxrecord → value
GET_INDEX0x43—list index → value
TRY0x44u16 catch_offvalue → unwrapped
EFFECT0x45—value →
HALT0xFF——

Structs§

Chunk
A compiled bytecode chunk — the unit of compilation and execution.
FuncMeta
Metadata for a compiled user-defined function.

Enums§

Const
A constant value in the constant pool.
Op
A single bytecode opcode.

Constants§

MAGIC
Magic bytes identifying a vibe-bc-0.1 chunk.
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.