pub struct Function {Show 16 fields
pub name: String,
pub kind: FunctionKind,
pub strict: bool,
pub args: Vec<VarDef>,
pub vars: Vec<VarDef>,
pub closure_vars: Vec<ClosureVar>,
pub cpool: Vec<Constant>,
pub atoms: Vec<Atom>,
pub code: Vec<u8>,
pub stack_size: u32,
pub positions: Vec<LineCol>,
pub var_ref_count: u32,
pub source: Option<String>,
pub line: u32,
pub column: u32,
pub filename: Option<String>,
}Expand description
A compiled function.
Fields§
§name: StringThe function’s name; <eval> for a script body.
kind: FunctionKindThe declaration form.
strict: boolWhether the body is strict.
args: Vec<VarDef>Parameters.
vars: Vec<VarDef>Locals, including the implicit return-value slot named <ret>.
closure_vars: Vec<ClosureVar>Captured variables of enclosing functions.
cpool: Vec<Constant>Constant pool.
atoms: Vec<Atom>Atom table: the names this function mentions. The runtime shares one interned table across the whole program; indexing it per function keeps the bytecode self-contained and makes disassembly readable.
code: Vec<u8>Resolved bytecode.
stack_size: u32Maximum value-stack depth.
positions: Vec<LineCol>Source positions, ordered by bytecode offset.
var_ref_count: u32Number of reference cells allocated on entry.
source: Option<String>Source text, kept for Function.prototype.toString and stack traces.
line: u32Line of the function’s declaration.
column: u32Column of the function’s declaration.
filename: Option<String>File name, if known.
Implementations§
Source§impl Function
impl Function
Sourcepub fn set_filename(&mut self, name: &str)
pub fn set_filename(&mut self, name: &str)
Name the script this function belongs to.
Nested functions inherit it, because a stack trace names every frame with the file the code came from and the parser does not know file names — the host does, after the source has already been compiled.
Sourcepub fn position_at(&self, pc: u32) -> Option<(u32, u32)>
pub fn position_at(&self, pc: u32) -> Option<(u32, u32)>
The source position of the instruction at pc.
The last entry at or before pc wins, so a position applies until the next one
starts. None when the function carries no positions at all — a script compiled
without source information.
Sourcepub fn instructions(&self) -> Vec<(usize, Instruction)>
pub fn instructions(&self) -> Vec<(usize, Instruction)>
Decode the instruction stream back into instructions.
Labels are already resolved, so a label operand is an absolute byte
offset.
Sourcepub fn jump_targets(&self) -> Vec<usize>
pub fn jump_targets(&self) -> Vec<usize>
Byte offsets that are the target of a jump, which the disassembler marks.
Sourcepub fn slot_count(&self) -> u32
pub fn slot_count(&self) -> u32
Total number of variable slots, as the serialiser stores them.