Expand description
Rhue’s bytecode. Instruction encoding, opcodes, function prototypes, the arithmetic the constant folder and VM share, the verifier that checks a prototype before it runs, and the binary format chunks get saved in.
This is part of Rhue’s guts. If you’re embedding
Rhue, use the rhue crate, that’s the API that stays stable.
Structs§
- Chunk
Types - The types saved with a chunk, as Luau type syntax.
- Inline
Cache - Per-instruction slots the VM uses as inline caches. For a field or global access it remembers where in the table’s hash part the key was last time, so the next lookup can check that one entry instead of hashing (the key still gets compared, so a stale hint just costs a normal lookup).
- Instr
- A 32-bit instruction.
- Load
Error - Why some bytes couldn’t load as a chunk.
- Local
Var - A local variable, for debuggers: which register holds it, and when.
- Proto
- A compiled function prototype, what the VM actually runs.
- Table
Template - The shape of the tables a constructor makes (
DUPTABLE): sizes to reserve and the constant string keys it stores first, in order. Keys start out nil, which tables treat as tombstones, so the program can’t tell a template’s there except the constructor doesn’t have to grow the table and search for each key. - Upval
Desc - How a closure finds one of its upvalues when it gets created.
- Verified
- Remembers that a prototype passed
verify, so a chunk that runs a lot only gets checked once. Same asInlineCache, clones start unmarked and it never affects equality. - Verify
Error - Why a prototype was rejected.
Enums§
- ArithOp
- Constant
- A compile-time constant.
- Op
- Every opcode. The comment on each one gives its operands,
R(x)is register x andK(x)is constant x.
Constants§
- FORMAT_
VERSION - Bumped whenever the encoding or instruction set changes. Chunks from any other version get refused instead of misread. Formats 1 to 3 never shipped, so 4 is the first one any release reads.
- MAGIC
- The first bytes of every serialized chunk.
- MAX_
STACK - The most registers a function can use. The VM keeps a window of a bit more
than 256 slots above every frame, so this leaves room for the registers
above
R(A)that some instructions touch. - MAX_
TEMPLATE_ SIZE - The most array or hash slots a table template can reserve.
Functions§
- arith
- Luau’s number semantics, IEEE-754 doubles all the way.
- floor
x.floor()without the libm call baseline x86-64 (no SSE4.1) turnsf64::floorinto. Matchesf64::floorexactly for every input, signed zeros, infinities and NaN included.- format_
number - Formats a number like Luau’s
tostring: whole numbers print without a fraction (3), others use the shortest form that round-trips (0.1), and really big or small ones get an exponent (1e+20). - is_
chunk - Whether
bytesstart like a saved chunk. - read_
chunk - Reads a chunk and the types saved with it (none for chunks saved without). Not verified.
- verify
- Checks
proto(a main chunk) and everything nested in it. - verify_
once verify, skipped when this prototype already passed (it stays marked for as long as it lives, the code can’t change inside anRc).- write_
chunk - Saves a main chunk, plus the types it exports if you give them.