Skip to main content

Chunk

Struct Chunk 

Source
pub struct Chunk {
    pub code: Vec<u8>,
    pub constants: Vec<Constant>,
    pub lines: Vec<u32>,
    pub columns: Vec<u32>,
    pub source_file: Option<String>,
    pub functions: Vec<CompiledFunction>,
    /* private fields */
}
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).

§columns: Vec<u32>

Source column numbers for each instruction (for error reporting). Parallel to lines; 0 means no column info available.

§source_file: Option<String>

Source file that this chunk was compiled from, when known. Set for chunks compiled from imported modules so runtime errors can report the correct file path for each frame instead of always pointing at the entry-point pipeline.

§functions: Vec<CompiledFunction>

Compiled function bodies (for closures).

Implementations§

Source§

impl Chunk

Source

pub fn new() -> Self

Source

pub fn set_column(&mut self, col: u32)

Set the current column for subsequent emit calls.

Source

pub fn add_constant(&mut self, constant: Constant) -> u16

Add a constant and return its index.

Source

pub fn emit(&mut self, op: Op, line: u32)

Emit a single-byte instruction.

Source

pub fn emit_u16(&mut self, op: Op, arg: u16, line: u32)

Emit an instruction with a u16 argument.

Source

pub fn emit_u8(&mut self, op: Op, arg: u8, line: u32)

Emit an instruction with a u8 argument.

Source

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).

Source

pub fn emit_method_call_opt(&mut self, name_idx: u16, arg_count: u8, line: u32)

Emit an optional method call (?.) — returns nil if receiver is nil.

Source

pub fn current_offset(&self) -> usize

Current code offset (for jump patching).

Source

pub fn emit_jump(&mut self, op: Op, line: u32) -> usize

Emit a jump instruction with a placeholder offset. Returns the position to patch.

Source

pub fn patch_jump(&mut self, patch_pos: usize)

Patch a jump instruction at the given position to jump to the current offset.

Source

pub fn patch_jump_to(&mut self, patch_pos: usize, target: usize)

Patch a jump to a specific target position.

Source

pub fn read_u16(&self, pos: usize) -> u16

Read a u16 argument at the given position.

Source

pub fn disassemble(&self, name: &str) -> String

Disassemble for debugging.

Trait Implementations§

Source§

impl Clone for Chunk

Source§

fn clone(&self) -> Chunk

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Chunk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Chunk

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more