From aeb5dc0ddc1f111ab0cd6aeabdb6e4a921fafa86 Mon Sep 17 00:00:00 2001 From: mehbark Date: Tue, 13 Jun 2023 14:34:43 -0400 Subject: [PATCH] add log --- src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index 21d1e37..24d9e75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -570,6 +570,7 @@ fn simp( for i in 0..step_limit { expr = expr .apply_special_form::() + .apply_special_form::() .apply_special_form::() .apply_special_form::(); @@ -704,6 +705,25 @@ impl SpecialForm<'_> for Genslop { } } +static LOG: Lazy = Lazy::new(|| TABLE.lock().unwrap().intern("log").unwrap()); + +#[derive(Debug, Clone)] +struct Log<'src>(&'src Sexp); + +impl<'src> SpecialForm<'src> for Log<'src> { + fn from_sexp(sexp: &'src Sexp) -> Option { + match sexp { + Sexp::List(xs) if xs.len() == 2 && *xs[0].atom()? == *LOG => Some(Self(&xs[1])), + _ => None, + } + } + + fn eval(self) -> Sexp { + eprintln!("LOG: {}", self.0); + self.0.clone() + } +} + fn make_rule(sexp: &Sexp) -> Option { match sexp { Sexp::List(xs) => match &xs[..] {