diff --git a/src/interpreter/value/function.rs b/src/interpreter/value/function.rs index f3a0e28..d5c2435 100644 --- a/src/interpreter/value/function.rs +++ b/src/interpreter/value/function.rs @@ -1,2 +1,8 @@ +use super::Str; +use crate::syntax::ast::{Expr, Spanned}; + #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Function; +pub struct Function<'s> { + params: Box<[Str<'s>]>, + ast: Box<[Spanned>]>, +} diff --git a/src/interpreter/value/mod.rs b/src/interpreter/value/mod.rs index 51d5267..83b726f 100644 --- a/src/interpreter/value/mod.rs +++ b/src/interpreter/value/mod.rs @@ -23,8 +23,9 @@ pub enum Value<'s> { Keyword(Str<'s>), Number(OrderedF64), String(Str<'s>), - Function(Function), - Macro(Function), + Function(Function<'s>), + NativeFun(fn(&'s [Value<'s>]) -> Value<'s>), + Macro(Function<'s>), } impl<'s> From>> for Value<'s> { @@ -65,6 +66,7 @@ impl<'s> Display for Value<'s> { Value::Number(n) => n.fmt(f), Value::String(s) => write!(f, "\"{s}\""), Value::Function(_) => "#fun#".fmt(f), + Value::NativeFun(fp) => write!(f, "#native-fun({fp:p})#"), Value::Macro(_) => "#macro#".fmt(f), } } diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index e61d08f..5705a41 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -31,6 +31,8 @@ impl PartialEq for Spanned { } } +impl Eq for Spanned {} + impl Hash for Spanned { fn hash(&self, state: &mut H) { self.item.hash(state); @@ -38,7 +40,7 @@ impl Hash for Spanned { } /// A Wisp AST -#[derive(Debug, Clone, Hash, PartialEq)] +#[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum Expr<'s> { List(Vec>), Vector(Vec>),