pub struct Chunk {
pub code: Vec<u8>,
pub constants: Vec<Constant>,
pub lines: Vec<u32>,
pub functions: Vec<CompiledFunction>,
}Expand description
A compiled chunk of bytecode.
Fields§
§code: Vec<u8>The bytecode instructions.
constants: Vec<Constant>Constant pool.
lines: Vec<u32>Source line numbers for each instruction (for error reporting).
functions: Vec<CompiledFunction>Compiled function bodies (for closures).
Implementations§
Source§impl Chunk
impl Chunk
pub fn new() -> Self
Sourcepub fn add_constant(&mut self, constant: Constant) -> u16
pub fn add_constant(&mut self, constant: Constant) -> u16
Add a constant and return its index.
Sourcepub fn emit_u16(&mut self, op: Op, arg: u16, line: u32)
pub fn emit_u16(&mut self, op: Op, arg: u16, line: u32)
Emit an instruction with a u16 argument.
Sourcepub fn emit_method_call(&mut self, name_idx: u16, arg_count: u8, line: u32)
pub fn emit_method_call(&mut self, name_idx: u16, arg_count: u8, line: u32)
Emit a method call: op + u16 (method name) + u8 (arg count).
Sourcepub fn current_offset(&self) -> usize
pub fn current_offset(&self) -> usize
Current code offset (for jump patching).
Sourcepub fn emit_jump(&mut self, op: Op, line: u32) -> usize
pub fn emit_jump(&mut self, op: Op, line: u32) -> usize
Emit a jump instruction with a placeholder offset. Returns the position to patch.
Sourcepub fn patch_jump(&mut self, patch_pos: usize)
pub fn patch_jump(&mut self, patch_pos: usize)
Patch a jump instruction at the given position to jump to the current offset.
Sourcepub fn disassemble(&self, name: &str) -> String
pub fn disassemble(&self, name: &str) -> String
Disassemble for debugging.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Chunk
impl RefUnwindSafe for Chunk
impl Send for Chunk
impl Sync for Chunk
impl Unpin for Chunk
impl UnsafeUnpin for Chunk
impl UnwindSafe for Chunk
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
Mutably borrows from an owned value. Read more