pub struct BytecodeChunk {Show 14 fields
pub name: String,
pub instructions: Vec<Instruction>,
pub constants: Vec<Value>,
pub register_count: u8,
pub parameter_count: u8,
pub local_names: Vec<String>,
pub line_numbers: Vec<usize>,
pub loop_bodies: Vec<Arc<Expr>>,
pub method_calls: Vec<(Arc<Expr>, String, Vec<Arc<Expr>>)>,
pub match_exprs: Vec<(Arc<Expr>, Vec<MatchArm>)>,
pub closures: Vec<(Vec<String>, Arc<Expr>)>,
pub array_element_regs: Vec<Vec<u8>>,
pub object_fields: Vec<Vec<(String, u8)>>,
pub locals_map: HashMap<String, u8>,
}Expand description
Bytecode function chunk
Contains compiled bytecode and associated metadata for a function.
Fields§
§name: StringFunction name (for debugging)
instructions: Vec<Instruction>Bytecode instructions
constants: Vec<Value>Constant pool (literals used in the function)
register_count: u8Number of registers required
parameter_count: u8Number of parameters
local_names: Vec<String>Local variable names (for debugging)
line_numbers: Vec<usize>Source line numbers (parallel to instructions for debugging)
loop_bodies: Vec<Arc<Expr>>Loop bodies (for hybrid execution - OPT-012) Stores AST bodies for for-loops to enable interpreter delegation
method_calls: Vec<(Arc<Expr>, String, Vec<Arc<Expr>>)>Method calls (for hybrid execution - OPT-014)
Stores AST for method calls to enable interpreter delegation
Each entry: (receiver_expr, method_name, args_exprs)
match_exprs: Vec<(Arc<Expr>, Vec<MatchArm>)>Match expressions (for hybrid execution - OPT-018)
Stores AST for match expressions to enable interpreter delegation
Each entry: (match_expr, match_arms)
closures: Vec<(Vec<String>, Arc<Expr>)>Closures (for hybrid execution - OPT-019) Stores AST for closures to enable interpreter delegation Each entry: (params, body) - environment captured at runtime
array_element_regs: Vec<Vec<u8>>Array element registers (for runtime array construction - OPT-020)
Stores register lists for NewArray opcodes (element registers may not be contiguous)
object_fields: Vec<Vec<(String, u8)>>Object field data (for runtime object construction - OPT-020)
Stores (key, value_register) pairs for NewObject opcodes
locals_map: HashMap<String, u8>Local variable name to register mapping (for hybrid execution) Enables synchronization between bytecode registers and interpreter scope
Implementations§
Source§impl BytecodeChunk
impl BytecodeChunk
Sourcepub fn emit(&mut self, instruction: Instruction, line: usize) -> usize
pub fn emit(&mut self, instruction: Instruction, line: usize) -> usize
Add an instruction to the chunk
Returns the index where the instruction was added (for jump patching).
Sourcepub fn add_constant(&mut self, value: Value) -> u16
pub fn add_constant(&mut self, value: Value) -> u16
Add a constant to the constant pool
Returns the index of the constant (existing or newly added).
Sourcepub fn patch_jump(&mut self, jump_index: usize)
pub fn patch_jump(&mut self, jump_index: usize)
Patch a jump instruction at the given index
Updates the jump offset to point to the current instruction position.
Trait Implementations§
Source§impl Clone for BytecodeChunk
impl Clone for BytecodeChunk
Source§fn clone(&self) -> BytecodeChunk
fn clone(&self) -> BytecodeChunk
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BytecodeChunk
impl !RefUnwindSafe for BytecodeChunk
impl !Send for BytecodeChunk
impl !Sync for BytecodeChunk
impl Unpin for BytecodeChunk
impl !UnwindSafe for BytecodeChunk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more