feat: stack var (WIP)
This commit is contained in:
25
evaluator/nixjit_eval/src/value/closure.rs
Normal file
25
evaluator/nixjit_eval/src/value/closure.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
//! Defines the runtime representation of a partially applied function.
|
||||
use std::rc::Rc;
|
||||
|
||||
use derive_more::Constructor;
|
||||
|
||||
use nixjit_error::Result;
|
||||
use nixjit_ir::ExprId;
|
||||
|
||||
use super::Value;
|
||||
use crate::EvalContext;
|
||||
|
||||
pub type StackFrame = smallvec::SmallVec<[Value; 5]>;
|
||||
|
||||
#[derive(Debug, Clone, Constructor)]
|
||||
pub struct Closure {
|
||||
pub body: ExprId,
|
||||
pub frame: StackFrame,
|
||||
}
|
||||
|
||||
impl Closure {
|
||||
pub fn call<Ctx: EvalContext>(self: Rc<Self>, arg: Option<Value>, ctx: &mut Ctx) -> Result<Value> {
|
||||
let Self { body: func, frame } = Rc::unwrap_or_clone(self);
|
||||
ctx.call(func, arg, frame)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user