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<CompiledFunctionRef>,
/* 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<CompiledFunctionRef>Compiled function bodies (for closures).
Implementations§
Source§impl Chunk
impl Chunk
pub fn new() -> Self
Sourcepub fn set_column(&mut self, col: u32)
pub fn set_column(&mut self, col: u32)
Set the current column for subsequent emit calls.
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_call_builtin(
&mut self,
id: BuiltinId,
name_idx: u16,
arg_count: u8,
line: u32,
)
pub fn emit_call_builtin( &mut self, id: BuiltinId, name_idx: u16, arg_count: u8, line: u32, )
Emit a direct builtin call.
Sourcepub fn emit_call_builtin_spread(
&mut self,
id: BuiltinId,
name_idx: u16,
line: u32,
)
pub fn emit_call_builtin_spread( &mut self, id: BuiltinId, name_idx: u16, line: u32, )
Emit a direct builtin spread call.
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 emit_method_call_opt(&mut self, name_idx: u16, arg_count: u8, line: u32)
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.
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 patch_jump_to(&mut self, patch_pos: usize, target: usize)
pub fn patch_jump_to(&mut self, patch_pos: usize, target: usize)
Patch a jump to a specific target position.
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
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);