pub struct Closure {
pub fn_ptr: FnPtr,
pub arity: u16,
pub env: Vec<RtObject>,
pub name: Option<String>,
pub is_recursive: bool,
pub is_known: bool,
}Expand description
A runtime closure with captured environment.
The closure captures free variables in a flat array. The function body
is represented by a FnPtr into the code table.
Fields§
§fn_ptr: FnPtrPointer to the function body.
arity: u16Total arity (number of parameters the function expects).
env: Vec<RtObject>Captured environment values.
name: Option<String>Name of the closure (for debugging).
is_recursive: boolWhether this closure is recursive.
is_known: boolWhether this closure has been marked as a known function (can be called directly without going through the closure mechanism).
Implementations§
Source§impl Closure
impl Closure
Sourcepub fn named(
name: String,
fn_ptr: FnPtr,
arity: u16,
env: Vec<RtObject>,
) -> Self
pub fn named( name: String, fn_ptr: FnPtr, arity: u16, env: Vec<RtObject>, ) -> Self
Create a closure with a name.
Sourcepub fn simple(fn_ptr: FnPtr, arity: u16) -> Self
pub fn simple(fn_ptr: FnPtr, arity: u16) -> Self
Create a simple closure with no captured environment.
Sourcepub fn set_env(&mut self, index: usize, value: RtObject) -> bool
pub fn set_env(&mut self, index: usize, value: RtObject) -> bool
Set a captured value by index.
Sourcepub fn extend_env(&mut self, values: &[RtObject])
pub fn extend_env(&mut self, values: &[RtObject])
Extend the environment with additional values.
Sourcepub fn set_recursive(&mut self)
pub fn set_recursive(&mut self)
Mark as recursive.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Closure
impl RefUnwindSafe for Closure
impl Send for Closure
impl Sync for Closure
impl Unpin for Closure
impl UnsafeUnpin for Closure
impl UnwindSafe for Closure
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