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/README.md b/README.md new file mode 100644 index 0000000..1effd75 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +## Credits + +Many of the tests are adapted from [craftinginterpriters](https://github.com/munificent/craftinginterpreters/tree/master/test). \ No newline at end of file diff --git a/src/ast.rs b/src/ast.rs index cdd9503..6d99b4b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,20 +1,25 @@ use std::rc::Rc; -#[derive(Debug, debug2::Debug, PartialEq)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] crate enum Tree { Leaf(Literal), Define(String, Box), + Set(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..fb4d850 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -1,58 +1,82 @@ 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::Set(name, to) => { + let val = eval(to, Rc::clone(&env))?; + env.borrow_mut().set(name, 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 +90,72 @@ 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 + + // TODO: Error on previous def self.vars.insert(name, val); } + + crate fn set(&mut self, name: &str, val: Value) -> Result<(), RTError> { + if let Some(loc) = self.vars.get_mut(name) { + *loc = val; + Ok(()) + } else if let Some(parent) = &self.enclosing { + parent.borrow_mut().set(name, val) + } else { + err(format!("Tried to `set!` un `define`d var `{}`", name)) + } + } } -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..b85479b 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -17,9 +17,11 @@ 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{<>})), + "(" "set!" ")" => Tree::Set(<>), Literal => Tree::Leaf(<>), } diff --git a/src/grammar.rs b/src/grammar.rs index 5175c41..8b7d0b8 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -1,13 +1,13 @@ // auto-generated: "lalrpop 0.19.6" -// sha3: c1daa5330c6265bff388c19ed1642efbf9924c741dbad19b8016bd2a5a646 +// sha3: 5cdf62b36e7f305a16087e7575bb60a55df0da8fdd57413f4ded28c458e7da use crate::ast::*; use std::rc::Rc; #[allow(unused_extern_crates)] extern crate lalrpop_util as __lalrpop_util; #[allow(unused_imports)] use self::__lalrpop_util::state_machine as __state_machine; -extern crate alloc; extern crate core; +extern crate alloc; #[cfg_attr(rustfmt, rustfmt_skip)] mod __parse__File { @@ -33,114 +33,128 @@ 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, + 30, 4, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 1 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 2 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, -32, 0, 0, 0, 0, 0, 0, 32, 33, // State 3 - 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 37, 38, 0, 0, 0, // State 4 - 26, 0, 27, 5, 0, 7, 8, 9, 0, 0, 28, 29, + 30, 0, 31, 5, 0, 7, 8, 9, 0, 0, 10, 32, 33, // State 5 - 26, 0, 27, 5, 35, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, 39, 0, 0, 0, 0, 0, 0, 32, 33, // State 6 - 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 33, // State 7 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 8 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 33, // State 9 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, // State 10 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 11 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, // State 12 - 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 13 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 33, // State 14 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 15 - 26, 0, 27, 5, -18, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 16 - 26, 0, 27, 5, -19, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 33, // State 17 - 26, 0, 27, 5, -18, 0, 0, 0, 0, 0, 28, 29, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 18 - -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 33, // State 20 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 21 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 22 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, 0, -14, -14, // State 23 - -33, 0, -33, -33, -33, 0, 0, 0, 0, 0, -33, -33, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 24 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, 0, -29, -29, // State 25 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, 0, -13, -13, // State 26 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, 0, -12, -12, // State 27 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, -30, -30, // State 28 - -20, 0, -20, -20, -20, 0, 0, 0, 0, 0, -20, -20, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 29 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, 0, -3, -3, // State 30 - -34, 0, -34, -34, -34, 0, 0, 0, 0, 0, -34, -34, + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, 0, -2, -2, // State 31 - -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, -7, -7, + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, 0, -15, -15, // State 32 - -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, -11, -11, + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, 0, -16, -16, // State 33 - -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, -10, -10, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 34 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + -31, 0, -31, -31, -31, 0, 0, 0, 0, 0, 0, -31, -31, // State 35 - 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, + -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, 0, -7, -7, // State 36 - 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, -23, + -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, 0, -11, -11, // State 37 - 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, + -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, 0, -10, -10, // State 38 - 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, + -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, 0, -21, -21, // State 39 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, 0, -19, // State 40 - 0, 0, 0, 0, -24, 0, 0, 0, 0, 0, 0, -24, + 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, // State 41 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, // State 42 - 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, // State 43 - 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, 0, -20, // State 44 - 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, // State 45 - -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, + 0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, // State 46 - -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, 0, -22, -22, // State 47 - 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, // State 48 - -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + 0, 0, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, + // State 49 + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, 0, -26, -26, + // State 50 + -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, 0, -28, -28, + // State 51 + 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, + // State 52 + -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, 0, -25, -25, + // State 53 + -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, 0, -27, -27, + // State 54 + 0, 0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, + // State 55 + -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, 0, -23, -23, + // State 56 + -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, 0, -24, -24, ]; fn __action(state: i8, integer: usize) -> i8 { - __ACTION[(state as usize) * 12 + integer] + __ACTION[(state as usize) * 13 + integer] } const __EOF_ACTION: &[i8] = &[ // State 0 @@ -148,7 +162,7 @@ mod __parse__File { // State 1 0, // State 2 - -35, + -32, // State 3 0, // State 4 @@ -180,39 +194,39 @@ mod __parse__File { // State 17 0, // State 18 - -14, + 0, // State 19 - -36, + 0, // State 20 - -30, + 0, // State 21 - -13, + 0, // State 22 - -12, + -14, // State 23 -33, // State 24 - -6, + -29, // State 25 - -3, + -13, // State 26 - -2, + -12, // State 27 - -15, + -30, // State 28 - -20, + -6, // State 29 - -5, + -3, // State 30 - -34, + -2, // State 31 - 0, + -15, // State 32 - 0, + -16, // State 33 - 0, + -5, // State 34 - -25, + -31, // State 35 0, // State 36 @@ -220,13 +234,13 @@ mod __parse__File { // State 37 0, // State 38 - 0, + -21, // State 39 0, // State 40 0, // State 41 - -26, + 0, // State 42 0, // State 43 @@ -234,56 +248,74 @@ mod __parse__File { // State 44 0, // State 45 - -28, + 0, // State 46 - -29, + -22, // State 47 0, // State 48 + 0, + // State 49 + -26, + // State 50 + -28, + // State 51 + 0, + // State 52 + -25, + // State 53 -27, + // State 54 + 0, + // State 55 + -23, + // State 56 + -24, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 0 => 37, - 1 => 18, - 2 => 38, - 3 => 19, - 4 => 1, - 6 => 31, - 7 => 20, - 8 => 21, - 9 => match state { - 13 => 42, - _ => 35, + 0 => match state { + 15 => 45, + _ => 40, }, - 10 => match state { - 17 => 47, - _ => 44, + 1 => 22, + 2 => 41, + 3 => 23, + 4 => 1, + 6 => 35, + 7 => 24, + 8 => 25, + 9 => match state { + 6 => 10, + 9 => 15, + 11 => 16, + 8 | 16 => 39, + 13 | 19 => 43, + _ => 26, }, 11 => match state { - 6 => 9, - 10 => 13, - 8 | 13 => 36, - 12 => 40, - _ => 22, + 16 => 19, + _ => 13, }, - 13 => 12, - 14 => match state { - 7 => 11, - 11 => 14, - 2 | 5 | 16 => 30, - 9 => 39, - 14 => 43, - _ => 23, + 12 => match state { + 7 => 12, + 12 => 17, + 2 | 5 => 34, + 10 | 15 => 42, + 17 => 47, + _ => 27, }, - 16 => match state { - 0..=1 => 2, + 13 => match state { 4 => 5, - _ => 16, + _ => 2, }, - 17 => match state { - 1 => 29, - _ => 24, + 14 => match state { + 1 => 33, + 14 => 44, + 18 => 48, + 20 => 51, + 21 => 54, + _ => 28, }, _ => 0, } @@ -300,6 +332,7 @@ mod __parse__File { r###""lambda (""###, r###""r7rs""###, r###""scheme""###, + r###""set!""###, r###"r#"[0-9]+(\\.[0-9]+)?"#"###, r###"r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"#"###, ]; @@ -354,7 +387,7 @@ mod __parse__File { #[inline] fn error_action(&self, state: i8) -> i8 { - __action(state, 12 - 1) + __action(state, 13 - 1) } #[inline] @@ -428,8 +461,9 @@ mod __parse__File { Token(9, _) if true => Some(7), Token(10, _) if true => Some(8), Token(11, _) if true => Some(9), - Token(0, _) if true => Some(10), - Token(1, _) if true => Some(11), + Token(12, _) if true => Some(10), + Token(0, _) if true => Some(11), + Token(1, _) if true => Some(12), _ => None, } } @@ -443,8 +477,8 @@ mod __parse__File { ) -> __Symbol<'input> { match __token_index { - 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 => match __token { - Token(2, __tok0) | Token(3, __tok0) | Token(4, __tok0) | Token(5, __tok0) | Token(6, __tok0) | Token(7, __tok0) | Token(8, __tok0) | Token(9, __tok0) | Token(10, __tok0) | Token(11, __tok0) | Token(0, __tok0) | Token(1, __tok0) if true => __Symbol::Variant0(__tok0), + 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 => match __token { + Token(2, __tok0) | Token(3, __tok0) | Token(4, __tok0) | Token(5, __tok0) | Token(6, __tok0) | Token(7, __tok0) | Token(8, __tok0) | Token(9, __tok0) | Token(10, __tok0) | Token(11, __tok0) | Token(12, __tok0) | Token(0, __tok0) | Token(1, __tok0) if true => __Symbol::Variant0(__tok0), _ => unreachable!(), }, _ => unreachable!(), @@ -593,15 +627,6 @@ mod __parse__File { __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 +634,8 @@ mod __parse__File { let __nt = super::__action0::<>(input, __sym0); return Some(Ok(__nt)); } - 36 => { - __reduce36(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) + 33 => { + __reduce33(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } _ => panic!("invalid action code {}", __action) }; @@ -662,54 +687,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() } } @@ -778,11 +781,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // BTree = Box => ActionFn(10); + // BTree = Box => ActionFn(11); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action10::<>(input, __sym0); + let __nt = super::__action11::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant1(__nt), __end)); (1, 0) } @@ -796,11 +799,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Bool = "#t" => ActionFn(16); + // Bool = "#t" => ActionFn(17); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action16::<>(input, __sym0); + let __nt = super::__action17::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant2(__nt), __end)); (1, 1) } @@ -814,11 +817,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Bool = "#f" => ActionFn(17); + // Bool = "#f" => ActionFn(18); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action17::<>(input, __sym0); + let __nt = super::__action18::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant2(__nt), __end)); (1, 1) } @@ -832,11 +835,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Box = Tree => ActionFn(21); - let __sym0 = __pop_Variant12(__symbols); + // Box = Tree => ActionFn(22); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action21::<>(input, __sym0); + let __nt = super::__action22::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant1(__nt), __end)); (1, 2) } @@ -850,13 +853,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(34); + // File = Lang, Trees => ActionFn(31); 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::__action31::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -870,11 +873,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(35); + // File = Trees => ActionFn(32); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action35::<>(input, __sym0); + let __nt = super::__action32::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -888,13 +891,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Lang = "#lang", LangName => ActionFn(18); + // Lang = "#lang", LangName => ActionFn(19); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action18::<>(input, __sym0, __sym1); + let __nt = super::__action19::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (2, 4) } @@ -908,11 +911,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Lang? = Lang => ActionFn(26); + // Lang? = Lang => ActionFn(27); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action26::<>(input, __sym0); + let __nt = super::__action27::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (1, 5) } @@ -926,10 +929,10 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Lang? = => ActionFn(27); + // Lang? = => 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::__action27::<>(input, &__start, &__end); + let __nt = super::__action28::<>(input, &__start, &__end); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (0, 5) } @@ -943,11 +946,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // LangName = "scheme" => ActionFn(19); + // LangName = "scheme" => ActionFn(20); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action19::<>(input, __sym0); + let __nt = super::__action20::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant0(__nt), __end)); (1, 6) } @@ -961,11 +964,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // LangName = "r7rs" => ActionFn(20); + // LangName = "r7rs" => ActionFn(21); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action20::<>(input, __sym0); + let __nt = super::__action21::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant0(__nt), __end)); (1, 6) } @@ -979,11 +982,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Sym => ActionFn(11); - let __sym0 = __pop_Variant10(__symbols); + // Literal = Sym => ActionFn(12); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action11::<>(input, __sym0); + let __nt = super::__action12::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 7) } @@ -997,11 +1000,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Num => ActionFn(12); + // Literal = Num => ActionFn(13); let __sym0 = __pop_Variant7(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action12::<>(input, __sym0); + let __nt = super::__action13::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 7) } @@ -1015,11 +1018,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Bool => ActionFn(13); + // Literal = Bool => ActionFn(14); let __sym0 = __pop_Variant2(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action13::<>(input, __sym0); + let __nt = super::__action14::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 7) } @@ -1033,11 +1036,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Num = r#"[0-9]+(\\.[0-9]+)?"# => ActionFn(15); + // Num = r#"[0-9]+(\\.[0-9]+)?"# => ActionFn(16); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action15::<>(input, __sym0); + let __nt = super::__action16::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (1, 8) } @@ -1051,12 +1054,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(15); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action15::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (0, 9) + (1, 9) } pub(crate) fn __reduce16< 'input, @@ -1068,13 +1072,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(23); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action23::<>(input, &__start, &__end); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (0, 10) } pub(crate) fn __reduce17< 'input, @@ -1086,12 +1089,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(24); + let __sym0 = __pop_Variant9(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (0, 10) + (1, 10) } pub(crate) fn __reduce18< 'input, @@ -1103,13 +1107,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Tree+ => ActionFn(39); - let __sym0 = __pop_Variant3(__symbols); + // Sym+ = Sym => ActionFn(29); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, __sym0); + let __nt = super::__action29::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + (1, 11) } pub(crate) fn __reduce19< 'input, @@ -1121,88 +1125,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(30); 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::__action30::<>(input, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (2, 11) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce20< 'input, 's, >( @@ -1220,10 +1153,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 +1170,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 +1189,48 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, RcSlice, ")", RcSlice, ")" => ActionFn(6); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(33); + 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::__action33::<>(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(34); 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::__action34::<>(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,16 +1243,86 @@ 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 __reduce25< + '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 (", ")", Trees, ")" => ActionFn(35); + 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::__action35::<>(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(36); + assert!(__symbols.len() >= 6); + let __sym5 = __pop_Variant0(__symbols); + let __sym4 = __pop_Variant3(__symbols); + let __sym3 = __pop_Variant0(__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::__action36::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) + } + pub(crate) fn __reduce27< + '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 = "(", "set!", Sym, BTree, ")" => ActionFn(9); + assert!(__symbols.len() >= 5); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant1(__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::__action9::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) } pub(crate) fn __reduce28< 'input, @@ -1306,19 +1334,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", RcSlice, ")", RcSlice, ")" => ActionFn(8); - assert!(__symbols.len() >= 6); - let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant9(__symbols); - let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); - let __sym1 = __pop_Variant0(__symbols); - let __sym0 = __pop_Variant0(__symbols); + // Tree = Literal => ActionFn(10); + let __sym0 = __pop_Variant6(__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 __end = __sym0.2.clone(); + let __nt = super::__action10::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } pub(crate) fn __reduce29< 'input, @@ -1330,13 +1352,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = Literal => ActionFn(9); - let __sym0 = __pop_Variant6(__symbols); + // Tree+ = Tree => ActionFn(25); + let __sym0 = __pop_Variant10(__symbols); 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) + let __nt = super::__action25::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant3(__nt), __end)); + (1, 13) } pub(crate) fn __reduce30< 'input, @@ -1348,70 +1370,17 @@ mod __parse__File { _: 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< - '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(24); - let __sym0 = __pop_Variant12(__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) - } - pub(crate) fn __reduce33< - '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+, Tree => ActionFn(25); + // Tree+ = Tree+, Tree => ActionFn(26); 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); + let __nt = super::__action26::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (2, 16) + (2, 13) } - pub(crate) fn __reduce34< + pub(crate) fn __reduce31< 'input, 's, >( @@ -1427,9 +1396,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 __reduce33< 'input, 's, >( @@ -1440,12 +1409,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,98 +1443,114 @@ 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, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 1 - 21, 0, 22, 2, 0, 4, 5, 6, 0, 0, 23, 24, + 26, 0, 27, 2, 0, 4, 5, 6, 0, 0, 7, 28, 29, // State 2 - 21, 0, 22, 2, 27, 0, 0, 0, 0, 0, 23, 24, + 26, 0, 27, 2, 32, 0, 0, 0, 0, 0, 0, 28, 29, // State 3 - 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 4 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 5 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 29, // State 6 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 7 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 8 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 9 - 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 24, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 10 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 29, // State 11 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 12 - 21, 0, 22, 2, -18, 0, 0, 0, 0, 0, 23, 24, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 13 - 21, 0, 22, 2, -19, 0, 0, 0, 0, 0, 23, 24, + 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 29, // State 14 - 21, 0, 22, 2, -18, 0, 0, 0, 0, 0, 23, 24, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 15 - -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 16 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + 26, 0, 27, 2, -32, 0, 0, 0, 0, 0, 0, 28, 29, // State 17 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 29, // State 18 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 20 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, 0, -14, -14, // State 21 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, 0, -29, -29, // State 22 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, 0, -13, -13, // State 23 - -20, 0, -20, -20, -20, 0, 0, 0, 0, 0, -20, -20, + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, 0, -12, -12, // State 24 - -33, 0, -33, -33, -33, 0, 0, 0, 0, 0, -33, -33, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 25 - -34, 0, -34, -34, -34, 0, 0, 0, 0, 0, -34, -34, + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, 0, -3, -3, // State 26 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, 0, -2, -2, // State 27 - 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, 0, -15, -15, // State 28 - 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, -23, + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, 0, -16, -16, // State 29 - 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, -30, -30, // State 30 - 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, + -31, 0, -31, -31, -31, 0, 0, 0, 0, 0, 0, -31, -31, // State 31 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, 0, -21, -21, // State 32 - 0, 0, 0, 0, -24, 0, 0, 0, 0, 0, 0, -24, + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, 0, -19, // State 33 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, + 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, // State 34 - 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, // State 35 - 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, // State 36 - 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, 0, -20, // State 37 - -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, + 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, // State 38 - -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, + 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, // State 39 - 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, 0, -22, -22, // State 40 - -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 0, + // State 41 + 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, + // State 42 + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, 0, -26, -26, + // State 43 + -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, 0, -28, -28, + // State 44 + 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, + // State 45 + -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, 0, -25, -25, + // State 46 + -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, 0, -27, -27, + // State 47 + 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, + // State 48 + -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, 0, -23, -23, + // State 49 + -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, 0, -24, -24, ]; fn __action(state: i8, integer: usize) -> i8 { - __ACTION[(state as usize) * 12 + integer] + __ACTION[(state as usize) * 13 + integer] } const __EOF_ACTION: &[i8] = &[ // State 0 @@ -1599,43 +1584,43 @@ mod __parse__Tree { // State 14 0, // State 15 - -14, + 0, // State 16 - -30, + 0, // State 17 - -13, + 0, // State 18 - -12, + 0, // State 19 - -37, + 0, // State 20 - -3, + -14, // State 21 - -2, + -29, // State 22 - -15, + -13, // State 23 - -20, + -12, // State 24 - 0, + -34, // State 25 - 0, + -3, // State 26 - -25, + -2, // State 27 - 0, + -15, // State 28 - 0, + -16, // State 29 0, // State 30 0, // State 31 - 0, + -21, // State 32 0, // State 33 - -26, + 0, // State 34 0, // State 35 @@ -1643,49 +1628,72 @@ mod __parse__Tree { // State 36 0, // State 37 - -28, - // State 38 - -29, - // State 39 0, + // State 38 + 0, + // State 39 + -22, // State 40 + 0, + // State 41 + 0, + // State 42 + -26, + // State 43 + -28, + // State 44 + 0, + // State 45 + -25, + // State 46 -27, + // State 47 + 0, + // State 48 + -23, + // State 49 + -24, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 0 => 29, - 1 => 15, - 2 => 30, - 7 => 16, - 8 => 17, - 9 => match state { - 10 => 34, - _ => 27, + 0 => match state { + 12 => 38, + _ => 33, }, - 10 => match state { - 14 => 39, - _ => 36, + 1 => 20, + 2 => 34, + 7 => 21, + 8 => 22, + 9 => match state { + 3 => 7, + 6 => 12, + 8 => 13, + 5 | 13 => 32, + 10 | 17 => 36, + _ => 23, }, 11 => match state { - 3 => 6, - 7 => 10, - 5 | 10 => 28, - 9 => 32, - _ => 18, + 13 => 17, + _ => 10, }, - 13 => 9, - 14 => match state { - 4 => 8, - 8 => 11, - 0 => 19, - 2 | 13 => 25, - 6 => 31, - 11 => 35, - _ => 24, + 12 => match state { + 4 => 9, + 9 => 14, + 0 => 24, + 2 | 16 => 30, + 7 | 12 => 35, + 14 => 40, + _ => 29, }, - 16 => match state { + 13 => match state { 1 => 2, - _ => 13, + _ => 16, + }, + 14 => match state { + 15 => 41, + 18 => 44, + 19 => 47, + _ => 37, }, _ => 0, } @@ -1702,6 +1710,7 @@ mod __parse__Tree { r###""lambda (""###, r###""r7rs""###, r###""scheme""###, + r###""set!""###, r###"r#"[0-9]+(\\.[0-9]+)?"#"###, r###"r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"#"###, ]; @@ -1756,7 +1765,7 @@ mod __parse__Tree { #[inline] fn error_action(&self, state: i8) -> i8 { - __action(state, 12 - 1) + __action(state, 13 - 1) } #[inline] @@ -1830,8 +1839,9 @@ mod __parse__Tree { Token(9, _) if true => Some(7), Token(10, _) if true => Some(8), Token(11, _) if true => Some(9), - Token(0, _) if true => Some(10), - Token(1, _) if true => Some(11), + Token(12, _) if true => Some(10), + Token(0, _) if true => Some(11), + Token(1, _) if true => Some(12), _ => None, } } @@ -1845,8 +1855,8 @@ mod __parse__Tree { ) -> __Symbol<'input> { match __token_index { - 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 => match __token { - Token(2, __tok0) | Token(3, __tok0) | Token(4, __tok0) | Token(5, __tok0) | Token(6, __tok0) | Token(7, __tok0) | Token(8, __tok0) | Token(9, __tok0) | Token(10, __tok0) | Token(11, __tok0) | Token(0, __tok0) | Token(1, __tok0) if true => __Symbol::Variant0(__tok0), + 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 => match __token { + Token(2, __tok0) | Token(3, __tok0) | Token(4, __tok0) | Token(5, __tok0) | Token(6, __tok0) | Token(7, __tok0) | Token(8, __tok0) | Token(9, __tok0) | Token(10, __tok0) | Token(11, __tok0) | Token(12, __tok0) | Token(0, __tok0) | Token(1, __tok0) if true => __Symbol::Variant0(__tok0), _ => unreachable!(), }, _ => unreachable!(), @@ -1998,17 +2008,8 @@ mod __parse__Tree { __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 +2065,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() } } @@ -2180,11 +2159,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // BTree = Box => ActionFn(10); + // BTree = Box => ActionFn(11); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action10::<>(input, __sym0); + let __nt = super::__action11::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant1(__nt), __end)); (1, 0) } @@ -2198,11 +2177,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Bool = "#t" => ActionFn(16); + // Bool = "#t" => ActionFn(17); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action16::<>(input, __sym0); + let __nt = super::__action17::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant2(__nt), __end)); (1, 1) } @@ -2216,11 +2195,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Bool = "#f" => ActionFn(17); + // Bool = "#f" => ActionFn(18); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action17::<>(input, __sym0); + let __nt = super::__action18::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant2(__nt), __end)); (1, 1) } @@ -2234,11 +2213,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Box = Tree => ActionFn(21); - let __sym0 = __pop_Variant12(__symbols); + // Box = Tree => ActionFn(22); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action21::<>(input, __sym0); + let __nt = super::__action22::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant1(__nt), __end)); (1, 2) } @@ -2252,13 +2231,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(34); + // File = Lang, Trees => ActionFn(31); 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::__action31::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -2272,11 +2251,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(35); + // File = Trees => ActionFn(32); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action35::<>(input, __sym0); + let __nt = super::__action32::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -2290,13 +2269,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Lang = "#lang", LangName => ActionFn(18); + // Lang = "#lang", LangName => ActionFn(19); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action18::<>(input, __sym0, __sym1); + let __nt = super::__action19::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (2, 4) } @@ -2310,11 +2289,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Lang? = Lang => ActionFn(26); + // Lang? = Lang => ActionFn(27); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action26::<>(input, __sym0); + let __nt = super::__action27::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (1, 5) } @@ -2328,10 +2307,10 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Lang? = => ActionFn(27); + // Lang? = => 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::__action27::<>(input, &__start, &__end); + let __nt = super::__action28::<>(input, &__start, &__end); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (0, 5) } @@ -2345,11 +2324,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // LangName = "scheme" => ActionFn(19); + // LangName = "scheme" => ActionFn(20); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action19::<>(input, __sym0); + let __nt = super::__action20::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant0(__nt), __end)); (1, 6) } @@ -2363,11 +2342,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // LangName = "r7rs" => ActionFn(20); + // LangName = "r7rs" => ActionFn(21); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action20::<>(input, __sym0); + let __nt = super::__action21::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant0(__nt), __end)); (1, 6) } @@ -2381,11 +2360,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Sym => ActionFn(11); - let __sym0 = __pop_Variant10(__symbols); + // Literal = Sym => ActionFn(12); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action11::<>(input, __sym0); + let __nt = super::__action12::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 7) } @@ -2399,11 +2378,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Num => ActionFn(12); + // Literal = Num => ActionFn(13); let __sym0 = __pop_Variant7(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action12::<>(input, __sym0); + let __nt = super::__action13::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 7) } @@ -2417,11 +2396,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Bool => ActionFn(13); + // Literal = Bool => ActionFn(14); let __sym0 = __pop_Variant2(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action13::<>(input, __sym0); + let __nt = super::__action14::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 7) } @@ -2435,11 +2414,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Num = r#"[0-9]+(\\.[0-9]+)?"# => ActionFn(15); + // Num = r#"[0-9]+(\\.[0-9]+)?"# => ActionFn(16); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action15::<>(input, __sym0); + let __nt = super::__action16::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (1, 8) } @@ -2453,12 +2432,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(15); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action15::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (0, 9) + (1, 9) } pub(crate) fn __reduce16< 'input, @@ -2470,13 +2450,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(23); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action23::<>(input, &__start, &__end); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (0, 10) } pub(crate) fn __reduce17< 'input, @@ -2488,12 +2467,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(24); + let __sym0 = __pop_Variant9(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (0, 10) + (1, 10) } pub(crate) fn __reduce18< 'input, @@ -2505,13 +2485,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Tree+ => ActionFn(39); - let __sym0 = __pop_Variant3(__symbols); + // Sym+ = Sym => ActionFn(29); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, __sym0); + let __nt = super::__action29::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + (1, 11) } pub(crate) fn __reduce19< 'input, @@ -2523,88 +2503,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(30); 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::__action30::<>(input, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (2, 11) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce20< 'input, 's, >( @@ -2622,10 +2531,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 +2548,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 +2567,48 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, RcSlice, ")", RcSlice, ")" => ActionFn(6); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(33); + 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::__action33::<>(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(34); 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::__action34::<>(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,16 +2621,86 @@ 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 __reduce25< + '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 (", ")", Trees, ")" => ActionFn(35); + 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::__action35::<>(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(36); + assert!(__symbols.len() >= 6); + let __sym5 = __pop_Variant0(__symbols); + let __sym4 = __pop_Variant3(__symbols); + let __sym3 = __pop_Variant0(__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::__action36::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) + } + pub(crate) fn __reduce27< + '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 = "(", "set!", Sym, BTree, ")" => ActionFn(9); + assert!(__symbols.len() >= 5); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant1(__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::__action9::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) } pub(crate) fn __reduce28< 'input, @@ -2708,19 +2712,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", RcSlice, ")", RcSlice, ")" => ActionFn(8); - assert!(__symbols.len() >= 6); - let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant9(__symbols); - let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); - let __sym1 = __pop_Variant0(__symbols); - let __sym0 = __pop_Variant0(__symbols); + // Tree = Literal => ActionFn(10); + let __sym0 = __pop_Variant6(__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 __end = __sym0.2.clone(); + let __nt = super::__action10::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } pub(crate) fn __reduce29< 'input, @@ -2732,13 +2730,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = Literal => ActionFn(9); - let __sym0 = __pop_Variant6(__symbols); + // Tree+ = Tree => ActionFn(25); + let __sym0 = __pop_Variant10(__symbols); 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) + let __nt = super::__action25::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant3(__nt), __end)); + (1, 13) } pub(crate) fn __reduce30< 'input, @@ -2750,70 +2748,17 @@ mod __parse__Tree { _: 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< - '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(24); - let __sym0 = __pop_Variant12(__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) - } - pub(crate) fn __reduce33< - '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+, Tree => ActionFn(25); + // Tree+ = Tree+, Tree => ActionFn(26); 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); + let __nt = super::__action26::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (2, 16) + (2, 13) } - pub(crate) fn __reduce34< + pub(crate) fn __reduce31< 'input, 's, >( @@ -2829,9 +2774,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 __reduce32< 'input, 's, >( @@ -2847,7 +2792,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; @@ -2876,6 +2821,7 @@ mod __intern_token { ("^(lambda \\()", false), ("^(r7rs)", false), ("^(scheme)", false), + ("^(set!)", false), ("^(;[\u{0}-\t\u{b}-\u{c}\u{e}-\u{10ffff}]*[\n\r]*)", true), ("^([\t-\r \u{85}\u{a0}\u{1680}\u{2000}-\u{200a}\u{2028}-\u{2029}\u{202f}\u{205f}\u{3000}]*)", true), ]; @@ -2885,74 +2831,108 @@ mod __intern_token { pub(crate) use self::__lalrpop_util::lexer::Token; #[allow(unused_variables)] -fn __action0<'input, 's>( +fn __action0< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ __0 } #[allow(unused_variables)] -fn __action1<'input, 's>(input: &'input str, (_, __0, _): (usize, Tree, usize)) -> Tree { +fn __action1< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, Tree, usize), +) -> Tree +{ __0 } #[allow(unused_variables)] -fn __action2<'input, 's>( +fn __action2< + 'input, + 's, +>( input: &'input str, (_, _, _): (usize, core::option::Option<()>, usize), (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ __0 } #[allow(unused_variables)] -fn __action3<'input, 's>( +fn __action3< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ __0 } #[allow(unused_variables)] -fn __action4<'input, 's>( +fn __action4< + 'input, + 's, +>( input: &'input str, (_, _, _): (usize, &'input str, usize), (_, __0, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), -) -> Tree { +) -> Tree +{ Tree::Branch(__0) } #[allow(unused_variables)] -fn __action5<'input, 's>( +fn __action5< + 'input, + 's, +>( input: &'input str, (_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize), (_, __0, _): (usize, String, usize), (_, __1, _): (usize, Box, usize), (_, _, _): (usize, &'input str, usize), -) -> Tree { +) -> Tree +{ Tree::Define(__0, __1) } #[allow(unused_variables)] -fn __action6<'input, 's>( +fn __action6< + 'input, + 's, +>( input: &'input str, (_, _, _): (usize, &'input str, usize), (_, _, _): (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 +{ + Tree::Define(name, Box::new(Tree::Func(Rc::new(Func{args, body})))) } #[allow(unused_variables)] -fn __action7<'input, 's>( +fn __action7< + 'input, + 's, +>( input: &'input str, (_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize), @@ -2960,308 +2940,496 @@ fn __action7<'input, 's>( (_, __1, _): (usize, Tree, usize), (_, __2, _): (usize, Tree, usize), (_, _, _): (usize, &'input str, usize), -) -> Tree { +) -> Tree +{ Tree::If(Box::new([__0, __1, __2])) } #[allow(unused_variables)] -fn __action8<'input, 's>( +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 +{ + Tree::Func(Rc::new(Func{args:args, body:body})) } #[allow(unused_variables)] -fn __action9<'input, 's>(input: &'input str, (_, __0, _): (usize, Literal, usize)) -> Tree { +fn __action9< + 'input, + 's, +>( + input: &'input str, + (_, _, _): (usize, &'input str, usize), + (_, _, _): (usize, &'input str, usize), + (_, __0, _): (usize, String, usize), + (_, __1, _): (usize, Box, usize), + (_, _, _): (usize, &'input str, usize), +) -> Tree +{ + Tree::Set(__0, __1) +} + +#[allow(unused_variables)] +fn __action10< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, Literal, usize), +) -> Tree +{ Tree::Leaf(__0) } #[allow(unused_variables)] -fn __action10<'input, 's>(input: &'input str, (_, __0, _): (usize, Box, usize)) -> Box { +fn __action11< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, Box, usize), +) -> Box +{ __0 } #[allow(unused_variables)] -fn __action11<'input, 's>(input: &'input str, (_, __0, _): (usize, String, usize)) -> Literal { +fn __action12< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, String, usize), +) -> Literal +{ Literal::Sym(__0) } #[allow(unused_variables)] -fn __action12<'input, 's>(input: &'input str, (_, __0, _): (usize, f64, usize)) -> Literal { +fn __action13< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, f64, usize), +) -> Literal +{ Literal::Num(__0) } #[allow(unused_variables)] -fn __action13<'input, 's>(input: &'input str, (_, __0, _): (usize, bool, usize)) -> Literal { +fn __action14< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, bool, usize), +) -> Literal +{ Literal::Bool(__0) } #[allow(unused_variables)] -fn __action14<'input, 's>(input: &'input str, (_, __0, _): (usize, &'input str, usize)) -> String { +fn __action15< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> String +{ __0.to_owned() } #[allow(unused_variables)] -fn __action15<'input, 's>(input: &'input str, (_, __0, _): (usize, &'input str, usize)) -> f64 { +fn __action16< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> f64 +{ __0.parse().unwrap() } #[allow(unused_variables)] -fn __action16<'input, 's>(input: &'input str, (_, __0, _): (usize, &'input str, usize)) -> bool { +fn __action17< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> bool +{ true } #[allow(unused_variables)] -fn __action17<'input, 's>(input: &'input str, (_, __0, _): (usize, &'input str, usize)) -> bool { +fn __action18< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> bool +{ false } #[allow(unused_variables)] -fn __action18<'input, 's>( +fn __action19< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, &'input str, usize), (_, __1, _): (usize, &'input str, usize), -) -> () { +) -> () +{ () } #[allow(unused_variables)] -fn __action19<'input, 's>( +fn __action20< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, &'input str, usize), -) -> &'input str { +) -> &'input str +{ __0 } #[allow(unused_variables)] -fn __action20<'input, 's>( +fn __action21< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, &'input str, usize), -) -> &'input str { +) -> &'input str +{ __0 } #[allow(unused_variables)] -fn __action21<'input, 's>(input: &'input str, (_, __0, _): (usize, Tree, usize)) -> Box { +fn __action22< + 'input, + 's, +>( + input: &'input str, + (_, __0, _): (usize, Tree, usize), +) -> Box +{ Box::new(__0) } #[allow(unused_variables)] -fn __action22<'input, 's>( +fn __action23< + '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>( +fn __action24< + '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)] -fn __action24<'input, 's>( +fn __action25< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, Tree, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ alloc::vec![__0] } #[allow(unused_variables)] -fn __action25<'input, 's>( +fn __action26< + 'input, + 's, +>( input: &'input str, (_, v, _): (usize, alloc::vec::Vec, usize), (_, e, _): (usize, Tree, usize), -) -> alloc::vec::Vec { - { - let mut v = v; - v.push(e); - v - } +) -> alloc::vec::Vec +{ + { let mut v = v; v.push(e); v } } #[allow(unused_variables)] -fn __action26<'input, 's>( +fn __action27< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, (), usize), -) -> core::option::Option<()> { +) -> core::option::Option<()> +{ Some(__0) } #[allow(unused_variables)] -fn __action27<'input, 's>( +fn __action28< + 'input, + 's, +>( input: &'input str, __lookbehind: &usize, __lookahead: &usize, -) -> core::option::Option<()> { +) -> core::option::Option<()> +{ None } #[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>( +fn __action29< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, String, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ alloc::vec![__0] } #[allow(unused_variables)] -fn __action33<'input, 's>( +fn __action30< + 'input, + 's, +>( input: &'input str, (_, v, _): (usize, alloc::vec::Vec, usize), (_, e, _): (usize, String, usize), -) -> alloc::vec::Vec { - { - let mut v = v; - v.push(e); - v - } +) -> alloc::vec::Vec +{ + { let mut v = v; v.push(e); v } } #[allow(unused_variables)] -fn __action34<'input, 's>( +fn __action31< + 'input, + 's, +>( input: &'input str, __0: (usize, (), usize), __1: (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ let __start0 = __0.0.clone(); let __end0 = __0.2.clone(); - let __temp0 = __action26(input, __0); + let __temp0 = __action27( + input, + __0, + ); let __temp0 = (__start0, __temp0, __end0); - __action2(input, __temp0, __1) + __action2( + input, + __temp0, + __1, + ) } #[allow(unused_variables)] -fn __action35<'input, 's>( +fn __action32< + 'input, + 's, +>( input: &'input str, __0: (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ let __start0 = __0.0.clone(); let __end0 = __0.0.clone(); - let __temp0 = __action27(input, &__start0, &__end0); + let __temp0 = __action28( + input, + &__start0, + &__end0, + ); let __temp0 = (__start0, __temp0, __end0); - __action2(input, __temp0, __0) + __action2( + input, + __temp0, + __0, + ) } #[allow(unused_variables)] -fn __action36<'input, 's>( +fn __action33< + '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 = __action23( + 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 __action34< + '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 = __action24( + 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 __action35< + '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 = __action23( + 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 __action36< + '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 = __action24( + input, + __2, + ); let __temp0 = (__start0, __temp0, __end0); - __action22(input, __temp0) + __action8( + input, + __0, + __1, + __temp0, + __3, + __4, + __5, + ) } -pub trait __ToTriple<'input, 's> { - fn to_triple( - value: Self, - ) -> Result< - (usize, Token<'input>, usize), - __lalrpop_util::ParseError, &'static str>, - >; +pub trait __ToTriple<'input, 's, > { + fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize), __lalrpop_util::ParseError, &'static str>>; } -impl<'input, 's> __ToTriple<'input, 's> for (usize, Token<'input>, usize) { - fn to_triple( - value: Self, - ) -> Result< - (usize, Token<'input>, usize), - __lalrpop_util::ParseError, &'static str>, - > { +impl<'input, 's, > __ToTriple<'input, 's, > for (usize, Token<'input>, usize) { + fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize), __lalrpop_util::ParseError, &'static str>> { Ok(value) } } -impl<'input, 's> __ToTriple<'input, 's> for Result<(usize, Token<'input>, usize), &'static str> { - fn to_triple( - value: Self, - ) -> Result< - (usize, Token<'input>, usize), - __lalrpop_util::ParseError, &'static str>, - > { +impl<'input, 's, > __ToTriple<'input, 's, > for Result<(usize, Token<'input>, usize), &'static str> { + fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize), __lalrpop_util::ParseError, &'static str>> { match value { Ok(v) => Ok(v), Err(error) => Err(__lalrpop_util::ParseError::User { error }), 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@4-1-6-Assignments.scm.snap b/src/snapshots/handball__tests__run-pass@4-1-6-Assignments.scm.snap new file mode 100644 index 0000000..d8a09b3 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@4-1-6-Assignments.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass r7rs-spec\\4-1-6-Assignments.scm" + +--- +3.05.0 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@assign-closures.scm.snap b/src/snapshots/handball__tests__run-pass@assign-closures.scm.snap new file mode 100644 index 0000000..4aa09ff --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@assign-closures.scm.snap @@ -0,0 +1,11 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\assign-closures.scm" + +--- +1.0 +2.0 +2.0 +3.0 + diff --git a/src/snapshots/handball__tests__run-pass@assign-shadowed-later.scm.snap b/src/snapshots/handball__tests__run-pass@assign-shadowed-later.scm.snap new file mode 100644 index 0000000..a1e7c91 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@assign-shadowed-later.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\assign-shadowed-later.scm" + +--- +1.0 +0.0 + diff --git a/src/snapshots/handball__tests__run-pass@bagel-donut.scm.snap b/src/snapshots/handball__tests__run-pass@bagel-donut.scm.snap new file mode 100644 index 0000000..93d1fbe --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@bagel-donut.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\bagel-donut.scm" + +--- +4.0 +2.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@close-over-function-param.scm.snap b/src/snapshots/handball__tests__run-pass@close-over-function-param.scm.snap new file mode 100644 index 0000000..050e695 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@close-over-function-param.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\close-over-function-param.scm" + +--- +77.0 diff --git a/src/snapshots/handball__tests__run-pass@close-over-later-variable.scm.snap b/src/snapshots/handball__tests__run-pass@close-over-later-variable.scm.snap new file mode 100644 index 0000000..49ff729 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@close-over-later-variable.scm.snap @@ -0,0 +1,8 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\close-over-later-variable.scm" + +--- +2.0 +1.0 diff --git a/src/snapshots/handball__tests__run-pass@close-unused.scm.snap b/src/snapshots/handball__tests__run-pass@close-unused.scm.snap new file mode 100644 index 0000000..8c5eeb6 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@close-unused.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\close-unused.scm" + +--- +7.0 diff --git a/src/snapshots/handball__tests__run-pass@closed-closure-in-function.scm.snap b/src/snapshots/handball__tests__run-pass@closed-closure-in-function.scm.snap new file mode 100644 index 0000000..9743e0c --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@closed-closure-in-function.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\closed-closure-in-function.scm" + +--- +1.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/snapshots/handball__tests__run-pass@gnarly-i.scm.snap b/src/snapshots/handball__tests__run-pass@gnarly-i.scm.snap new file mode 100644 index 0000000..1b7b569 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@gnarly-i.scm.snap @@ -0,0 +1,10 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\gnarly-i.scm" + +--- +3.0 +2.0 +1.0 + diff --git a/src/snapshots/handball__tests__run-pass@mutate-levels.scm.snap b/src/snapshots/handball__tests__run-pass@mutate-levels.scm.snap new file mode 100644 index 0000000..6853d0e --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@mutate-levels.scm.snap @@ -0,0 +1,13 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\mutate-levels.scm" + +--- +2.0 +3.0 +3.0 +3.0 +7.0 +8.0 + diff --git a/src/snapshots/handball__tests__run-pass@nested-assign.scm.snap b/src/snapshots/handball__tests__run-pass@nested-assign.scm.snap new file mode 100644 index 0000000..744868e --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@nested-assign.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\nested-assign.scm" + +--- +1.0 diff --git a/src/snapshots/handball__tests__run-pass@nested-closure.scm.snap b/src/snapshots/handball__tests__run-pass@nested-closure.scm.snap new file mode 100644 index 0000000..744940e --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@nested-closure.scm.snap @@ -0,0 +1,10 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\nested-closure.scm" + +--- +1.0 +2.0 +3.0 + diff --git a/src/snapshots/handball__tests__run-pass@objects-are-a-poor-mans-closure.scm.snap b/src/snapshots/handball__tests__run-pass@objects-are-a-poor-mans-closure.scm.snap new file mode 100644 index 0000000..e290ade --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@objects-are-a-poor-mans-closure.scm.snap @@ -0,0 +1,20 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\objects-are-a-poor-mans-closure.scm" + +--- +1.0 +7.0 +1.0 +7.0 + +8.0 +2.0 +8.0 +2.0 + +9.0 +9.0 + + diff --git a/src/snapshots/handball__tests__run-pass@open-closure-in-function.scm.snap b/src/snapshots/handball__tests__run-pass@open-closure-in-function.scm.snap new file mode 100644 index 0000000..6c929d9 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@open-closure-in-function.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\open-closure-in-function.scm" + +--- +1.0 diff --git a/src/snapshots/handball__tests__run-pass@reference-closure-multiple-times.scm.snap b/src/snapshots/handball__tests__run-pass@reference-closure-multiple-times.scm.snap new file mode 100644 index 0000000..a7095a5 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@reference-closure-multiple-times.scm.snap @@ -0,0 +1,8 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\reference-closure-multiple-times.scm" + +--- +1.0 +1.0 diff --git a/src/snapshots/handball__tests__run-pass@reuse-closure-slot.scm.snap b/src/snapshots/handball__tests__run-pass@reuse-closure-slot.scm.snap new file mode 100644 index 0000000..f3b7b5a --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@reuse-closure-slot.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\reuse-closure-slot.scm" + +--- +1.0 diff --git a/src/snapshots/handball__tests__run-pass@scope.scm.snap b/src/snapshots/handball__tests__run-pass@scope.scm.snap new file mode 100644 index 0000000..2474233 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@scope.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\scope.scm" + +--- +7.0 +2.0 + diff --git a/src/snapshots/handball__tests__run-pass@shadow-closure-with-local.scm.snap b/src/snapshots/handball__tests__run-pass@shadow-closure-with-local.scm.snap new file mode 100644 index 0000000..7ed2745 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@shadow-closure-with-local.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\shadow-closure-with-local.scm" + +--- +0.0 +1.0 + diff --git a/src/snapshots/handball__tests__run-pass@unused-later-closures.scm.snap b/src/snapshots/handball__tests__run-pass@unused-later-closures.scm.snap new file mode 100644 index 0000000..82b2efb --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@unused-later-closures.scm.snap @@ -0,0 +1,8 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\unused-later-closures.scm" + +--- +1.0 +1.0 diff --git a/src/snapshots/handball__tests__run-pass@use-after-close.scm.snap b/src/snapshots/handball__tests__run-pass@use-after-close.scm.snap new file mode 100644 index 0000000..5641625 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@use-after-close.scm.snap @@ -0,0 +1,7 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\use-after-close.scm" + +--- +1.0 diff --git a/src/snapshots/handball__tests__run-pass@val-or-var.scm.snap b/src/snapshots/handball__tests__run-pass@val-or-var.scm.snap new file mode 100644 index 0000000..bb679ec --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@val-or-var.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: "run-pass closure\\val-or-var.scm" + +--- +0.0 +1.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..57a27ff --- /dev/null +++ b/src/test/run-pass/ambig-scope.scm @@ -0,0 +1,22 @@ +#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) diff --git a/src/test/run-pass/capture.scm b/src/test/run-pass/capture.scm new file mode 100644 index 0000000..83898ef --- /dev/null +++ b/src/test/run-pass/capture.scm @@ -0,0 +1,13 @@ +#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/closure/assign-closures.scm b/src/test/run-pass/closure/assign-closures.scm new file mode 100644 index 0000000..69895e4 --- /dev/null +++ b/src/test/run-pass/closure/assign-closures.scm @@ -0,0 +1,28 @@ +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/assign_to_closure.lox + +(define f #f) +(define g #f) + +(define (displayln x) + (display x) + (newline)) + +((lambda () + (define local 1) + + (define (f_) + (displayln local) + (set! local 2) + (displayln local)) + + (set! f f_) + + (define (g_) + (displayln local) + (set! local 3) + (displayln local)) + + (set! g g_))) + +(f) +(g) diff --git a/src/test/run-pass/closure/assign-shadowed-later.scm b/src/test/run-pass/closure/assign-shadowed-later.scm new file mode 100644 index 0000000..5a4275c --- /dev/null +++ b/src/test/run-pass/closure/assign-shadowed-later.scm @@ -0,0 +1,17 @@ +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/assign_to_shadowed_later.lox + +(define a 0) + +(define (displayln x) + (display x) + (newline)) + +((lambda () + (define (assign) + (set! a 1)) + + (define a 2) + (assign) + (displayln a))) + +(displayln a) diff --git a/src/test/run-pass/closure/bagel-donut.scm b/src/test/run-pass/closure/bagel-donut.scm new file mode 100644 index 0000000..ac06159 --- /dev/null +++ b/src/test/run-pass/closure/bagel-donut.scm @@ -0,0 +1,14 @@ +(define (displayln x) + (display x) + (newline)) + +(define (make-print x) + (define (print) + (displayln x)) + print) + +(define print-2 (make-print 2)) +(define print-4 (make-print 4)) + +(print-4) +(print-2) diff --git a/src/test/run-pass/closure/close-over-function-param.scm b/src/test/run-pass/closure/close-over-function-param.scm new file mode 100644 index 0000000..df024aa --- /dev/null +++ b/src/test/run-pass/closure/close-over-function-param.scm @@ -0,0 +1,10 @@ +(define f #f) + +(define (foo param) + (define (f_) + (display param)) + (set! f f_)) + +(foo 77) + +(f) diff --git a/src/test/run-pass/closure/close-over-later-variable.scm b/src/test/run-pass/closure/close-over-later-variable.scm new file mode 100644 index 0000000..9a1a978 --- /dev/null +++ b/src/test/run-pass/closure/close-over-later-variable.scm @@ -0,0 +1,14 @@ +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/close_over_later_variable.lox + +(define (f) + (define a 1) + (define b 2) + + (define (g) + (display b) + (newline) + (display a)) + + (g)) + +(f) diff --git a/src/test/run-pass/closure/close-unused.scm b/src/test/run-pass/closure/close-unused.scm new file mode 100644 index 0000000..ab70eb0 --- /dev/null +++ b/src/test/run-pass/closure/close-unused.scm @@ -0,0 +1,6 @@ +((lambda () + (define a 1) + + (if #f (lambda () a) 0))) + +(display 7) diff --git a/src/test/run-pass/closure/closed-closure-in-function.scm b/src/test/run-pass/closure/closed-closure-in-function.scm new file mode 100644 index 0000000..11d8dd0 --- /dev/null +++ b/src/test/run-pass/closure/closed-closure-in-function.scm @@ -0,0 +1,11 @@ +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/closed_closure_in_function.lox + +(define f #f) + +((lambda () + (define local 1) + (define (f_) + (display local)) + (set! f f_))) + +(f) diff --git a/src/test/run-pass/closure/gnarly-i.scm b/src/test/run-pass/closure/gnarly-i.scm new file mode 100644 index 0000000..6190093 --- /dev/null +++ b/src/test/run-pass/closure/gnarly-i.scm @@ -0,0 +1,22 @@ +#lang scheme + +(define (displayln x) + (display x) + (newline)) + +(define (outer) + (define x 1) + + (define (middle) + (define (inner) + (displayln x)) + (displayln 2) + inner) + + (displayln 3) + + middle) + +(define mid (outer)) +(define in (mid)) +(in) diff --git a/src/test/run-pass/closure/mutate-levels.scm b/src/test/run-pass/closure/mutate-levels.scm new file mode 100644 index 0000000..61f7d3d --- /dev/null +++ b/src/test/run-pass/closure/mutate-levels.scm @@ -0,0 +1,24 @@ +(define x 2) + +(define (show-x) + (display x) + (newline)) + +(show-x) +(set! x 3) +(show-x) + +((lambda () + (define x 7) + (show-x) + (set! x 8) + (show-x))) + +((lambda () + (define (show-x) + (display x) + (newline)) + (define x 7) + (show-x) + (set! x 8) + (show-x))) diff --git a/src/test/run-pass/closure/nested-assign.scm b/src/test/run-pass/closure/nested-assign.scm new file mode 100644 index 0000000..5bd5b1e --- /dev/null +++ b/src/test/run-pass/closure/nested-assign.scm @@ -0,0 +1,8 @@ +(define (outer) + (define x 0) + (define (y) + (set! x 1)) + (y) + (display x)) + +(outer) diff --git a/src/test/run-pass/closure/nested-closure.scm b/src/test/run-pass/closure/nested-closure.scm new file mode 100644 index 0000000..9e84874 --- /dev/null +++ b/src/test/run-pass/closure/nested-closure.scm @@ -0,0 +1,26 @@ +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/nested_closure.lox +#lang scheme + +(define (displayln x) + (display x) + (newline)) + +(define f #f) + +(define (f1) + (define a 1) + (define (f2) + (define b 2) + (define (f3) + (define c 3) + (define (f4) + (displayln a) + (displayln b) + (displayln c)) + (set! f f4)) + (f3)) + (f2)) + +(f1) + +(f) diff --git a/src/test/run-pass/closure/objects-are-a-poor-mans-closure.scm b/src/test/run-pass/closure/objects-are-a-poor-mans-closure.scm new file mode 100644 index 0000000..0a00e31 --- /dev/null +++ b/src/test/run-pass/closure/objects-are-a-poor-mans-closure.scm @@ -0,0 +1,43 @@ +#lang scheme + +(define get-x 1) +(define get-y 2) +(define do-print 3) +(define add 4) + +(define (displayln x) + (display x) + (newline)) + +(define (vector x y) + (define (add-to other) + (vector (+ x (other get-x)) (+ y (other get-y)))) + + (lambda (message) + (if (= message get-x) + x + (if (= message get-y) + y + (if (= message add) + add-to + (if (= message do-print) + ((lambda () + (displayln x) + (displayln y) + (newline))) + ((lambda () + (displayln -99) + 0)))))))) + +(define v-1-7 (vector 1 7)) +(displayln (v-1-7 get-x)) +(displayln (v-1-7 get-y)) +(v-1-7 do-print) + +(define v-8-2 (vector 8 2)) +(displayln (v-8-2 get-x)) +(displayln (v-8-2 get-y)) +(v-8-2 do-print) + +(define v-9-9 ((v-8-2 add) v-1-7)) +(v-9-9 do-print) diff --git a/src/test/run-pass/closure/open-closure-in-function.scm b/src/test/run-pass/closure/open-closure-in-function.scm new file mode 100644 index 0000000..904424e --- /dev/null +++ b/src/test/run-pass/closure/open-closure-in-function.scm @@ -0,0 +1,9 @@ +#lang scheme + +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/open_closure_in_function.lox + +((lambda () + (define local 1) + (define (f) + (display local)) + (f))) diff --git a/src/test/run-pass/closure/reference-closure-multiple-times.scm b/src/test/run-pass/closure/reference-closure-multiple-times.scm new file mode 100644 index 0000000..71ce1d7 --- /dev/null +++ b/src/test/run-pass/closure/reference-closure-multiple-times.scm @@ -0,0 +1,14 @@ +#lang scheme +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/reference_closure_multiple_times.lox + +(define f #f) + +((lambda () + (define a 1) + (define (f_) + (display a) + (newline) + (display a)) + (set! f f_))) + +(f) diff --git a/src/test/run-pass/closure/reuse-closure-slot.scm b/src/test/run-pass/closure/reuse-closure-slot.scm new file mode 100644 index 0000000..d963162 --- /dev/null +++ b/src/test/run-pass/closure/reuse-closure-slot.scm @@ -0,0 +1,15 @@ +#lang scheme + +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/reuse_closure_slot.lox + +((lambda () + (define f #f) + ((lambda () + (define a 1) + (define (f_) + (display a)) + (set! f f_))) + + ((lambda () + (define b 2) + (f))))) diff --git a/src/test/run-pass/closure/scope.scm b/src/test/run-pass/closure/scope.scm new file mode 100644 index 0000000..7c636b8 --- /dev/null +++ b/src/test/run-pass/closure/scope.scm @@ -0,0 +1,13 @@ +(define x 2) + +(define (displayln x) + (display x) + (newline)) + +(define (gy y) + x) +(define (gx x) + x) + +(displayln (gx 7)) +(displayln (gy 7)) diff --git a/src/test/run-pass/closure/shadow-closure-with-local.scm b/src/test/run-pass/closure/shadow-closure-with-local.scm new file mode 100644 index 0000000..2d19f4e --- /dev/null +++ b/src/test/run-pass/closure/shadow-closure-with-local.scm @@ -0,0 +1,15 @@ +; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/shadow_closure_with_local.lox +; TODO: Forbid this https://discordapp.com/channels/571040468092321801/618895179343986688/925533402592079912 + +(define (displayln x) + (display x) + (newline)) + +((lambda () + (define foo 0) + (define (f) + ((lambda () + (displayln foo) + (define foo 1) + (displayln foo)))) + (f))) diff --git a/src/test/run-pass/closure/unused-later-closures.scm b/src/test/run-pass/closure/unused-later-closures.scm new file mode 100644 index 0000000..e556b15 --- /dev/null +++ b/src/test/run-pass/closure/unused-later-closures.scm @@ -0,0 +1,19 @@ +(define closure #f) + +((lambda () + (define a 1) + + ((lambda () + (define b 2) + + (define (get-a) + a) + + (set! closure get-a) + + (if #f (lambda () b) 0))) + + (display (closure)))) + +(newline) +(display (closure)) diff --git a/src/test/run-pass/closure/use-after-close.scm b/src/test/run-pass/closure/use-after-close.scm new file mode 100644 index 0000000..355c468 --- /dev/null +++ b/src/test/run-pass/closure/use-after-close.scm @@ -0,0 +1,8 @@ +(define (outer) + (define x 1) + (define (inner) + (display x)) + inner) + +(define clousre (outer)) +(clousre) diff --git a/src/test/run-pass/closure/val-or-var.scm b/src/test/run-pass/closure/val-or-var.scm new file mode 100644 index 0000000..2404e4d --- /dev/null +++ b/src/test/run-pass/closure/val-or-var.scm @@ -0,0 +1,19 @@ +(define globalSet #f) +(define globalGet #f) + +(define (main) + (define a 0) + + (define (set) + (set! a 1)) + (define (get) + (display a) + (newline)) + + (set! globalSet set) + (set! globalGet get)) + +(main) +(globalGet) +(globalSet) +(globalGet) diff --git a/src/test/run-pass/curry.scm b/src/test/run-pass/curry.scm new file mode 100644 index 0000000..7fd510d --- /dev/null +++ b/src/test/run-pass/curry.scm @@ -0,0 +1,10 @@ +#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/test/run-pass/fib.scm b/src/test/run-pass/fib.scm index 92cbcab..6754aad 100644 --- a/src/test/run-pass/fib.scm +++ b/src/test/run-pass/fib.scm @@ -1,21 +1,28 @@ #lang scheme -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) -(define (my-or a b) (if a #t b)) ; Test was written before we had `or` +(define (my-or a b) + (if a #t b)) ; Test was written before we had `or` - -(define (fib-base? n) (my-or (= n 1) (= n 0))) +(define (fib-base? n) + (my-or (= n 1) (= n 0))) (define (fib n) - (if (fib-base? n) 1 - (+ (fib (- n 1)) (fib (- n 2))))) - + (if (fib-base? n) 1 (+ (fib (- n 1)) (fib (- n 2))))) -(define (pfib n) (displayln n) (displayln (fib n)) (newline)) +(define (pfib n) + (displayln n) + (displayln (fib n)) + (newline)) (define (pfibs n) - (if (= n (- 1)) 0 ; Hack - ((lambda () (pfib n) (pfibs (- n 1)))))) ; Hack + (if (= n (- 1)) + 0 ; Hack + ((lambda () + (pfib n) + (pfibs (- n 1)))))) ; Hack -(pfibs 10) \ No newline at end of file +(pfibs 10) diff --git a/src/test/run-pass/funcs.scm b/src/test/run-pass/funcs.scm index 58c1e2d..856fd88 100644 --- a/src/test/run-pass/funcs.scm +++ b/src/test/run-pass/funcs.scm @@ -1,6 +1,8 @@ #lang scheme -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) (define add1 +) (displayln (add1 2 3)) @@ -8,5 +10,6 @@ (define add2 (lambda (a b) (+ a b))) (displayln (add2 5 6)) -(define (add3 a b) (+ a b)) -(displayln (add3 5 9)) \ No newline at end of file +(define (add3 a b) + (+ a b)) +(displayln (add3 5 9)) diff --git a/src/test/run-pass/lambda-calc.scm b/src/test/run-pass/lambda-calc.scm index 5d3e56e..6da98f2 100644 --- a/src/test/run-pass/lambda-calc.scm +++ b/src/test/run-pass/lambda-calc.scm @@ -1,18 +1,24 @@ #lang scheme -(define (displayln x) (display x) (newline)) -(define (printbool x) (displayln (bool->int x))) +(define (displayln x) + (display x) + (newline)) +(define (printbool x) + (displayln (bool->int x))) -(define (true x y) x) -(define (false x y) y) -(define (and x y) (x y x)) -(define (or x y) (x x y)) -(define (not x) (x false true)) +(define (true x y) + x) +(define (false x y) + y) +(define (and x y) + (x y x)) +(define (or x y) + (x x y)) +(define (not x) + (x false true)) -(define (bool->int x) - (if - (equal? x true) 1 - (if (equal? x false) 0 (- 1)))) +(define (bool->int x) + (if (equal? x true) 1 (if (equal? x false) 0 (- 1)))) (printbool true) (printbool false) @@ -27,4 +33,4 @@ (printbool (or true false)) (printbool (or false true)) (printbool (or false false)) -(printbool (and (or true false) (or false true))) \ No newline at end of file +(printbool (and (or true false) (or false true))) diff --git a/src/test/run-pass/multi.scm b/src/test/run-pass/multi.scm index 6df5bff..3a5dc57 100644 --- a/src/test/run-pass/multi.scm +++ b/src/test/run-pass/multi.scm @@ -1,5 +1,8 @@ #lang scheme -(define (multi) 1 2 3) +(define (multi) + 1 + 2 + 3) -(display (multi)) \ No newline at end of file +(display (multi)) diff --git a/src/test/run-pass/nested-defs.scm b/src/test/run-pass/nested-defs.scm index 6d4265a..15c9eee 100644 --- a/src/test/run-pass/nested-defs.scm +++ b/src/test/run-pass/nested-defs.scm @@ -6,15 +6,14 @@ (define (sqrt x) (define (sqrt-iter guess x) (define (good-enough? guess x) - (define (square x) (* x x)) + (define (square x) + (* x x)) (< (abs (- (square guess) x)) 0.001)) (define (improve guess x) - (define (average x y) + (define (average x y) (/ (+ x y) 2)) (average guess (/ x guess))) - (if (good-enough? guess x) - guess - (sqrt-iter (improve guess x) x))) + (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x))) (sqrt-iter 1.0 x)) -(display (sqrt 2)) \ No newline at end of file +(display (sqrt 2)) diff --git a/src/test/run-pass/r7rs-spec/4-1-6-Assignments.scm b/src/test/run-pass/r7rs-spec/4-1-6-Assignments.scm new file mode 100644 index 0000000..1ba7aca --- /dev/null +++ b/src/test/run-pass/r7rs-spec/4-1-6-Assignments.scm @@ -0,0 +1,4 @@ +(define x 2) +(display (+ x 1)) +(set! x 4) +(display (+ x 1)) diff --git a/src/test/run-pass/sqrt.scm b/src/test/run-pass/sqrt.scm index 051ac15..5300635 100644 --- a/src/test/run-pass/sqrt.scm +++ b/src/test/run-pass/sqrt.scm @@ -4,17 +4,16 @@ ; http://sarabander.github.io/sicp/html/1_002e1.xhtml#g_t1_002e1_002e7 (define (sqrt-iter guess x) - (if (good-enough? guess x) - guess - (sqrt-iter (improve guess x) x))) + (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x))) (define (improve guess x) (average guess (/ x guess))) -(define (average x y) +(define (average x y) (/ (+ x y) 2)) -(define (square x) (* x x)) +(define (square x) + (* x x)) (define (good-enough? guess x) (< (abs (- (square guess) x)) 0.001)) @@ -22,4 +21,4 @@ (define (sqrt x) (sqrt-iter 1.0 x)) -(display (sqrt 2)) \ No newline at end of file +(display (sqrt 2)) diff --git a/src/tests.rs b/src/tests.rs index 7aecb78..c69e945 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -18,7 +18,7 @@ upstream for this fn run_pass() { let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); - insta::glob!("test/run-pass/**.scm", |p| { + insta::glob!("test/run-pass/**/*.scm", |p| { let p = PathBuf::from( p.canonicalize() .unwrap() 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))), } }