rhue-bytecode 2.2.0

Rhue bytecode: instructions, prototypes, the saved-chunk format and the verifier
Documentation

This is part of Rhue's insides. If you just want to run scripts from Rust, use rhue, it's the only crate whose API is meant to stay stable. Everything else (this one included) can change between minor versions.

What's in here:

  • Instr and Op — the instruction encoding. The opcode's in the low byte like Luau's, then A, B, C (or Bx/sBx, or a 24-bit jump)
  • Proto — one compiled function: code, constants, spans for every instruction, nested prototypes, debug info, table templates. disassemble() gives you a listing
  • verify — checks a prototype before the VM runs it: registers in bounds, constants the right type, jumps landing on real instructions, the top protocol, captures that exist. Bad bytecode gets refused instead of panicking the VM
  • to_bytes / from_bytes — the saved-chunk format (with the source text, so errors still point at lines, and optionally the chunk's types). Loading only checks the shape of the bytes, run verify on whatever you load
  • arith — the arithmetic, shared by the constant folder and the VM so a folded 2 ^ 0.5 and a computed one are bit-for-bit the same

A listing looks like this:

function sq (3 instructions, 0 constants, 2 registers, 1 params)
     0  MUL       R1 R0 R0
     1  RETURN    R1 1
     2  RETURN    R0 0

License

MIT or Apache-2.0, same as the rest of Rhue.