various stuff

This commit is contained in:
Erin 2022-08-06 21:47:06 +02:00 committed by ondra05
parent cb20383f08
commit 1c4b04dc6d
3 changed files with 14 additions and 4 deletions

View file

@ -1,2 +1,8 @@
use super::Str;
use crate::syntax::ast::{Expr, Spanned};
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Function; pub struct Function<'s> {
params: Box<[Str<'s>]>,
ast: Box<[Spanned<Expr<'s>>]>,
}

View file

@ -23,8 +23,9 @@ pub enum Value<'s> {
Keyword(Str<'s>), Keyword(Str<'s>),
Number(OrderedF64), Number(OrderedF64),
String(Str<'s>), String(Str<'s>),
Function(Function), Function(Function<'s>),
Macro(Function), NativeFun(fn(&'s [Value<'s>]) -> Value<'s>),
Macro(Function<'s>),
} }
impl<'s> From<Spanned<Expr<'s>>> for Value<'s> { impl<'s> From<Spanned<Expr<'s>>> for Value<'s> {
@ -65,6 +66,7 @@ impl<'s> Display for Value<'s> {
Value::Number(n) => n.fmt(f), Value::Number(n) => n.fmt(f),
Value::String(s) => write!(f, "\"{s}\""), Value::String(s) => write!(f, "\"{s}\""),
Value::Function(_) => "#fun#".fmt(f), Value::Function(_) => "#fun#".fmt(f),
Value::NativeFun(fp) => write!(f, "#native-fun({fp:p})#"),
Value::Macro(_) => "#macro#".fmt(f), Value::Macro(_) => "#macro#".fmt(f),
} }
} }

View file

@ -31,6 +31,8 @@ impl<T: PartialEq> PartialEq for Spanned<T> {
} }
} }
impl<T: Eq> Eq for Spanned<T> {}
impl<T: Hash> Hash for Spanned<T> { impl<T: Hash> Hash for Spanned<T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.item.hash(state); self.item.hash(state);
@ -38,7 +40,7 @@ impl<T: Hash> Hash for Spanned<T> {
} }
/// A Wisp AST /// A Wisp AST
#[derive(Debug, Clone, Hash, PartialEq)] #[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum Expr<'s> { pub enum Expr<'s> {
List(Vec<Spanned<Self>>), List(Vec<Spanned<Self>>),
Vector(Vec<Spanned<Self>>), Vector(Vec<Spanned<Self>>),