Skip to main content

Function

Struct Function 

Source
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: String

The function’s name; <eval> for a script body.

§kind: FunctionKind

The declaration form.

§strict: bool

Whether 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: u32

Maximum value-stack depth.

§positions: Vec<LineCol>

Source positions, ordered by bytecode offset.

§var_ref_count: u32

Number of reference cells allocated on entry.

§source: Option<String>

Source text, kept for Function.prototype.toString and stack traces.

§line: u32

Line of the function’s declaration.

§column: u32

Column of the function’s declaration.

§filename: Option<String>

File name, if known.

Implementations§

Source§

impl Function

Source

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.

Source

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.

Source

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.

Source

pub fn jump_targets(&self) -> Vec<usize>

Byte offsets that are the target of a jump, which the disassembler marks.

Source

pub fn slot_count(&self) -> u32

Total number of variable slots, as the serialiser stores them.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

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

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

impl PartialEq for Function

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Function

Auto Trait Implementations§

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, 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.