Expand description
Bytecode representation for the Maat virtual machine.
This crate provides a compact bytecode format for representing Maat programs. Instructions consist of an opcode byte followed by zero or more operand bytes, with all multi-byte operands encoded in big-endian format.
§Example
use maat_bytecode::{Instructions, Opcode, encode};
// Encode some bytecode instructions
let const_instr = encode(Opcode::Constant, &[0]);
let add_instr = encode(Opcode::Add, &[]);
// Combine into an instruction sequence
let mut bytecode = Instructions::from(const_instr);
bytecode.extend(&Instructions::from(add_instr));
// Display as disassembly
println!("{}", bytecode);Structs§
- Bytecode
- Compiled bytecode output containing instructions and constants.
- Instruction
- Tracks the most recently emitted instruction for peephole operations.
- Instructions
- A sequence of bytecode instructions.
Enums§
Constants§
- MAX_
CONSTANT_ POOL_ SIZE - Maximum number of constants in the constant pool.
- MAX_
ENUM_ VARIANTS - Maximum number of variants an enum may have.
- MAX_
FRAMES - Maximum number of call frames on the VM’s frame stack.
- MAX_
GLOBALS - Maximum number of global variable bindings.
- MAX_
LOCALS - Maximum number of local variable bindings per function scope.
- MAX_
STACK_ SIZE - Maximum number of elements that can be pushed onto the VM’s stack.
Functions§
- decode_
operands - Decodes operands from an instruction byte slice.
- encode
- Encodes a bytecode instruction from an opcode and operands.