Retrieve function from memory when called
This commit is contained in:
parent
1011ff08f3
commit
fdbb21990d
@ -22,7 +22,7 @@ pub enum Expr {
|
|||||||
Func(Func),
|
Func(Func),
|
||||||
Val(Rc<String>),
|
Val(Rc<String>),
|
||||||
Call {
|
Call {
|
||||||
f: Func,
|
f: Box<Expr>,
|
||||||
args: Vec<Expr>,
|
args: Vec<Expr>,
|
||||||
},
|
},
|
||||||
UnimplementedSigilValue
|
UnimplementedSigilValue
|
||||||
@ -79,12 +79,10 @@ impl Expression {
|
|||||||
BinExp(binop, lhs, rhs) => binop.reduce(lhs, rhs),
|
BinExp(binop, lhs, rhs) => binop.reduce(lhs, rhs),
|
||||||
PrefixExp(op, arg) => op.reduce(arg),
|
PrefixExp(op, arg) => op.reduce(arg),
|
||||||
Value(name) => Expr::Val(name.clone()),
|
Value(name) => Expr::Val(name.clone()),
|
||||||
/*
|
Call { f, arguments } => Expr::Call {
|
||||||
&Call { ref f, ref arguments } => Expr::Call {
|
f: Box::new(f.reduce()),
|
||||||
f: Box<Expression>,
|
args: arguments.iter().map(|arg| arg.reduce()).collect(),
|
||||||
arguments: Vec<Expression>,
|
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
e => Expr::UnimplementedSigilValue,
|
e => Expr::UnimplementedSigilValue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,14 +109,14 @@ impl Declaration {
|
|||||||
|
|
||||||
impl BinOp {
|
impl BinOp {
|
||||||
fn reduce(&self, lhs: &Box<Expression>, rhs: &Box<Expression>) -> Expr {
|
fn reduce(&self, lhs: &Box<Expression>, rhs: &Box<Expression>) -> Expr {
|
||||||
let f = Func::BuiltIn(self.sigil().clone());
|
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
|
||||||
Expr::Call { f, args: vec![lhs.reduce(), rhs.reduce()]}
|
Expr::Call { f, args: vec![lhs.reduce(), rhs.reduce()]}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixOp {
|
impl PrefixOp {
|
||||||
fn reduce(&self, arg: &Box<Expression>) -> Expr {
|
fn reduce(&self, arg: &Box<Expression>) -> Expr {
|
||||||
let f = Func::BuiltIn(self.sigil().clone());
|
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
|
||||||
Expr::Call { f, args: vec![arg.reduce()]}
|
Expr::Call { f, args: vec![arg.reduce()]}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,13 @@ impl<'a> State<'a> {
|
|||||||
use self::Expr::*;
|
use self::Expr::*;
|
||||||
match expr {
|
match expr {
|
||||||
literal @ Lit(_) => Ok(literal),
|
literal @ Lit(_) => Ok(literal),
|
||||||
Call { f, args } => self.apply_function(f, args),
|
Call { box f, args } => {
|
||||||
|
let f = match self.expression(f)? {
|
||||||
|
Func(f) => f,
|
||||||
|
other => return Err(format!("Tried to call {:?} which is not a function", other)),
|
||||||
|
};
|
||||||
|
self.apply_function(f, args)
|
||||||
|
},
|
||||||
Val(v) => self.value(v),
|
Val(v) => self.value(v),
|
||||||
func @ Func(_) => Ok(func),
|
func @ Func(_) => Ok(func),
|
||||||
e => Err(format!("Expr {:?} eval not implemented", e))
|
e => Err(format!("Expr {:?} eval not implemented", e))
|
||||||
|
Loading…
Reference in New Issue
Block a user