pub struct Chunk {
pub code: Vec<u8>,
pub constants: Vec<VMValue>,
pub lines: Vec<u32>,
pub key_symbols: Vec<Option<Symbol>>,
pub source_file: Option<String>,
}Expand description
A compiled bytecode chunk.
Contains the instruction stream, a constant pool for literal values and nested function chunks, and source line information for error reporting.
Fields§
§code: Vec<u8>The raw bytecode instruction stream.
constants: Vec<VMValue>Constant pool: literals, string keys, nested chunks.
lines: Vec<u32>Source line number for each byte in code (1:1 mapping).
Used for error messages. Line 0 means “unknown”.
key_symbols: Vec<Option<Symbol>>Pre-resolved symbols for constant pool entries that are string keys.
Maps constant index -> interned Symbol. Populated at compile time
so the VM can skip the intern() call on every GetAttr/HasAttr
dispatch. Only entries used as attrset keys are populated.
source_file: Option<String>The source file this chunk was compiled from (if known). Used for error diagnostics — not set for inline expressions.
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn write_byte(&mut self, byte: u8, line: u32)
pub fn write_byte(&mut self, byte: u8, line: u32)
Write a single byte to the instruction stream.
Sourcepub fn write_u16(&mut self, value: u16, line: u32)
pub fn write_u16(&mut self, value: u16, line: u32)
Write a u16 operand as two little-endian bytes.
Sourcepub fn write_u32(&mut self, value: u32, line: u32)
pub fn write_u32(&mut self, value: u32, line: u32)
Write a u32 operand as four little-endian bytes.
Sourcepub fn add_constant(&mut self, value: VMValue) -> Result<u16, CompileError>
pub fn add_constant(&mut self, value: VMValue) -> Result<u16, CompileError>
Add a constant to the pool and return its index.
Returns an error if the pool exceeds u16::MAX entries.
Sourcepub fn add_key_constant(
&mut self,
value: VMValue,
sym: Symbol,
) -> Result<u16, CompileError>
pub fn add_key_constant( &mut self, value: VMValue, sym: Symbol, ) -> Result<u16, CompileError>
Add a constant string and its pre-interned symbol to the pool.
The symbol is stored in key_symbols so the VM can skip the
intern() call when resolving attribute keys at runtime.
Sourcepub fn read_u16(&self, offset: usize) -> u16
pub fn read_u16(&self, offset: usize) -> u16
Read a u16 operand from the bytecode at the given offset.
Returns the value and the offset past the two bytes.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Chunk
impl !Send for Chunk
impl !Sync for Chunk
impl !UnwindSafe for Chunk
impl Freeze for Chunk
impl Unpin for Chunk
impl UnsafeUnpin for Chunk
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.