pub struct Function { /* private fields */ }Expand description
The 𝗍𝗒𝗉𝖾 of a function declares its signature by reference to a type defined in the module. The parameters of the function are referenced through 0-based local indices in the function’s body; they are mutable. The 𝗅𝗈𝖼𝖺𝗅𝗌 declare a vector of mutable local variables and their types. These variables are referenced through local indices in the function’s body. The index of the first local is the smallest index not referencing a parameter. The 𝖻𝗈𝖽𝗒 is an instruction sequence that upon termination must produce a stack matching the function type’s result type.
See https://webassembly.github.io/spec/core/syntax/modules.html#functions
§Examples
use wasm_ast::{Function, TypeIndex, Expression, ResultType, ValueType, NumericInstruction, NumberType};
let locals: ResultType = vec![ValueType::I32, ValueType::F32].into();
let body: Expression = vec![
32u32.into(),
2u32.into(),
NumericInstruction::Multiply(NumberType::I32).into()
].into();
let function = Function::new(0, locals.clone(), body.clone());
assert_eq!(function.kind(), 0);
assert_eq!(function.locals(), &locals);
assert_eq!(function.body(), &body);Implementations§
Source§impl Function
impl Function
pub fn new(kind: TypeIndex, locals: ResultType, body: Expression) -> Self
Sourcepub fn locals(&self) -> &ResultType
pub fn locals(&self) -> &ResultType
The types of the locals of this Function.
Sourcepub fn body(&self) -> &Expression
pub fn body(&self) -> &Expression
The code for this Function.
Trait Implementations§
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
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
Mutably borrows from an owned value. Read more