feat: SCC analysis (thunk capture WIP)
This commit is contained in:
@@ -21,13 +21,14 @@ impl PartialEq for PrimOp {
|
||||
}
|
||||
|
||||
impl PrimOp {
|
||||
pub fn call(&self, arg: Value, ctx: &Engine) -> Result<Value> {
|
||||
let mut args = Vec::with_capacity(self.arity);
|
||||
args.push(arg);
|
||||
if self.arity > 1 {
|
||||
pub fn call(&self, args: Vec<Value>, ctx: &Engine) -> Result<Value> {
|
||||
if args.len() > self.arity {
|
||||
todo!()
|
||||
}
|
||||
if self.arity > args.len() {
|
||||
Value::PartialPrimOp(Rc::new(PartialPrimOp {
|
||||
name: self.name,
|
||||
arity: self.arity - 1,
|
||||
arity: self.arity - args.len(),
|
||||
args,
|
||||
func: self.func,
|
||||
}))
|
||||
@@ -38,7 +39,7 @@ impl PrimOp {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PartialPrimOp {
|
||||
pub name: &'static str,
|
||||
arity: usize,
|
||||
@@ -53,12 +54,15 @@ impl PartialEq for PartialPrimOp {
|
||||
}
|
||||
|
||||
impl PartialPrimOp {
|
||||
pub fn call(self: &mut Rc<Self>, arg: Value, ctx: &Engine) -> Result<Value> {
|
||||
pub fn call(self: &mut Rc<Self>, args: Vec<Value>, ctx: &Engine) -> Result<Value> {
|
||||
if self.arity < args.len() {
|
||||
todo!()
|
||||
}
|
||||
let func = self.func;
|
||||
let Some(ret) = ({
|
||||
let self_mut = Rc::make_mut(self);
|
||||
self_mut.args.push(arg);
|
||||
self_mut.arity -= 1;
|
||||
self_mut.arity -= args.len();
|
||||
self_mut.args.extend(args);
|
||||
if self_mut.arity == 0 {
|
||||
Some(func(std::mem::take(&mut self_mut.args), ctx))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user