pub struct Chunk {Show 47 fields
pub ops: Vec<Op>,
pub constants: Vec<PerlValue>,
pub names: Vec<String>,
pub lines: Vec<usize>,
pub op_ast_expr: Vec<Option<u32>>,
pub ast_expr_pool: Vec<Expr>,
pub sub_entries: Vec<(u16, usize, bool)>,
pub blocks: Vec<Block>,
pub block_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub static_sub_calls: Vec<(usize, bool, u16)>,
pub lvalues: Vec<Expr>,
pub struct_defs: Vec<StructDef>,
pub enum_defs: Vec<EnumDef>,
pub class_defs: Vec<ClassDef>,
pub trait_defs: Vec<TraitDef>,
pub given_entries: Vec<(Expr, Block)>,
pub given_topic_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub eval_timeout_entries: Vec<(Expr, Block)>,
pub eval_timeout_expr_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub algebraic_match_entries: Vec<(Expr, Vec<MatchArm>)>,
pub algebraic_match_subject_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub runtime_sub_decls: Vec<RuntimeSubDecl>,
pub code_ref_sigs: Vec<Vec<SubSigParam>>,
pub par_lines_entries: Vec<(Expr, Expr, Option<Expr>)>,
pub par_walk_entries: Vec<(Expr, Expr, Option<Expr>)>,
pub pwatch_entries: Vec<(Expr, Expr)>,
pub substr_four_arg_entries: Vec<(Expr, Expr, Option<Expr>, Expr)>,
pub keys_expr_entries: Vec<Expr>,
pub keys_expr_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub values_expr_entries: Vec<Expr>,
pub values_expr_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub delete_expr_entries: Vec<Expr>,
pub exists_expr_entries: Vec<Expr>,
pub push_expr_entries: Vec<(Expr, Vec<Expr>)>,
pub pop_expr_entries: Vec<Expr>,
pub shift_expr_entries: Vec<Expr>,
pub unshift_expr_entries: Vec<(Expr, Vec<Expr>)>,
pub splice_expr_entries: Vec<(Expr, Option<Expr>, Option<Expr>, Vec<Expr>)>,
pub map_expr_entries: Vec<Expr>,
pub map_expr_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub grep_expr_entries: Vec<Expr>,
pub grep_expr_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub regex_flip_flop_rhs_expr_entries: Vec<Expr>,
pub regex_flip_flop_rhs_expr_bytecode_ranges: Vec<Option<(usize, usize)>>,
pub flip_flop_slots: u16,
pub format_decls: Vec<(String, Vec<String>)>,
pub use_overload_entries: Vec<Vec<(String, String)>>,
}Expand description
A compiled chunk of bytecode with its constant pools.
Fields§
§ops: Vec<Op>§constants: Vec<PerlValue>Constant pool: string literals, regex patterns, etc.
names: Vec<String>Name pool: variable names, sub names (interned/deduped).
lines: Vec<usize>Source line for each op (parallel array for error reporting).
op_ast_expr: Vec<Option<u32>>Optional link from each op to the originating Expr (pool index into Self::ast_expr_pool).
Filled for ops emitted from crate::compiler::Compiler::compile_expr_ctx; other paths leave None.
ast_expr_pool: Vec<Expr>Interned Expr nodes referenced by Self::op_ast_expr (for debugging / tooling).
sub_entries: Vec<(u16, usize, bool)>Compiled subroutine entry points: (name_index, op_index, uses_stack_args).
When uses_stack_args is true, the Call op leaves arguments on the value
stack and the sub reads them via GetArg(idx) instead of shift @_.
blocks: Vec<Block>AST blocks for map/grep/sort/parallel operations. Referenced by block-based opcodes via u16 index.
block_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), blocks[i] is also lowered to ops[start..end] (exclusive end)
with trailing Op::BlockReturnValue. VM uses opcodes; otherwise the AST in blocks[i].
static_sub_calls: Vec<(usize, bool, u16)>Resolved Op::CallStaticSubId targets: subroutine entry IP, stack-args calling convention,
and stash name pool index (qualified key matching [Interpreter::subs]).
lvalues: Vec<Expr>Assign targets for s/// / tr/// bytecode (LHS expressions).
struct_defs: Vec<StructDef>struct Name { ... } definitions in this chunk (registered on the interpreter at VM start).
enum_defs: Vec<EnumDef>enum Name { ... } definitions in this chunk (registered on the interpreter at VM start).
class_defs: Vec<ClassDef>class Name extends ... impl ... { ... } definitions.
trait_defs: Vec<TraitDef>trait Name { ... } definitions.
given_entries: Vec<(Expr, Block)>given (topic) { body } — topic expression + body (when/default handled by interpreter).
given_topic_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), given_entries[i].0 (topic) is lowered to ops[start..end] +
Op::BlockReturnValue.
eval_timeout_entries: Vec<(Expr, Block)>eval_timeout timeout_expr { body } — evaluated at runtime.
eval_timeout_expr_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), eval_timeout_entries[i].0 (timeout expr) is lowered to
ops[start..end] with trailing Op::BlockReturnValue.
algebraic_match_entries: Vec<(Expr, Vec<MatchArm>)>Algebraic match (subject) { arms }.
algebraic_match_subject_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), algebraic_match_entries[i].0 (subject) is lowered to
ops[start..end] + Op::BlockReturnValue.
runtime_sub_decls: Vec<RuntimeSubDecl>Nested / runtime sub declarations (see Op::RuntimeSubDecl).
code_ref_sigs: Vec<Vec<SubSigParam>>Stryke fn ($a, …) / hash-destruct params for Op::MakeCodeRef (second operand is pool index).
par_lines_entries: Vec<(Expr, Expr, Option<Expr>)>par_lines PATH, fn { } [, progress => EXPR] — evaluated by interpreter inside VM.
par_walk_entries: Vec<(Expr, Expr, Option<Expr>)>par_walk PATH, fn { } [, progress => EXPR] — evaluated by interpreter inside VM.
pwatch_entries: Vec<(Expr, Expr)>pwatch GLOB, fn { } — evaluated by interpreter inside VM.
substr_four_arg_entries: Vec<(Expr, Expr, Option<Expr>, Expr)>substr $var, OFF, LEN, REPL — four-arg form (mutates LHS); evaluated by interpreter inside VM.
keys_expr_entries: Vec<Expr>keys EXPR when EXPR is not bare %h.
keys_expr_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), keys_expr_entries[i] is lowered to ops[start..end] +
Op::BlockReturnValue (operand only; Op::KeysExpr still applies keys to the value).
values_expr_entries: Vec<Expr>values EXPR when not bare %h.
values_expr_bytecode_ranges: Vec<Option<(usize, usize)>>§delete_expr_entries: Vec<Expr>delete EXPR when not the fast %h{k} lowering.
exists_expr_entries: Vec<Expr>exists EXPR when not the fast %h{k} lowering.
push_expr_entries: Vec<(Expr, Vec<Expr>)>push when the array operand is not a bare @name (e.g. push $aref, ...).
pop_expr_entries: Vec<Expr>§shift_expr_entries: Vec<Expr>§unshift_expr_entries: Vec<(Expr, Vec<Expr>)>§splice_expr_entries: Vec<(Expr, Option<Expr>, Option<Expr>, Vec<Expr>)>§map_expr_entries: Vec<Expr>map EXPR, LIST — map expression (list context) with $_ set to each element.
map_expr_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), map_expr_entries[i] is lowered like Self::grep_expr_bytecode_ranges.
grep_expr_entries: Vec<Expr>grep EXPR, LIST — filter expression evaluated with $_ set to each element.
grep_expr_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), grep_expr_entries[i] is also lowered to ops[start..end]
(exclusive end) with trailing Op::BlockReturnValue, like Self::block_bytecode_ranges.
regex_flip_flop_rhs_expr_entries: Vec<Expr>Right-hand expression for Op::RegexFlipFlopExprRhs — boolean context (bare m// is $_ =~ m//).
regex_flip_flop_rhs_expr_bytecode_ranges: Vec<Option<(usize, usize)>>When Some((start, end)), regex_flip_flop_rhs_expr_entries[i] is lowered to ops[start..end] +
Op::BlockReturnValue.
flip_flop_slots: u16Number of flip-flop slots (Op::ScalarFlipFlop, Op::RegexFlipFlop, Op::RegexEofFlipFlop,
Op::RegexFlipFlopExprRhs, Op::RegexFlipFlopDotLineRhs); VM resets flip-flop vectors.
format_decls: Vec<(String, Vec<String>)>format NAME = bodies: basename + lines between = and . (see lexer).
use_overload_entries: Vec<Vec<(String, String)>>use overload pair lists (installed into current package at run time).
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn find_sub_entry(&self, name_idx: u16) -> Option<(usize, bool)>
pub fn find_sub_entry(&self, name_idx: u16) -> Option<(usize, bool)>
Look up a compiled subroutine entry by stash name pool index.
pub fn new() -> Self
Sourcepub fn add_format_decl(&mut self, name: String, lines: Vec<String>) -> u16
pub fn add_format_decl(&mut self, name: String, lines: Vec<String>) -> u16
Pool index for Op::FormatDecl.
Sourcepub fn add_use_overload(&mut self, pairs: Vec<(String, String)>) -> u16
pub fn add_use_overload(&mut self, pairs: Vec<(String, String)>) -> u16
Pool index for Op::UseOverload.
Sourcepub fn alloc_flip_flop_slot(&mut self) -> u16
pub fn alloc_flip_flop_slot(&mut self) -> u16
Allocate a slot index for Op::ScalarFlipFlop / Op::RegexFlipFlop / Op::RegexEofFlipFlop /
Op::RegexFlipFlopExprRhs / Op::RegexFlipFlopDotLineRhs flip-flop state.
Sourcepub fn add_map_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_map_expr_entry(&mut self, expr: Expr) -> u16
map EXPR, LIST — pool index for Op::MapWithExpr.
Sourcepub fn add_grep_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_grep_expr_entry(&mut self, expr: Expr) -> u16
grep EXPR, LIST — pool index for Op::GrepWithExpr.
Sourcepub fn add_regex_flip_flop_rhs_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_regex_flip_flop_rhs_expr_entry(&mut self, expr: Expr) -> u16
Regex flip-flop with compound RHS — pool index for Op::RegexFlipFlopExprRhs.
Sourcepub fn add_keys_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_keys_expr_entry(&mut self, expr: Expr) -> u16
keys EXPR (dynamic) — pool index for Op::KeysExpr.
Sourcepub fn add_values_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_values_expr_entry(&mut self, expr: Expr) -> u16
values EXPR (dynamic) — pool index for Op::ValuesExpr.
Sourcepub fn add_delete_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_delete_expr_entry(&mut self, expr: Expr) -> u16
delete EXPR (dynamic operand) — pool index for Op::DeleteExpr.
Sourcepub fn add_exists_expr_entry(&mut self, expr: Expr) -> u16
pub fn add_exists_expr_entry(&mut self, expr: Expr) -> u16
exists EXPR (dynamic operand) — pool index for Op::ExistsExpr.
pub fn add_push_expr_entry(&mut self, array: Expr, values: Vec<Expr>) -> u16
pub fn add_pop_expr_entry(&mut self, array: Expr) -> u16
pub fn add_shift_expr_entry(&mut self, array: Expr) -> u16
pub fn add_unshift_expr_entry(&mut self, array: Expr, values: Vec<Expr>) -> u16
pub fn add_splice_expr_entry( &mut self, array: Expr, offset: Option<Expr>, length: Option<Expr>, replacement: Vec<Expr>, ) -> u16
Sourcepub fn add_substr_four_arg_entry(
&mut self,
string: Expr,
offset: Expr,
length: Option<Expr>,
replacement: Expr,
) -> u16
pub fn add_substr_four_arg_entry( &mut self, string: Expr, offset: Expr, length: Option<Expr>, replacement: Expr, ) -> u16
Four-arg substr — returns pool index for Op::SubstrFourArg.
Sourcepub fn add_par_lines_entry(
&mut self,
path: Expr,
callback: Expr,
progress: Option<Expr>,
) -> u16
pub fn add_par_lines_entry( &mut self, path: Expr, callback: Expr, progress: Option<Expr>, ) -> u16
par_lines PATH, fn { } [, progress => EXPR] — returns pool index for Op::ParLines.
Sourcepub fn add_par_walk_entry(
&mut self,
path: Expr,
callback: Expr,
progress: Option<Expr>,
) -> u16
pub fn add_par_walk_entry( &mut self, path: Expr, callback: Expr, progress: Option<Expr>, ) -> u16
par_walk PATH, fn { } [, progress => EXPR] — returns pool index for Op::ParWalk.
Sourcepub fn add_pwatch_entry(&mut self, path: Expr, callback: Expr) -> u16
pub fn add_pwatch_entry(&mut self, path: Expr, callback: Expr) -> u16
pwatch GLOB, fn { } — returns pool index for Op::Pwatch.
Sourcepub fn add_given_entry(&mut self, topic: Expr, body: Block) -> u16
pub fn add_given_entry(&mut self, topic: Expr, body: Block) -> u16
given (EXPR) { ... } — returns pool index for Op::Given.
Sourcepub fn add_eval_timeout_entry(&mut self, timeout: Expr, body: Block) -> u16
pub fn add_eval_timeout_entry(&mut self, timeout: Expr, body: Block) -> u16
eval_timeout SECS { ... } — returns pool index for Op::EvalTimeout.
Sourcepub fn add_algebraic_match_entry(
&mut self,
subject: Expr,
arms: Vec<MatchArm>,
) -> u16
pub fn add_algebraic_match_entry( &mut self, subject: Expr, arms: Vec<MatchArm>, ) -> u16
Algebraic match — returns pool index for Op::AlgebraicMatch.
Sourcepub fn add_code_ref_sig(&mut self, params: Vec<SubSigParam>) -> u16
pub fn add_code_ref_sig(&mut self, params: Vec<SubSigParam>) -> u16
Pool index for Op::MakeCodeRef signature (stryke extension); use empty vec for legacy fn { }.
Sourcepub fn add_lvalue_expr(&mut self, e: Expr) -> u16
pub fn add_lvalue_expr(&mut self, e: Expr) -> u16
Store an assignable expression (LHS of s/// / tr///) and return its index.
Sourcepub fn intern_name(&mut self, name: &str) -> u16
pub fn intern_name(&mut self, name: &str) -> u16
Intern a name, returning its pool index.
Sourcepub fn add_constant(&mut self, val: PerlValue) -> u16
pub fn add_constant(&mut self, val: PerlValue) -> u16
Add a constant to the pool, returning its index.
Sourcepub fn emit_with_ast_idx(
&mut self,
op: Op,
line: usize,
ast: Option<u32>,
) -> usize
pub fn emit_with_ast_idx( &mut self, op: Op, line: usize, ast: Option<u32>, ) -> usize
Like Self::emit but attach an optional interned AST Expr pool index (see Self::op_ast_expr).
Sourcepub fn ast_expr_at(&self, ip: usize) -> Option<&Expr>
pub fn ast_expr_at(&self, ip: usize) -> Option<&Expr>
Resolve the originating expression for an instruction pointer, if recorded.
Sourcepub fn patch_jump_here(&mut self, idx: usize)
pub fn patch_jump_here(&mut self, idx: usize)
Patch a jump instruction at idx to target the current position.
Sourcepub fn patch_jump_to(&mut self, idx: usize, target: usize)
pub fn patch_jump_to(&mut self, idx: usize, target: usize)
Patch a jump instruction at idx to target an explicit op address.
pub fn patch_try_push_catch(&mut self, idx: usize, catch_ip: usize)
pub fn patch_try_push_finally(&mut self, idx: usize, finally_ip: Option<usize>)
pub fn patch_try_push_after(&mut self, idx: usize, after_ip: usize)
pub fn is_empty(&self) -> bool
Sourcepub fn disassemble(&self) -> String
pub fn disassemble(&self) -> String
Human-readable listing: subroutine entry points and each op with its source line (javap / dis-style).
Sourcepub fn peephole_fuse(&mut self)
pub fn peephole_fuse(&mut self)
Peephole pass: fuse common multi-op sequences into single superinstructions, then compact by removing Nop slots and remapping all jump targets.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chunk
impl<'de> Deserialize<'de> for Chunk
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> 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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.