Skip to main content

Chunk

Struct Chunk 

Source
pub struct Chunk {
Show 49 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 ast_eval_exprs: Vec<Expr>, pub body_start_ip: usize, 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).

§ast_eval_exprs: Vec<Expr>

AST expressions delegated to interpreter at runtime via Op::EvalAstExpr.

§body_start_ip: usize

Instruction pointer where the main program body starts (after BEGIN/CHECK/INIT phase blocks). Used by -n/-p line mode to re-execute only the body per input line.

§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: u16§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

Source

pub fn find_sub_entry(&self, name_idx: u16) -> Option<(usize, bool)>

Look up a compiled subroutine entry by stash name pool index.

Source

pub fn new() -> Self

Source

pub fn add_format_decl(&mut self, name: String, lines: Vec<String>) -> u16

Pool index for Op::FormatDecl.

Source

pub fn add_use_overload(&mut self, pairs: Vec<(String, String)>) -> u16

Pool index for Op::UseOverload.

Source

pub fn alloc_flip_flop_slot(&mut self) -> u16

Source

pub fn add_map_expr_entry(&mut self, expr: Expr) -> u16

map EXPR, LIST — pool index for Op::MapWithExpr.

Source

pub fn add_grep_expr_entry(&mut self, expr: Expr) -> u16

grep EXPR, LIST — pool index for Op::GrepWithExpr.

Source

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.

Source

pub fn add_keys_expr_entry(&mut self, expr: Expr) -> u16

keys EXPR (dynamic) — pool index for Op::KeysExpr.

Source

pub fn add_values_expr_entry(&mut self, expr: Expr) -> u16

values EXPR (dynamic) — pool index for Op::ValuesExpr.

Source

pub fn add_delete_expr_entry(&mut self, expr: Expr) -> u16

delete EXPR (dynamic operand) — pool index for Op::DeleteExpr.

Source

pub fn add_exists_expr_entry(&mut self, expr: Expr) -> u16

exists EXPR (dynamic operand) — pool index for Op::ExistsExpr.

Source

pub fn add_push_expr_entry(&mut self, array: Expr, values: Vec<Expr>) -> u16

Source

pub fn add_pop_expr_entry(&mut self, array: Expr) -> u16

Source

pub fn add_shift_expr_entry(&mut self, array: Expr) -> u16

Source

pub fn add_unshift_expr_entry(&mut self, array: Expr, values: Vec<Expr>) -> u16

Source

pub fn add_splice_expr_entry( &mut self, array: Expr, offset: Option<Expr>, length: Option<Expr>, replacement: Vec<Expr>, ) -> u16

Source

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.

Source

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.

Source

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.

Source

pub fn add_pwatch_entry(&mut self, path: Expr, callback: Expr) -> u16

pwatch GLOB, fn { } — returns pool index for Op::Pwatch.

Source

pub fn add_given_entry(&mut self, topic: Expr, body: Block) -> u16

given (EXPR) { ... } — returns pool index for Op::Given.

Source

pub fn add_eval_timeout_entry(&mut self, timeout: Expr, body: Block) -> u16

eval_timeout SECS { ... } — returns pool index for Op::EvalTimeout.

Source

pub fn add_algebraic_match_entry( &mut self, subject: Expr, arms: Vec<MatchArm>, ) -> u16

Algebraic match — returns pool index for Op::AlgebraicMatch.

Source

pub fn add_block(&mut self, block: Block) -> u16

Store an AST block and return its index.

Source

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 { }.

Source

pub fn add_lvalue_expr(&mut self, e: Expr) -> u16

Store an assignable expression (LHS of s/// / tr///) and return its index.

Source

pub fn intern_name(&mut self, name: &str) -> u16

Intern a name, returning its pool index.

Source

pub fn add_constant(&mut self, val: PerlValue) -> u16

Add a constant to the pool, returning its index.

Source

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

Append an op with source line info.

Source

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

Source

pub fn ast_expr_at(&self, ip: usize) -> Option<&Expr>

Resolve the originating expression for an instruction pointer, if recorded.

Source

pub fn patch_jump_here(&mut self, idx: usize)

Patch a jump instruction at idx to target the current position.

Source

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

Patch a jump instruction at idx to target an explicit op address.

Source

pub fn patch_try_push_catch(&mut self, idx: usize, catch_ip: usize)

Source

pub fn patch_try_push_finally(&mut self, idx: usize, finally_ip: Option<usize>)

Source

pub fn patch_try_push_after(&mut self, idx: usize, after_ip: usize)

Source

pub fn len(&self) -> usize

Current op count (next emit position).

Source

pub fn is_empty(&self) -> bool

Source

pub fn disassemble(&self) -> String

Human-readable listing: subroutine entry points and each op with its source line (javap / dis-style).

Source

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 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
Source§

impl<'de> Deserialize<'de> for Chunk

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Chunk

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,