From bc00dbe69eba285881fca0f5c68d7ec83e2c48dc Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Tue, 28 Dec 2021 01:42:17 +0000 Subject: [PATCH] Implement closures What a pain. Next steps: More happy path tests, then large values/mutabilty, then redo in bytecode. --- Cargo.toml | 5 + src/ast.rs | 16 +- src/eval.rs | 99 +- src/grammar.lalrpop | 5 +- src/grammar.rs | 1351 ++++++++--------- src/main.rs | 19 +- src/prims.rs | 38 +- ...ball__tests__run-pass@ambig-scope.scm.snap | 13 + ...handball__tests__run-pass@capture.scm.snap | 9 + .../handball__tests__run-pass@curry.scm.snap | 8 + src/test/run-pass/ambig-scope.scm | 18 + src/test/run-pass/capture.scm | 12 + src/test/run-pass/curry.scm | 7 + src/value.rs | 41 +- 14 files changed, 816 insertions(+), 825 deletions(-) create mode 100644 src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@capture.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@curry.scm.snap create mode 100644 src/test/run-pass/ambig-scope.scm create mode 100644 src/test/run-pass/capture.scm create mode 100644 src/test/run-pass/curry.scm diff --git a/Cargo.toml b/Cargo.toml index 41c62ef..bf58b25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,8 @@ lalrpop = "0.19.6" [dev-dependencies] assert_cmd = "2.0.2" insta = { version = "1.9.0", features = ["glob"] } + +[profile.dev] +# https://github.com/rust-lang/rust/issues/92163 +# https://github.com/rust-lang/rust/issues/92315 +incremental=false \ No newline at end of file diff --git a/src/ast.rs b/src/ast.rs index cdd9503..d4029e6 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,20 +1,24 @@ use std::rc::Rc; -#[derive(Debug, debug2::Debug, PartialEq)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] crate enum Tree { Leaf(Literal), Define(String, Box), If(Box<[Tree; 3]>), - Lambda(Lambda), + // Its easier to box the lambdas in the parser than the vm, as + // here we see all of them exactly once + Func(Rc), Branch(Vec), } -#[derive(Debug, debug2::Debug, PartialEq, Clone)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] +crate struct Func { + crate args: Vec, + crate body: Vec, +} -crate struct Lambda(crate Rc<[String]>, crate Rc<[Tree]>); - -#[derive(Debug, debug2::Debug, PartialEq)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] crate enum Literal { Sym(String), diff --git a/src/eval.rs b/src/eval.rs index b9dbd8d..5eaf1c6 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -1,58 +1,77 @@ use std::assert_matches::assert_matches; +use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; use crate::value::Value; use crate::{ast, prims}; -pub(crate) fn eval(t: &ast::Tree, env: &mut Env) -> Result { +#[derive(/*debug2::Debug,*/ Debug, Clone)] +crate struct Lambda { + crate func: Rc, + crate captures: Rc>, +} + +pub(crate) fn eval(t: &ast::Tree, env: Rc>) -> Result { Ok(match t { ast::Tree::Leaf(l) => match l { - ast::Literal::Sym(s) => match env.lookup(s) { + ast::Literal::Sym(s) => match env.borrow().lookup(s) { Some(v) => v, None => return err(format!("Undefined variable `{}`", s)), }, ast::Literal::Num(v) => Value::Num(*v), ast::Literal::Bool(b) => Value::Bool(*b), }, - ast::Tree::Lambda(l) => Value::Lambda(l.clone()), + ast::Tree::Func(l) => Value::Lambda(Lambda { + func: Rc::clone(l), + captures: Rc::clone(&env), + }), ast::Tree::Branch(args) => { - let Some(fun) = args.get(0) else { return err("No argument given".to_owned()) }; - let fun = eval(fun, env)?; - let fun = fun.as_func()?; + let Some(fun) = args.get(0) else { return err("No func given".to_owned()) }; + + let fun = eval(fun, Rc::clone(&env))?.as_func()?; + let args = args .iter() .skip(1) - .map(|a| eval(a, env)) + .map(|a| eval(a, Rc::clone(&env))) .collect::, _>>()?; - // return fun(&args); + match fun { Callable::Func(f) => f(&args)?, Callable::Lambda(l) => { - if l.0.len() == args.len() { - let mut env = env.child(); - for (x, y) in l.0.iter().zip(args) { + if l.func.args.len() == args.len() { + // let mut env = env.child(); + let mut env = Env::child(Rc::clone(&l.captures)); + + for (x, y) in l.func.args.iter().zip(args) { env.define(x.clone(), y) } + let env = Rc::new(RefCell::new(env)); - let [main @ .., tail] = &l.1[..] else { unreachable!("Body has 1+ element by parser") }; + let [main @ .., tail] = &l.func.body[..] else { unreachable!("Body has 1+ element by parser") }; for i in main { - eval(i, &mut env)?; + eval(i, Rc::clone(&env))?; } - eval(tail, &mut env)? + eval(tail, env)? } else { - return err(format!("Need {} args, got {}", l.0.len(), args.len())); + return err(format!( + "Need {} args, got {}", + l.func.args.len(), + args.len() + )); } } } } ast::Tree::Define(name, to) => { - let val = eval(to, env)?; - env.define(name.to_owned(), val); + let val = eval(to, Rc::clone(&env))?; + env.borrow_mut().define(name.to_owned(), val); Value::Trap } ast::Tree::If(box [cond, tcase, fcase]) => { - let b = eval(cond, env)?.as_bool()?; + let b = eval(cond, Rc::clone(&env))?.as_bool()?; let body = if b { tcase } else { fcase }; eval(body, env)? } @@ -66,40 +85,60 @@ pub(crate) fn err(s: String) -> Result { Err(RTError(s)) } -pub(crate) enum Callable<'a> { - Func(prims::Func), - Lambda(&'a ast::Lambda), +pub(crate) enum Callable { + Func(prims::NativeFunc), + Lambda(Lambda), } -pub(crate) struct Env<'a> { - pub(crate) vars: HashMap, - pub(crate) enclosing: Option<&'a Env<'a>>, +#[derive(Clone /*, debug2::Debug*/)] +pub(crate) struct Env { + vars: HashMap, + enclosing: Option>>, } -impl<'a> Env<'a> { - pub(crate) fn child(&'a self) -> Env<'a> { +impl std::fmt::Debug for Env { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + struct Vars<'a>(&'a HashMap); + + impl std::fmt::Debug for Vars<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_set().entries(self.0.keys()).finish() + } + } + + f.debug_struct("Env") + .field("vars", &Vars(&self.vars)) + .field("enclosing", &self.enclosing) + .finish() + } +} + +impl Env { + pub(crate) fn child(this: Rc>) -> Env { Env { vars: HashMap::new(), - enclosing: Some(self), + enclosing: Some(this), } } pub(crate) fn lookup(&self, s: &str) -> Option { if let Some(v) = self.vars.get(s) { Some(v.clone()) - } else if let Some(parent) = self.enclosing { - parent.lookup(s) + } else if let Some(parent) = &self.enclosing { + parent.borrow().lookup(s) } else { None } } pub(crate) fn define(&mut self, name: String, val: Value) { + assert_ne!(val, Value::Trap); // TODO: Better error + self.vars.insert(name, val); } } -pub(crate) fn default_env() -> Env<'static> { +pub(crate) fn default_env() -> Env { let mut vars = HashMap::new(); for (name, fun) in prims::prims() { diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 681053d..3aed6d9 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -17,9 +17,10 @@ Trees = Tree+; pub(crate) Tree: Tree = { "(" ")" => Tree::Branch(<>), "(" "define" ")" => Tree::Define(<>), - "(" "define" "(" > ")" > ")" => Tree::Define(name, Box::new(Tree::Lambda(Lambda(args, body)))), + "(" "define" "(" ")" ")" + => Tree::Define(name, Box::new(Tree::Func(Rc::new(Func{args, body})))), "(" "if" ")" => Tree::If(Box::new([<>])), - "(" "lambda (" > ")" > ")" => Tree::Lambda(Lambda(<>)), + "(" "lambda (" ")" ")" => Tree::Func(Rc::new(Func{<>})), Literal => Tree::Leaf(<>), } diff --git a/src/grammar.rs b/src/grammar.rs index 5175c41..dea8cd9 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.19.6" -// sha3: c1daa5330c6265bff388c19ed1642efbf9924c741dbad19b8016bd2a5a646 +// sha3: e06bc49958cb5e211ea88ac1ea9d95dffc9b12e0e8f9e43b4681a168821c use crate::ast::*; use std::rc::Rc; #[allow(unused_extern_crates)] @@ -33,111 +33,117 @@ mod __parse__File { Variant5(core::option::Option<()>), Variant6(Literal), Variant7(f64), - Variant8(Rc<[String]>), - Variant9(Rc<[Tree]>), - Variant10(String), - Variant11(alloc::vec::Vec), - Variant12(Tree), + Variant8(String), + Variant9(alloc::vec::Vec), + Variant10(Tree), } const __ACTION: &[i8] = &[ // State 0 - 26, 4, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 4, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 1 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 2 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, -31, 0, 0, 0, 0, 0, 30, 31, // State 3 - 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 35, 36, 0, 0, // State 4 - 26, 0, 27, 5, 0, 7, 8, 9, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 7, 8, 9, 0, 0, 30, 31, // State 5 - 26, 0, 27, 5, 35, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 37, 0, 0, 0, 0, 0, 30, 31, // State 6 - 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 31, // State 7 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 8 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 31, // State 9 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 10 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, // State 11 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 12 - 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 31, // State 13 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 14 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 31, // State 15 - 26, 0, 27, 5, -18, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 16 - 26, 0, 27, 5, -19, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 17 - 26, 0, 27, 5, -18, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 31, // State 18 - -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 20 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, // State 21 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 22 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, - // State 23 - -33, 0, -33, -33, -33, 0, 0, 0, 0, 0, -33, -33, - // State 24 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // State 25 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, - // State 26 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, - // State 27 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, - // State 28 - -20, 0, -20, -20, -20, 0, 0, 0, 0, 0, -20, -20, - // State 29 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // State 30 - -34, 0, -34, -34, -34, 0, 0, 0, 0, 0, -34, -34, - // State 31 - -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, -7, -7, - // State 32 - -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, -11, -11, - // State 33 - -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, -10, -10, - // State 34 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, - // State 35 - 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, - // State 36 - 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, -23, - // State 37 - 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, - // State 38 - 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, - // State 39 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, - // State 40 - 0, 0, 0, 0, -24, 0, 0, 0, 0, 0, 0, -24, - // State 41 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, - // State 42 - 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, - // State 43 - 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, - // State 44 - 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, - // State 45 -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, - // State 46 + // State 23 + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + // State 24 + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + // State 25 -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, - // State 47 + // State 26 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 27 + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + // State 28 + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + // State 29 + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + // State 30 + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, -16, -16, + // State 31 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 32 + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + // State 33 + -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, -7, -7, + // State 34 + -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, -11, -11, + // State 35 + -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, -10, -10, + // State 36 + -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, -21, -21, + // State 37 + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, -19, + // State 38 + 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, + // State 39 + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, + // State 40 + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + // State 41 + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, -20, + // State 42 + 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, + // State 43 + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, -22, -22, + // State 44 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, + // State 45 + 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, + // State 46 + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, + // State 47 + 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, // State 48 + -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + // State 49 -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + // State 50 + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, + // State 51 + -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, -23, -23, + // State 52 + -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, -24, -24, ]; fn __action(state: i8, integer: usize) -> i8 { __ACTION[(state as usize) * 12 + integer] @@ -148,7 +154,7 @@ mod __parse__File { // State 1 0, // State 2 - -35, + -31, // State 3 0, // State 4 @@ -180,43 +186,43 @@ mod __parse__File { // State 17 0, // State 18 - -14, + 0, // State 19 - -36, + 0, // State 20 - -30, + -14, // State 21 - -13, + -32, // State 22 - -12, + -28, // State 23 - -33, + -13, // State 24 - -6, + -12, // State 25 - -3, + -29, // State 26 - -2, + -6, // State 27 - -15, + -3, // State 28 - -20, + -2, // State 29 - -5, + -15, // State 30 - -34, + -16, // State 31 - 0, + -5, // State 32 - 0, + -30, // State 33 0, // State 34 - -25, + 0, // State 35 0, // State 36 - 0, + -21, // State 37 0, // State 38 @@ -226,64 +232,70 @@ mod __parse__File { // State 40 0, // State 41 - -26, + 0, // State 42 0, // State 43 - 0, + -22, // State 44 0, // State 45 - -28, + 0, // State 46 - -29, + -26, // State 47 0, // State 48 + -25, + // State 49 -27, + // State 50 + 0, + // State 51 + -23, + // State 52 + -24, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 0 => 37, - 1 => 18, - 2 => 38, - 3 => 19, + 0 => 38, + 1 => 20, + 2 => 39, + 3 => 21, 4 => 1, - 6 => 31, - 7 => 20, - 8 => 21, + 6 => 33, + 7 => 22, + 8 => 23, 9 => match state { - 13 => 42, - _ => 35, - }, - 10 => match state { - 17 => 47, - _ => 44, + 6 => 9, + 10 => 14, + 8 | 14 => 37, + 12 | 17 => 41, + _ => 24, }, 11 => match state { - 6 => 9, - 10 => 13, - 8 | 13 => 36, - 12 => 40, - _ => 22, + 14 => 17, + _ => 12, }, - 13 => 12, - 14 => match state { + 12 => match state { 7 => 11, - 11 => 14, - 2 | 5 | 16 => 30, - 9 => 39, - 14 => 43, - _ => 23, + 11 => 15, + 2 | 5 => 32, + 9 => 40, + 15 => 44, + _ => 25, }, - 16 => match state { - 0..=1 => 2, + 13 => match state { 4 => 5, - _ => 16, + _ => 2, }, - 17 => match state { - 1 => 29, - _ => 24, + 14 => match state { + 1 => 31, + 13 => 42, + 16 => 45, + 18 => 47, + 19 => 50, + _ => 26, }, _ => 0, } @@ -590,18 +602,6 @@ mod __parse__File { __reduce30(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } 31 => { - __reduce31(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 32 => { - __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 33 => { - __reduce33(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 34 => { - __reduce34(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 35 => { // __File = File => ActionFn(0); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); @@ -609,8 +609,8 @@ mod __parse__File { let __nt = super::__action0::<>(input, __sym0); return Some(Ok(__nt)); } - 36 => { - __reduce36(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) + 32 => { + __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } _ => panic!("invalid action code {}", __action) }; @@ -662,54 +662,32 @@ mod __parse__File { 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[String]>, usize) + ) -> (usize, String, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant8(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant9< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[Tree]>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } fn __pop_Variant10< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, String, usize) + ) -> (usize, Tree, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant12< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Tree, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant11< + fn __pop_Variant9< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, alloc::vec::Vec, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -833,7 +811,7 @@ mod __parse__File { ) -> (usize, usize) { // Box = Tree => ActionFn(21); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action21::<>(input, __sym0); @@ -850,13 +828,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(34); + // File = Lang, Trees => ActionFn(30); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant3(__symbols); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action34::<>(input, __sym0, __sym1); + let __nt = super::__action30::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -870,11 +848,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(35); + // File = Trees => ActionFn(31); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action35::<>(input, __sym0); + let __nt = super::__action31::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -980,7 +958,7 @@ mod __parse__File { ) -> (usize, usize) { // Literal = Sym => ActionFn(11); - let __sym0 = __pop_Variant10(__symbols); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action11::<>(input, __sym0); @@ -1051,12 +1029,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(36); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action36::<>(input, &__start, &__end); + // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action14::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (0, 9) + (1, 9) } pub(crate) fn __reduce16< 'input, @@ -1068,13 +1047,12 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Sym+ => ActionFn(37); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action37::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (1, 9) + // Sym* = => ActionFn(22); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action22::<>(input, &__start, &__end); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (0, 10) } pub(crate) fn __reduce17< 'input, @@ -1086,12 +1064,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(38); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action38::<>(input, &__start, &__end); + // Sym* = Sym+ => ActionFn(23); + let __sym0 = __pop_Variant9(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action23::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (0, 10) + (1, 10) } pub(crate) fn __reduce18< 'input, @@ -1103,13 +1082,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Tree+ => ActionFn(39); - let __sym0 = __pop_Variant3(__symbols); + // Sym+ = Sym => ActionFn(28); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, __sym0); + let __nt = super::__action28::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + (1, 11) } pub(crate) fn __reduce19< 'input, @@ -1121,88 +1100,17 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); - let __sym0 = __pop_Variant0(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action14::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) - } - pub(crate) fn __reduce20< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = => ActionFn(28); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action28::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (0, 12) - } - pub(crate) fn __reduce21< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = Sym+ => ActionFn(29); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action29::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) - } - pub(crate) fn __reduce22< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym => ActionFn(32); - let __sym0 = __pop_Variant10(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action32::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 13) - } - pub(crate) fn __reduce23< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym+, Sym => ActionFn(33); + // Sym+ = Sym+, Sym => ActionFn(29); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant10(__symbols); - let __sym0 = __pop_Variant11(__symbols); + let __sym1 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action33::<>(input, __sym0, __sym1); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (2, 13) + let __nt = super::__action29::<>(input, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (2, 11) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce20< 'input, 's, >( @@ -1220,10 +1128,10 @@ mod __parse__File { let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); let __nt = super::__action4::<>(input, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (3, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (3, 12) } - pub(crate) fn __reduce25< + pub(crate) fn __reduce21< 'input, 's, >( @@ -1237,16 +1145,16 @@ mod __parse__File { assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant1(__symbols); - let __sym2 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action5::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (5, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) } - pub(crate) fn __reduce26< + pub(crate) fn __reduce22< 'input, 's, >( @@ -1256,23 +1164,48 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, RcSlice, ")", RcSlice, ")" => ActionFn(6); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(32); + assert!(__symbols.len() >= 7); + let __sym6 = __pop_Variant0(__symbols); + let __sym5 = __pop_Variant3(__symbols); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym6.2.clone(); + let __nt = super::__action32::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (7, 12) + } + pub(crate) fn __reduce23< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(33); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant0(__symbols); - let __sym6 = __pop_Variant9(__symbols); + let __sym6 = __pop_Variant3(__symbols); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant8(__symbols); - let __sym3 = __pop_Variant10(__symbols); + let __sym4 = __pop_Variant9(__symbols); + let __sym3 = __pop_Variant8(__symbols); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym7.2.clone(); - let __nt = super::__action6::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (8, 14) + let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (8, 12) } - pub(crate) fn __reduce27< + pub(crate) fn __reduce24< 'input, 's, >( @@ -1285,18 +1218,18 @@ mod __parse__File { // Tree = "(", "if", Tree, Tree, Tree, ")" => ActionFn(7); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant12(__symbols); - let __sym3 = __pop_Variant12(__symbols); - let __sym2 = __pop_Variant12(__symbols); + let __sym4 = __pop_Variant10(__symbols); + let __sym3 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant10(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); let __nt = super::__action7::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce28< + pub(crate) fn __reduce25< 'input, 's, >( @@ -1306,21 +1239,44 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", RcSlice, ")", RcSlice, ")" => ActionFn(8); + // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(34); + assert!(__symbols.len() >= 5); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant3(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym4.2.clone(); + let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) + } + pub(crate) fn __reduce26< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(35); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant9(__symbols); + let __sym4 = __pop_Variant3(__symbols); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant9(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action8::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce29< + pub(crate) fn __reduce27< 'input, 's, >( @@ -1335,45 +1291,10 @@ mod __parse__File { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action9::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } - pub(crate) fn __reduce30< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = => ActionFn(30); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action30::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (0, 15) - } - pub(crate) fn __reduce31< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = Tree+ => ActionFn(31); - let __sym0 = __pop_Variant3(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action31::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 15) - } - pub(crate) fn __reduce32< + pub(crate) fn __reduce28< 'input, 's, >( @@ -1384,14 +1305,14 @@ mod __parse__File { ) -> (usize, usize) { // Tree+ = Tree => ActionFn(24); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 16) + (1, 13) } - pub(crate) fn __reduce33< + pub(crate) fn __reduce29< 'input, 's, >( @@ -1403,15 +1324,15 @@ mod __parse__File { { // Tree+ = Tree+, Tree => ActionFn(25); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant12(__symbols); + let __sym1 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); let __nt = super::__action25::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (2, 16) + (2, 13) } - pub(crate) fn __reduce34< + pub(crate) fn __reduce30< 'input, 's, >( @@ -1427,9 +1348,9 @@ mod __parse__File { let __end = __sym0.2.clone(); let __nt = super::__action3::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 17) + (1, 14) } - pub(crate) fn __reduce36< + pub(crate) fn __reduce32< 'input, 's, >( @@ -1440,12 +1361,12 @@ mod __parse__File { ) -> (usize, usize) { // __Tree = Tree => ActionFn(1); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action1::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 19) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 16) } } pub(crate) use self::__parse__File::FileParser; @@ -1474,95 +1395,103 @@ mod __parse__Tree { Variant5(core::option::Option<()>), Variant6(Literal), Variant7(f64), - Variant8(Rc<[String]>), - Variant9(Rc<[Tree]>), - Variant10(String), - Variant11(alloc::vec::Vec), - Variant12(Tree), + Variant8(String), + Variant9(alloc::vec::Vec), + Variant10(Tree), } const __ACTION: &[i8] = &[ // State 0 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 1 - 21, 0, 22, 2, 0, 4, 5, 6, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 4, 5, 6, 0, 0, 26, 27, // State 2 - 21, 0, 22, 2, 27, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 30, 0, 0, 0, 0, 0, 26, 27, // State 3 - 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 27, // State 4 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 5 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 27, // State 6 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 7 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, // State 8 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 9 - 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 27, // State 10 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 11 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 27, // State 12 - 21, 0, 22, 2, -18, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 13 - 21, 0, 22, 2, -19, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 14 - 21, 0, 22, 2, -18, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, -31, 0, 0, 0, 0, 0, 26, 27, // State 15 - -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, + 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 27, // State 16 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 17 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 18 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // State 20 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, - // State 21 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, - // State 22 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, - // State 23 - -20, 0, -20, -20, -20, 0, 0, 0, 0, 0, -20, -20, - // State 24 - -33, 0, -33, -33, -33, 0, 0, 0, 0, 0, -33, -33, - // State 25 - -34, 0, -34, -34, -34, 0, 0, 0, 0, 0, -34, -34, - // State 26 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, - // State 27 - 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, - // State 28 - 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, -23, - // State 29 - 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, - // State 30 - 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, - // State 31 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, - // State 32 - 0, 0, 0, 0, -24, 0, 0, 0, 0, 0, 0, -24, - // State 33 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, - // State 34 - 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, - // State 35 - 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 0, 0, - // State 36 - 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, - // State 37 -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, - // State 38 + // State 20 + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + // State 21 + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + // State 22 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 23 + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + // State 24 + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + // State 25 + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + // State 26 + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, -16, -16, + // State 27 -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, + // State 28 + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + // State 29 + -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, -21, -21, + // State 30 + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, -19, + // State 31 + 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, + // State 32 + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, + // State 33 + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + // State 34 + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, -20, + // State 35 + 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, + // State 36 + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, -22, -22, + // State 37 + 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, + // State 38 + 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, // State 39 - 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, // State 40 + 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, + // State 41 + -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + // State 42 -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + // State 43 + 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, + // State 44 + -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, -23, -23, + // State 45 + -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, -24, -24, ]; fn __action(state: i8, integer: usize) -> i8 { __ACTION[(state as usize) * 12 + integer] @@ -1599,35 +1528,35 @@ mod __parse__Tree { // State 14 0, // State 15 - -14, + 0, // State 16 - -30, + 0, // State 17 - -13, + 0, // State 18 - -12, + -14, // State 19 - -37, + -28, // State 20 - -3, + -13, // State 21 - -2, + -12, // State 22 - -15, + -33, // State 23 - -20, + -3, // State 24 - 0, + -2, // State 25 - 0, + -15, // State 26 - -25, + -16, // State 27 0, // State 28 0, // State 29 - 0, + -21, // State 30 0, // State 31 @@ -1635,57 +1564,68 @@ mod __parse__Tree { // State 32 0, // State 33 - -26, + 0, // State 34 0, // State 35 0, // State 36 - 0, + -22, // State 37 - -28, - // State 38 - -29, - // State 39 0, + // State 38 + 0, + // State 39 + -26, // State 40 + 0, + // State 41 + -25, + // State 42 -27, + // State 43 + 0, + // State 44 + -23, + // State 45 + -24, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 0 => 29, - 1 => 15, - 2 => 30, - 7 => 16, - 8 => 17, + 0 => 31, + 1 => 18, + 2 => 32, + 7 => 19, + 8 => 20, 9 => match state { - 10 => 34, - _ => 27, - }, - 10 => match state { - 14 => 39, - _ => 36, + 3 => 6, + 7 => 11, + 5 | 11 => 30, + 9 | 15 => 34, + _ => 21, }, 11 => match state { - 3 => 6, - 7 => 10, - 5 | 10 => 28, - 9 => 32, - _ => 18, + 11 => 15, + _ => 9, }, - 13 => 9, - 14 => match state { + 12 => match state { 4 => 8, - 8 => 11, - 0 => 19, - 2 | 13 => 25, - 6 => 31, - 11 => 35, - _ => 24, + 8 => 12, + 0 => 22, + 2 | 14 => 28, + 6 => 33, + 12 => 37, + _ => 27, }, - 16 => match state { + 13 => match state { 1 => 2, - _ => 13, + _ => 14, + }, + 14 => match state { + 13 => 38, + 16 => 40, + 17 => 43, + _ => 35, }, _ => 0, } @@ -1995,20 +1935,8 @@ mod __parse__Tree { __reduce31(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } 32 => { - __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 33 => { - __reduce33(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 34 => { - __reduce34(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 35 => { - __reduce35(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 36 => { // __Tree = Tree => ActionFn(1); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action1::<>(input, __sym0); @@ -2064,54 +1992,32 @@ mod __parse__Tree { 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[String]>, usize) + ) -> (usize, String, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant8(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant9< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[Tree]>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } fn __pop_Variant10< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, String, usize) + ) -> (usize, Tree, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant12< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Tree, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant11< + fn __pop_Variant9< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, alloc::vec::Vec, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -2235,7 +2141,7 @@ mod __parse__Tree { ) -> (usize, usize) { // Box = Tree => ActionFn(21); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action21::<>(input, __sym0); @@ -2252,13 +2158,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(34); + // File = Lang, Trees => ActionFn(30); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant3(__symbols); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action34::<>(input, __sym0, __sym1); + let __nt = super::__action30::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -2272,11 +2178,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(35); + // File = Trees => ActionFn(31); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action35::<>(input, __sym0); + let __nt = super::__action31::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -2382,7 +2288,7 @@ mod __parse__Tree { ) -> (usize, usize) { // Literal = Sym => ActionFn(11); - let __sym0 = __pop_Variant10(__symbols); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action11::<>(input, __sym0); @@ -2453,12 +2359,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(36); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action36::<>(input, &__start, &__end); + // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action14::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (0, 9) + (1, 9) } pub(crate) fn __reduce16< 'input, @@ -2470,13 +2377,12 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Sym+ => ActionFn(37); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action37::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (1, 9) + // Sym* = => ActionFn(22); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action22::<>(input, &__start, &__end); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (0, 10) } pub(crate) fn __reduce17< 'input, @@ -2488,12 +2394,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(38); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action38::<>(input, &__start, &__end); + // Sym* = Sym+ => ActionFn(23); + let __sym0 = __pop_Variant9(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action23::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (0, 10) + (1, 10) } pub(crate) fn __reduce18< 'input, @@ -2505,13 +2412,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Tree+ => ActionFn(39); - let __sym0 = __pop_Variant3(__symbols); + // Sym+ = Sym => ActionFn(28); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, __sym0); + let __nt = super::__action28::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + (1, 11) } pub(crate) fn __reduce19< 'input, @@ -2523,88 +2430,17 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); - let __sym0 = __pop_Variant0(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action14::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) - } - pub(crate) fn __reduce20< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = => ActionFn(28); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action28::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (0, 12) - } - pub(crate) fn __reduce21< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = Sym+ => ActionFn(29); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action29::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) - } - pub(crate) fn __reduce22< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym => ActionFn(32); - let __sym0 = __pop_Variant10(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action32::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 13) - } - pub(crate) fn __reduce23< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym+, Sym => ActionFn(33); + // Sym+ = Sym+, Sym => ActionFn(29); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant10(__symbols); - let __sym0 = __pop_Variant11(__symbols); + let __sym1 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action33::<>(input, __sym0, __sym1); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (2, 13) + let __nt = super::__action29::<>(input, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (2, 11) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce20< 'input, 's, >( @@ -2622,10 +2458,10 @@ mod __parse__Tree { let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); let __nt = super::__action4::<>(input, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (3, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (3, 12) } - pub(crate) fn __reduce25< + pub(crate) fn __reduce21< 'input, 's, >( @@ -2639,16 +2475,16 @@ mod __parse__Tree { assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant1(__symbols); - let __sym2 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action5::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (5, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) } - pub(crate) fn __reduce26< + pub(crate) fn __reduce22< 'input, 's, >( @@ -2658,23 +2494,48 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, RcSlice, ")", RcSlice, ")" => ActionFn(6); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(32); + assert!(__symbols.len() >= 7); + let __sym6 = __pop_Variant0(__symbols); + let __sym5 = __pop_Variant3(__symbols); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym6.2.clone(); + let __nt = super::__action32::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (7, 12) + } + pub(crate) fn __reduce23< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(33); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant0(__symbols); - let __sym6 = __pop_Variant9(__symbols); + let __sym6 = __pop_Variant3(__symbols); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant8(__symbols); - let __sym3 = __pop_Variant10(__symbols); + let __sym4 = __pop_Variant9(__symbols); + let __sym3 = __pop_Variant8(__symbols); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym7.2.clone(); - let __nt = super::__action6::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (8, 14) + let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (8, 12) } - pub(crate) fn __reduce27< + pub(crate) fn __reduce24< 'input, 's, >( @@ -2687,18 +2548,18 @@ mod __parse__Tree { // Tree = "(", "if", Tree, Tree, Tree, ")" => ActionFn(7); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant12(__symbols); - let __sym3 = __pop_Variant12(__symbols); - let __sym2 = __pop_Variant12(__symbols); + let __sym4 = __pop_Variant10(__symbols); + let __sym3 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant10(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); let __nt = super::__action7::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce28< + pub(crate) fn __reduce25< 'input, 's, >( @@ -2708,21 +2569,44 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", RcSlice, ")", RcSlice, ")" => ActionFn(8); + // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(34); + assert!(__symbols.len() >= 5); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant3(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym4.2.clone(); + let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) + } + pub(crate) fn __reduce26< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(35); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant9(__symbols); + let __sym4 = __pop_Variant3(__symbols); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant9(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action8::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce29< + pub(crate) fn __reduce27< 'input, 's, >( @@ -2737,45 +2621,10 @@ mod __parse__Tree { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action9::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } - pub(crate) fn __reduce30< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = => ActionFn(30); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action30::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (0, 15) - } - pub(crate) fn __reduce31< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = Tree+ => ActionFn(31); - let __sym0 = __pop_Variant3(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action31::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 15) - } - pub(crate) fn __reduce32< + pub(crate) fn __reduce28< 'input, 's, >( @@ -2786,14 +2635,14 @@ mod __parse__Tree { ) -> (usize, usize) { // Tree+ = Tree => ActionFn(24); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 16) + (1, 13) } - pub(crate) fn __reduce33< + pub(crate) fn __reduce29< 'input, 's, >( @@ -2805,15 +2654,15 @@ mod __parse__Tree { { // Tree+ = Tree+, Tree => ActionFn(25); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant12(__symbols); + let __sym1 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); let __nt = super::__action25::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (2, 16) + (2, 13) } - pub(crate) fn __reduce34< + pub(crate) fn __reduce30< 'input, 's, >( @@ -2829,9 +2678,9 @@ mod __parse__Tree { let __end = __sym0.2.clone(); let __nt = super::__action3::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 17) + (1, 14) } - pub(crate) fn __reduce35< + pub(crate) fn __reduce31< 'input, 's, >( @@ -2847,7 +2696,7 @@ mod __parse__Tree { let __end = __sym0.2.clone(); let __nt = super::__action0::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 18) + (1, 15) } } pub(crate) use self::__parse__Tree::TreeParser; @@ -2943,12 +2792,12 @@ fn __action6<'input, 's>( (_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize), (_, name, _): (usize, String, usize), - (_, args, _): (usize, Rc<[String]>, usize), + (_, args, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), - (_, body, _): (usize, Rc<[Tree]>, usize), + (_, body, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), ) -> Tree { - Tree::Define(name, Box::new(Tree::Lambda(Lambda(args, body)))) + Tree::Define(name, Box::new(Tree::Func(Rc::new(Func { args, body })))) } #[allow(unused_variables)] @@ -2969,12 +2818,15 @@ fn __action8<'input, 's>( input: &'input str, (_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize), - (_, __0, _): (usize, Rc<[String]>, usize), + (_, args, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), - (_, __1, _): (usize, Rc<[Tree]>, usize), + (_, body, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), ) -> Tree { - Tree::Lambda(Lambda(__0, __1)) + Tree::Func(Rc::new(Func { + args: args, + body: body, + })) } #[allow(unused_variables)] @@ -3055,17 +2907,18 @@ fn __action21<'input, 's>(input: &'input str, (_, __0, _): (usize, Tree, usize)) #[allow(unused_variables)] fn __action22<'input, 's>( input: &'input str, - (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> Rc<[Tree]> { - __0.into() + __lookbehind: &usize, + __lookahead: &usize, +) -> alloc::vec::Vec { + alloc::vec![] } #[allow(unused_variables)] fn __action23<'input, 's>( input: &'input str, - (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> Rc<[String]> { - __0.into() + (_, v, _): (usize, alloc::vec::Vec, usize), +) -> alloc::vec::Vec { + v } #[allow(unused_variables)] @@ -3108,40 +2961,6 @@ fn __action27<'input, 's>( #[allow(unused_variables)] fn __action28<'input, 's>( - input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> alloc::vec::Vec { - alloc::vec![] -} - -#[allow(unused_variables)] -fn __action29<'input, 's>( - input: &'input str, - (_, v, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { - v -} - -#[allow(unused_variables)] -fn __action30<'input, 's>( - input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> alloc::vec::Vec { - alloc::vec![] -} - -#[allow(unused_variables)] -fn __action31<'input, 's>( - input: &'input str, - (_, v, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { - v -} - -#[allow(unused_variables)] -fn __action32<'input, 's>( input: &'input str, (_, __0, _): (usize, String, usize), ) -> alloc::vec::Vec { @@ -3149,7 +2968,7 @@ fn __action32<'input, 's>( } #[allow(unused_variables)] -fn __action33<'input, 's>( +fn __action29<'input, 's>( input: &'input str, (_, v, _): (usize, alloc::vec::Vec, usize), (_, e, _): (usize, String, usize), @@ -3162,7 +2981,7 @@ fn __action33<'input, 's>( } #[allow(unused_variables)] -fn __action34<'input, 's>( +fn __action30<'input, 's>( input: &'input str, __0: (usize, (), usize), __1: (usize, alloc::vec::Vec, usize), @@ -3175,7 +2994,7 @@ fn __action34<'input, 's>( } #[allow(unused_variables)] -fn __action35<'input, 's>( +fn __action31<'input, 's>( input: &'input str, __0: (usize, alloc::vec::Vec, usize), ) -> alloc::vec::Vec { @@ -3187,53 +3006,73 @@ fn __action35<'input, 's>( } #[allow(unused_variables)] -fn __action36<'input, 's>( +fn __action32<'input, 's>( input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> Rc<[String]> { - let __start0 = __lookbehind.clone(); - let __end0 = __lookahead.clone(); - let __temp0 = __action28(input, &__start0, &__end0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, &'input str, usize), + __3: (usize, String, usize), + __4: (usize, &'input str, usize), + __5: (usize, alloc::vec::Vec, usize), + __6: (usize, &'input str, usize), +) -> Tree { + let __start0 = __3.2.clone(); + let __end0 = __4.0.clone(); + let __temp0 = __action22(input, &__start0, &__end0); let __temp0 = (__start0, __temp0, __end0); - __action23(input, __temp0) + __action6(input, __0, __1, __2, __3, __temp0, __4, __5, __6) } #[allow(unused_variables)] -fn __action37<'input, 's>( +fn __action33<'input, 's>( input: &'input str, - __0: (usize, alloc::vec::Vec, usize), -) -> Rc<[String]> { - let __start0 = __0.0.clone(); - let __end0 = __0.2.clone(); - let __temp0 = __action29(input, __0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, &'input str, usize), + __3: (usize, String, usize), + __4: (usize, alloc::vec::Vec, usize), + __5: (usize, &'input str, usize), + __6: (usize, alloc::vec::Vec, usize), + __7: (usize, &'input str, usize), +) -> Tree { + let __start0 = __4.0.clone(); + let __end0 = __4.2.clone(); + let __temp0 = __action23(input, __4); let __temp0 = (__start0, __temp0, __end0); - __action23(input, __temp0) + __action6(input, __0, __1, __2, __3, __temp0, __5, __6, __7) } #[allow(unused_variables)] -fn __action38<'input, 's>( +fn __action34<'input, 's>( input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> Rc<[Tree]> { - let __start0 = __lookbehind.clone(); - let __end0 = __lookahead.clone(); - let __temp0 = __action30(input, &__start0, &__end0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, &'input str, usize), + __3: (usize, alloc::vec::Vec, usize), + __4: (usize, &'input str, usize), +) -> Tree { + let __start0 = __1.2.clone(); + let __end0 = __2.0.clone(); + let __temp0 = __action22(input, &__start0, &__end0); let __temp0 = (__start0, __temp0, __end0); - __action22(input, __temp0) + __action8(input, __0, __1, __temp0, __2, __3, __4) } #[allow(unused_variables)] -fn __action39<'input, 's>( +fn __action35<'input, 's>( input: &'input str, - __0: (usize, alloc::vec::Vec, usize), -) -> Rc<[Tree]> { - let __start0 = __0.0.clone(); - let __end0 = __0.2.clone(); - let __temp0 = __action31(input, __0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, alloc::vec::Vec, usize), + __3: (usize, &'input str, usize), + __4: (usize, alloc::vec::Vec, usize), + __5: (usize, &'input str, usize), +) -> Tree { + let __start0 = __2.0.clone(); + let __end0 = __2.2.clone(); + let __temp0 = __action23(input, __2); let __temp0 = (__start0, __temp0, __end0); - __action22(input, __temp0) + __action8(input, __0, __1, __temp0, __3, __4, __5) } pub trait __ToTriple<'input, 's> { diff --git a/src/main.rs b/src/main.rs index 1f83267..f7ec21c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,9 @@ #![feature(crate_visibility_modifier)] #![feature(let_else)] +use std::cell::RefCell; use std::io; +use std::rc::Rc; use rustyline::validate::{ MatchingBracketValidator, ValidationContext, ValidationResult, Validator, @@ -33,9 +35,9 @@ fn main() { fn run_file(file: &str) -> io::Result<()> { let src = std::fs::read_to_string(file)?; let tree = grammar::FileParser::new().parse(&src).unwrap(); - let mut env = eval::default_env(); + let env = Rc::new(RefCell::new(eval::default_env())); for i in tree { - eval::eval(&i, &mut env).unwrap(); + eval::eval(&i, Rc::clone(&env)).unwrap(); } Ok(()) } @@ -46,14 +48,23 @@ fn repl() { brackets: MatchingBracketValidator::new(), })); - let mut env = eval::default_env(); + let env = Rc::new(RefCell::new(eval::default_env())); while let Ok(line) = rl.readline("> ") { rl.add_history_entry(&line); let tree = grammar::TreeParser::new().parse(&line).unwrap(); // dbg!(&tree); - println!("< {:?}", eval::eval(&tree, &mut env)) + match eval::eval(&tree, Rc::clone(&env)) { + Ok(v) => { + // Cant use == because it will panic. This is the only + // valid comparison to trap + if !matches!(v, value::Value::Trap) { + println!("{}", v) + } + } + Err(e) => println!("! {}", e.0), + } } } diff --git a/src/prims.rs b/src/prims.rs index 62e67ff..45c1232 100644 --- a/src/prims.rs +++ b/src/prims.rs @@ -1,9 +1,12 @@ use crate::eval::{err, RTError}; use crate::value::Value; -crate type Func = fn(&[Value]) -> Result; -crate fn prims() -> &'static [(&'static str, Func)] { +type Result = std::result::Result; + +crate type NativeFunc = for<'a> fn(&'a [Value]) -> Result; + +crate fn prims() -> &'static [(&'static str, NativeFunc)] { &[ ("*", mul), ("+", add), @@ -21,25 +24,27 @@ crate fn prims() -> &'static [(&'static str, Func)] { (">", gt), ("<=", le), (">=", ge), + + ("_Z_debug", z_debug) ] } // TODO: DRY +-/* -fn add(args: &[Value]) -> Result { +fn add(args: &[Value]) -> Result { args.iter() .map(Value::as_num) .try_fold(0.0, |a, b| Ok(a + b?)) .map(Value::Num) } -fn mul(args: &[Value]) -> Result { +fn mul(args: &[Value]) -> Result { args.iter() .map(Value::as_num) .try_fold(1.0, |a, b| Ok(a * b?)) .map(Value::Num) } -fn div(args: &[Value]) -> Result { +fn div(args: &[Value]) -> Result { let init = args .get(0) .ok_or_else(|| RTError("`div` needs at least one argument".to_owned()))? @@ -53,7 +58,7 @@ fn div(args: &[Value]) -> Result { })) } -fn sub(args: &[Value]) -> Result { +fn sub(args: &[Value]) -> Result { let init = args .get(0) .ok_or_else(|| RTError("`sub` needs at least one argument".to_owned()))? @@ -67,17 +72,17 @@ fn sub(args: &[Value]) -> Result { })) } -fn equals(args: &[Value]) -> Result { +fn equals(args: &[Value]) -> Result { Ok(Value::Bool(args.array_windows().all(|[l, r]| l == r))) } -fn display(args: &[Value]) -> Result { +fn display(args: &[Value]) -> Result { let [arg] = args else {return err("To many args to `display`".to_owned())}; - print!("{:?}", arg); + print!("{}", arg); Ok(Value::Trap) } -fn newline(args: &[Value]) -> Result { +fn newline(args: &[Value]) -> Result { if !args.is_empty() { return err("Newline takes no args".to_owned()); } @@ -85,7 +90,7 @@ fn newline(args: &[Value]) -> Result { Ok(Value::Trap) } -fn abs(args: &[Value]) -> Result { +fn abs(args: &[Value]) -> Result { let [v] = args else { return err("abs takes 1 arg".to_owned()) }; let ans = v.as_num()?.abs(); Ok(Value::Num(ans)) @@ -95,7 +100,7 @@ crate fn compare_core( args: &[Value], f: fn(f64, f64) -> bool, name: &'static str, -) -> Result { +) -> Result { for [l, r] in args.array_windows() { let (Value::Num(l), Value::Num(r)) = (l,r) else { @@ -114,11 +119,16 @@ crate fn compare_core( macro_rules! cmps { ($(($name:ident $op:tt))*) => { $( - fn $name(args: &[Value]) -> Result { + fn $name(args: &[Value]) -> Result { compare_core(args, |l, r| l $op r, stringify!($op)) } )* }; } -cmps! { (lt <) (gt >) (le <=) (ge >=) } \ No newline at end of file +cmps! { (lt <) (gt >) (le <=) (ge >=) } + +fn z_debug(args: &[Value]) -> Result { + eprintln!("{:?}", args); + Ok(Value::Trap) +} \ No newline at end of file diff --git a/src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap b/src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap new file mode 100644 index 0000000..657c8a2 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap @@ -0,0 +1,13 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: run-pass ambig-scope.scm + +--- + +42.0 +1.0 +2.0 +3.0 +2.0 +1.0 diff --git a/src/snapshots/handball__tests__run-pass@capture.scm.snap b/src/snapshots/handball__tests__run-pass@capture.scm.snap new file mode 100644 index 0000000..4d73305 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@capture.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: run-pass capture.scm + +--- +# +2.0 + diff --git a/src/snapshots/handball__tests__run-pass@curry.scm.snap b/src/snapshots/handball__tests__run-pass@curry.scm.snap new file mode 100644 index 0000000..7e245c0 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@curry.scm.snap @@ -0,0 +1,8 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: run-pass curry.scm + +--- +3.0 + diff --git a/src/test/run-pass/ambig-scope.scm b/src/test/run-pass/ambig-scope.scm new file mode 100644 index 0000000..055e8ac --- /dev/null +++ b/src/test/run-pass/ambig-scope.scm @@ -0,0 +1,18 @@ +#lang scheme + +(define (displayln x) (newline) (display x)) + +(define (ambig1 x) (lambda (x) x)) + +(displayln ((ambig1 13) 42)) + +(define (ambig2 a) + (displayln a) + (define a- a) + (lambda (b) (displayln b) + (lambda (a) + (displayln a) + (displayln b) + (displayln a-)))) + +(((ambig2 1) 2) 3) \ No newline at end of file diff --git a/src/test/run-pass/capture.scm b/src/test/run-pass/capture.scm new file mode 100644 index 0000000..bbf6c99 --- /dev/null +++ b/src/test/run-pass/capture.scm @@ -0,0 +1,12 @@ +#lang scheme + +(define (displayln x) (display x) (newline)) + + +(define (const x) (lambda () x)) + +(define two-thunk (const 2)) + +(displayln two-thunk) +(displayln (two-thunk)) + diff --git a/src/test/run-pass/curry.scm b/src/test/run-pass/curry.scm new file mode 100644 index 0000000..c5bac77 --- /dev/null +++ b/src/test/run-pass/curry.scm @@ -0,0 +1,7 @@ +#lang scheme + +(define (displayln x) (display x) (newline)) + +(define (curry2 f) (lambda (l) (lambda (r) (f l r)))) + +(displayln (((curry2 +) 1) 2)) diff --git a/src/value.rs b/src/value.rs index 09f309a..6ddf6de 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,16 +1,32 @@ -use crate::{ast, eval, prims}; +use crate::{eval, prims}; use std::rc::Rc; -#[derive(Clone)] +#[derive(Clone /*, debug2::Debug*/)] crate enum Value { Num(f64), - Func(prims::Func), - Lambda(ast::Lambda), + // TODO: implement debug2::Debug for `fn` type, and do it right + // https://godbolt.org/z/vr9erGeKq + Func(prims::NativeFunc), + Lambda(eval::Lambda), Bool(bool), /// Result of things that shouldnt have values, like (define x 3) + /// TODO: Figure this out Trap, } +impl std::fmt::Debug for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Num(arg0) => f.debug_tuple("Num").field(arg0).finish(), + // We cant just pass the field because of livetime bs, see https://godbolt.org/z/vr9erGeKq + Self::Func(_) => f.debug_struct("Func").finish_non_exhaustive(), + Self::Lambda(arg0) => f.debug_tuple("Lambda").field(arg0).finish(), + Self::Bool(arg0) => f.debug_tuple("Bool").field(arg0).finish(), + Self::Trap => write!(f, "Trap"), + } + } +} + impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { use Value::*; @@ -18,7 +34,9 @@ impl PartialEq for Value { (Num(l), Num(r)) => l == r, (Func(l), Func(r)) => *l as usize == *r as usize, (Bool(l), Bool(r)) => l == r, - (Lambda(l), Lambda(r)) => Rc::ptr_eq(&l.0, &r.0) && Rc::ptr_eq(&l.1, &r.1), + (Lambda(l), Lambda(r)) => { + Rc::ptr_eq(&l.func, &r.func) && Rc::ptr_eq(&l.captures, &r.captures) + } (Num(_), _) => false, (Func(_), _) => false, @@ -30,10 +48,10 @@ impl PartialEq for Value { } } -impl std::fmt::Debug for Value { +impl std::fmt::Display for Value { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Num(n) => n.fmt(f), + Self::Num(n) => std::fmt::Debug::fmt(n, f), // TODO: Change to displays Self::Func(_) => f.write_str("#"), Self::Lambda(_) => f.write_str("#"), Self::Bool(b) => f.write_str(if *b { "#t" } else { "#f" }), @@ -51,14 +69,11 @@ impl Value { } } - crate fn as_func(&self) -> Result { + crate fn as_func(self) -> Result { match self { - Self::Func(f) => Ok(eval::Callable::Func(*f)), + Self::Func(f) => Ok(eval::Callable::Func(f)), Self::Lambda(l) => Ok(eval::Callable::Lambda(l)), - _ => Err(eval::RTError(format!( - "Expected a function, got {:?}", - self - ))), + _ => Err(eval::RTError(format!("Expected a function, got {}", self))), } }