Skip to main content

Crate rhue_bytecode

Crate rhue_bytecode 

Source
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§

ChunkTypes
The types saved with a chunk, as Luau type syntax.
InlineCache
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.
LoadError
Why some bytes couldn’t load as a chunk.
LocalVar
A local variable, for debuggers: which register holds it, and when.
Proto
A compiled function prototype, what the VM actually runs.
TableTemplate
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.
UpvalDesc
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 as InlineCache, clones start unmarked and it never affects equality.
VerifyError
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 and K(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) turns f64::floor into. Matches f64::floor exactly 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 bytes start 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 an Rc).
write_chunk
Saves a main chunk, plus the types it exports if you give them.