From 6c71bde8a867531a13fd6b6e8f7ad11f621f66e8 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 21 Jul 2022 22:50:58 +0200 Subject: [PATCH] Added macro and internal fn types --- src/parser.rs | 2 +- src/value.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 07b8088..7cadac4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -66,7 +66,7 @@ fn stream_of_lexer<'a>( mod tests { use super::*; - fn assert_parse(src: &str, expected: &[Value]) { + fn assert_parse<'a>(src: &'a str, expected: &'a [Value<'a>]) { assert_eq!(read(src).unwrap(), expected) } diff --git a/src/value.rs b/src/value.rs index c1fdd2c..eff25b2 100644 --- a/src/value.rs +++ b/src/value.rs @@ -3,7 +3,7 @@ use ordered_float::OrderedFloat; use std::{ borrow::Cow, collections::BTreeMap, - fmt::{Display, Write}, + fmt::{Debug, Display, Write}, rc::Rc, }; @@ -15,6 +15,8 @@ pub enum Value<'a> { Map(BTreeMap), Module(Module<'a>), Function(Function<'a>), + InternalFn(fn(&'a List<'a>) -> Value<'a>), + Macro(/* TODO: Bytecode */), Symbol(Symbol<'a>), Keyword(Cow<'a, str>), Bool(bool), @@ -83,7 +85,9 @@ impl<'a> Display for Value<'a> { Value::Module(_) => write!(f, "#module#"), Value::Symbol(sym) => write!(f, "{sym}"), Value::Keyword(kw) => write!(f, ":{kw}"), - Value::Function { .. } => write!(f, "fn"), + Value::Function { .. } => write!(f, "#fn#"), + Value::InternalFn(function) => write!(f, "#internal-fn@{function:p}"), + Value::Macro() => write!(f, "#macro#"), Value::Bool(b) => write!(f, "{b}"), Value::Number(n) => write!(f, "{n}"), Value::String(s) => write!(f, "\"{s}\""),