From bc00dbe69eba285881fca0f5c68d7ec83e2c48dc Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Tue, 28 Dec 2021 01:42:17 +0000 Subject: [PATCH 1/4] Implement closures What a pain. Next steps: More happy path tests, then large values/mutabilty, then redo in bytecode. --- Cargo.toml | 5 + src/ast.rs | 16 +- src/eval.rs | 99 +- src/grammar.lalrpop | 5 +- src/grammar.rs | 1351 ++++++++--------- src/main.rs | 19 +- src/prims.rs | 38 +- ...ball__tests__run-pass@ambig-scope.scm.snap | 13 + ...handball__tests__run-pass@capture.scm.snap | 9 + .../handball__tests__run-pass@curry.scm.snap | 8 + src/test/run-pass/ambig-scope.scm | 18 + src/test/run-pass/capture.scm | 12 + src/test/run-pass/curry.scm | 7 + src/value.rs | 41 +- 14 files changed, 816 insertions(+), 825 deletions(-) create mode 100644 src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@capture.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@curry.scm.snap create mode 100644 src/test/run-pass/ambig-scope.scm create mode 100644 src/test/run-pass/capture.scm create mode 100644 src/test/run-pass/curry.scm diff --git a/Cargo.toml b/Cargo.toml index 41c62ef..bf58b25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,8 @@ lalrpop = "0.19.6" [dev-dependencies] assert_cmd = "2.0.2" insta = { version = "1.9.0", features = ["glob"] } + +[profile.dev] +# https://github.com/rust-lang/rust/issues/92163 +# https://github.com/rust-lang/rust/issues/92315 +incremental=false \ No newline at end of file diff --git a/src/ast.rs b/src/ast.rs index cdd9503..d4029e6 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,20 +1,24 @@ use std::rc::Rc; -#[derive(Debug, debug2::Debug, PartialEq)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] crate enum Tree { Leaf(Literal), Define(String, Box), If(Box<[Tree; 3]>), - Lambda(Lambda), + // Its easier to box the lambdas in the parser than the vm, as + // here we see all of them exactly once + Func(Rc), Branch(Vec), } -#[derive(Debug, debug2::Debug, PartialEq, Clone)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] +crate struct Func { + crate args: Vec, + crate body: Vec, +} -crate struct Lambda(crate Rc<[String]>, crate Rc<[Tree]>); - -#[derive(Debug, debug2::Debug, PartialEq)] +#[derive(Debug /*/*, debug2::Debug*/*/, PartialEq)] crate enum Literal { Sym(String), diff --git a/src/eval.rs b/src/eval.rs index b9dbd8d..5eaf1c6 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -1,58 +1,77 @@ use std::assert_matches::assert_matches; +use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; use crate::value::Value; use crate::{ast, prims}; -pub(crate) fn eval(t: &ast::Tree, env: &mut Env) -> Result { +#[derive(/*debug2::Debug,*/ Debug, Clone)] +crate struct Lambda { + crate func: Rc, + crate captures: Rc>, +} + +pub(crate) fn eval(t: &ast::Tree, env: Rc>) -> Result { Ok(match t { ast::Tree::Leaf(l) => match l { - ast::Literal::Sym(s) => match env.lookup(s) { + ast::Literal::Sym(s) => match env.borrow().lookup(s) { Some(v) => v, None => return err(format!("Undefined variable `{}`", s)), }, ast::Literal::Num(v) => Value::Num(*v), ast::Literal::Bool(b) => Value::Bool(*b), }, - ast::Tree::Lambda(l) => Value::Lambda(l.clone()), + ast::Tree::Func(l) => Value::Lambda(Lambda { + func: Rc::clone(l), + captures: Rc::clone(&env), + }), ast::Tree::Branch(args) => { - let Some(fun) = args.get(0) else { return err("No argument given".to_owned()) }; - let fun = eval(fun, env)?; - let fun = fun.as_func()?; + let Some(fun) = args.get(0) else { return err("No func given".to_owned()) }; + + let fun = eval(fun, Rc::clone(&env))?.as_func()?; + let args = args .iter() .skip(1) - .map(|a| eval(a, env)) + .map(|a| eval(a, Rc::clone(&env))) .collect::, _>>()?; - // return fun(&args); + match fun { Callable::Func(f) => f(&args)?, Callable::Lambda(l) => { - if l.0.len() == args.len() { - let mut env = env.child(); - for (x, y) in l.0.iter().zip(args) { + if l.func.args.len() == args.len() { + // let mut env = env.child(); + let mut env = Env::child(Rc::clone(&l.captures)); + + for (x, y) in l.func.args.iter().zip(args) { env.define(x.clone(), y) } + let env = Rc::new(RefCell::new(env)); - let [main @ .., tail] = &l.1[..] else { unreachable!("Body has 1+ element by parser") }; + let [main @ .., tail] = &l.func.body[..] else { unreachable!("Body has 1+ element by parser") }; for i in main { - eval(i, &mut env)?; + eval(i, Rc::clone(&env))?; } - eval(tail, &mut env)? + eval(tail, env)? } else { - return err(format!("Need {} args, got {}", l.0.len(), args.len())); + return err(format!( + "Need {} args, got {}", + l.func.args.len(), + args.len() + )); } } } } ast::Tree::Define(name, to) => { - let val = eval(to, env)?; - env.define(name.to_owned(), val); + let val = eval(to, Rc::clone(&env))?; + env.borrow_mut().define(name.to_owned(), val); Value::Trap } ast::Tree::If(box [cond, tcase, fcase]) => { - let b = eval(cond, env)?.as_bool()?; + let b = eval(cond, Rc::clone(&env))?.as_bool()?; let body = if b { tcase } else { fcase }; eval(body, env)? } @@ -66,40 +85,60 @@ pub(crate) fn err(s: String) -> Result { Err(RTError(s)) } -pub(crate) enum Callable<'a> { - Func(prims::Func), - Lambda(&'a ast::Lambda), +pub(crate) enum Callable { + Func(prims::NativeFunc), + Lambda(Lambda), } -pub(crate) struct Env<'a> { - pub(crate) vars: HashMap, - pub(crate) enclosing: Option<&'a Env<'a>>, +#[derive(Clone /*, debug2::Debug*/)] +pub(crate) struct Env { + vars: HashMap, + enclosing: Option>>, } -impl<'a> Env<'a> { - pub(crate) fn child(&'a self) -> Env<'a> { +impl std::fmt::Debug for Env { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + struct Vars<'a>(&'a HashMap); + + impl std::fmt::Debug for Vars<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_set().entries(self.0.keys()).finish() + } + } + + f.debug_struct("Env") + .field("vars", &Vars(&self.vars)) + .field("enclosing", &self.enclosing) + .finish() + } +} + +impl Env { + pub(crate) fn child(this: Rc>) -> Env { Env { vars: HashMap::new(), - enclosing: Some(self), + enclosing: Some(this), } } pub(crate) fn lookup(&self, s: &str) -> Option { if let Some(v) = self.vars.get(s) { Some(v.clone()) - } else if let Some(parent) = self.enclosing { - parent.lookup(s) + } else if let Some(parent) = &self.enclosing { + parent.borrow().lookup(s) } else { None } } pub(crate) fn define(&mut self, name: String, val: Value) { + assert_ne!(val, Value::Trap); // TODO: Better error + self.vars.insert(name, val); } } -pub(crate) fn default_env() -> Env<'static> { +pub(crate) fn default_env() -> Env { let mut vars = HashMap::new(); for (name, fun) in prims::prims() { diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 681053d..3aed6d9 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -17,9 +17,10 @@ Trees = Tree+; pub(crate) Tree: Tree = { "(" ")" => Tree::Branch(<>), "(" "define" ")" => Tree::Define(<>), - "(" "define" "(" > ")" > ")" => Tree::Define(name, Box::new(Tree::Lambda(Lambda(args, body)))), + "(" "define" "(" ")" ")" + => Tree::Define(name, Box::new(Tree::Func(Rc::new(Func{args, body})))), "(" "if" ")" => Tree::If(Box::new([<>])), - "(" "lambda (" > ")" > ")" => Tree::Lambda(Lambda(<>)), + "(" "lambda (" ")" ")" => Tree::Func(Rc::new(Func{<>})), Literal => Tree::Leaf(<>), } diff --git a/src/grammar.rs b/src/grammar.rs index 5175c41..dea8cd9 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.19.6" -// sha3: c1daa5330c6265bff388c19ed1642efbf9924c741dbad19b8016bd2a5a646 +// sha3: e06bc49958cb5e211ea88ac1ea9d95dffc9b12e0e8f9e43b4681a168821c use crate::ast::*; use std::rc::Rc; #[allow(unused_extern_crates)] @@ -33,111 +33,117 @@ mod __parse__File { Variant5(core::option::Option<()>), Variant6(Literal), Variant7(f64), - Variant8(Rc<[String]>), - Variant9(Rc<[Tree]>), - Variant10(String), - Variant11(alloc::vec::Vec), - Variant12(Tree), + Variant8(String), + Variant9(alloc::vec::Vec), + Variant10(Tree), } const __ACTION: &[i8] = &[ // State 0 - 26, 4, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 4, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 1 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 2 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, -31, 0, 0, 0, 0, 0, 30, 31, // State 3 - 0, 0, 0, 0, 0, 0, 0, 0, 33, 34, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 35, 36, 0, 0, // State 4 - 26, 0, 27, 5, 0, 7, 8, 9, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 7, 8, 9, 0, 0, 30, 31, // State 5 - 26, 0, 27, 5, 35, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 37, 0, 0, 0, 0, 0, 30, 31, // State 6 - 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 31, // State 7 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 8 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 31, // State 9 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 10 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, // State 11 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 12 - 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 29, + 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 31, // State 13 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 14 - 26, 0, 27, 5, 0, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 31, // State 15 - 26, 0, 27, 5, -18, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 16 - 26, 0, 27, 5, -19, 0, 0, 0, 0, 0, 28, 29, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 17 - 26, 0, 27, 5, -18, 0, 0, 0, 0, 0, 28, 29, + 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 31, // State 18 - -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, // State 20 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, // State 21 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 22 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, - // State 23 - -33, 0, -33, -33, -33, 0, 0, 0, 0, 0, -33, -33, - // State 24 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // State 25 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, - // State 26 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, - // State 27 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, - // State 28 - -20, 0, -20, -20, -20, 0, 0, 0, 0, 0, -20, -20, - // State 29 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // State 30 - -34, 0, -34, -34, -34, 0, 0, 0, 0, 0, -34, -34, - // State 31 - -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, -7, -7, - // State 32 - -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, -11, -11, - // State 33 - -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, -10, -10, - // State 34 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, - // State 35 - 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, - // State 36 - 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, -23, - // State 37 - 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, - // State 38 - 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, - // State 39 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, - // State 40 - 0, 0, 0, 0, -24, 0, 0, 0, 0, 0, 0, -24, - // State 41 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, - // State 42 - 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, - // State 43 - 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, - // State 44 - 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, - // State 45 -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, - // State 46 + // State 23 + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + // State 24 + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + // State 25 -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, - // State 47 + // State 26 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 27 + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + // State 28 + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + // State 29 + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + // State 30 + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, -16, -16, + // State 31 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 32 + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + // State 33 + -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, -7, -7, + // State 34 + -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, -11, -11, + // State 35 + -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, -10, -10, + // State 36 + -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, -21, -21, + // State 37 + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, -19, + // State 38 + 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, + // State 39 + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, + // State 40 + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + // State 41 + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, -20, + // State 42 + 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, + // State 43 + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, -22, -22, + // State 44 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, + // State 45 + 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, + // State 46 + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, + // State 47 + 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, // State 48 + -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + // State 49 -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + // State 50 + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, + // State 51 + -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, -23, -23, + // State 52 + -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, -24, -24, ]; fn __action(state: i8, integer: usize) -> i8 { __ACTION[(state as usize) * 12 + integer] @@ -148,7 +154,7 @@ mod __parse__File { // State 1 0, // State 2 - -35, + -31, // State 3 0, // State 4 @@ -180,43 +186,43 @@ mod __parse__File { // State 17 0, // State 18 - -14, + 0, // State 19 - -36, + 0, // State 20 - -30, + -14, // State 21 - -13, + -32, // State 22 - -12, + -28, // State 23 - -33, + -13, // State 24 - -6, + -12, // State 25 - -3, + -29, // State 26 - -2, + -6, // State 27 - -15, + -3, // State 28 - -20, + -2, // State 29 - -5, + -15, // State 30 - -34, + -16, // State 31 - 0, + -5, // State 32 - 0, + -30, // State 33 0, // State 34 - -25, + 0, // State 35 0, // State 36 - 0, + -21, // State 37 0, // State 38 @@ -226,64 +232,70 @@ mod __parse__File { // State 40 0, // State 41 - -26, + 0, // State 42 0, // State 43 - 0, + -22, // State 44 0, // State 45 - -28, + 0, // State 46 - -29, + -26, // State 47 0, // State 48 + -25, + // State 49 -27, + // State 50 + 0, + // State 51 + -23, + // State 52 + -24, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 0 => 37, - 1 => 18, - 2 => 38, - 3 => 19, + 0 => 38, + 1 => 20, + 2 => 39, + 3 => 21, 4 => 1, - 6 => 31, - 7 => 20, - 8 => 21, + 6 => 33, + 7 => 22, + 8 => 23, 9 => match state { - 13 => 42, - _ => 35, - }, - 10 => match state { - 17 => 47, - _ => 44, + 6 => 9, + 10 => 14, + 8 | 14 => 37, + 12 | 17 => 41, + _ => 24, }, 11 => match state { - 6 => 9, - 10 => 13, - 8 | 13 => 36, - 12 => 40, - _ => 22, + 14 => 17, + _ => 12, }, - 13 => 12, - 14 => match state { + 12 => match state { 7 => 11, - 11 => 14, - 2 | 5 | 16 => 30, - 9 => 39, - 14 => 43, - _ => 23, + 11 => 15, + 2 | 5 => 32, + 9 => 40, + 15 => 44, + _ => 25, }, - 16 => match state { - 0..=1 => 2, + 13 => match state { 4 => 5, - _ => 16, + _ => 2, }, - 17 => match state { - 1 => 29, - _ => 24, + 14 => match state { + 1 => 31, + 13 => 42, + 16 => 45, + 18 => 47, + 19 => 50, + _ => 26, }, _ => 0, } @@ -590,18 +602,6 @@ mod __parse__File { __reduce30(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } 31 => { - __reduce31(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 32 => { - __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 33 => { - __reduce33(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 34 => { - __reduce34(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 35 => { // __File = File => ActionFn(0); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); @@ -609,8 +609,8 @@ mod __parse__File { let __nt = super::__action0::<>(input, __sym0); return Some(Ok(__nt)); } - 36 => { - __reduce36(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) + 32 => { + __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } _ => panic!("invalid action code {}", __action) }; @@ -662,54 +662,32 @@ mod __parse__File { 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[String]>, usize) + ) -> (usize, String, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant8(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant9< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[Tree]>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } fn __pop_Variant10< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, String, usize) + ) -> (usize, Tree, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant12< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Tree, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant11< + fn __pop_Variant9< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, alloc::vec::Vec, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -833,7 +811,7 @@ mod __parse__File { ) -> (usize, usize) { // Box = Tree => ActionFn(21); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action21::<>(input, __sym0); @@ -850,13 +828,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(34); + // File = Lang, Trees => ActionFn(30); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant3(__symbols); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action34::<>(input, __sym0, __sym1); + let __nt = super::__action30::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -870,11 +848,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(35); + // File = Trees => ActionFn(31); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action35::<>(input, __sym0); + let __nt = super::__action31::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -980,7 +958,7 @@ mod __parse__File { ) -> (usize, usize) { // Literal = Sym => ActionFn(11); - let __sym0 = __pop_Variant10(__symbols); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action11::<>(input, __sym0); @@ -1051,12 +1029,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(36); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action36::<>(input, &__start, &__end); + // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action14::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (0, 9) + (1, 9) } pub(crate) fn __reduce16< 'input, @@ -1068,13 +1047,12 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Sym+ => ActionFn(37); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action37::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (1, 9) + // Sym* = => ActionFn(22); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action22::<>(input, &__start, &__end); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (0, 10) } pub(crate) fn __reduce17< 'input, @@ -1086,12 +1064,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(38); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action38::<>(input, &__start, &__end); + // Sym* = Sym+ => ActionFn(23); + let __sym0 = __pop_Variant9(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action23::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (0, 10) + (1, 10) } pub(crate) fn __reduce18< 'input, @@ -1103,13 +1082,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Tree+ => ActionFn(39); - let __sym0 = __pop_Variant3(__symbols); + // Sym+ = Sym => ActionFn(28); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, __sym0); + let __nt = super::__action28::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + (1, 11) } pub(crate) fn __reduce19< 'input, @@ -1121,88 +1100,17 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); - let __sym0 = __pop_Variant0(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action14::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) - } - pub(crate) fn __reduce20< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = => ActionFn(28); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action28::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (0, 12) - } - pub(crate) fn __reduce21< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = Sym+ => ActionFn(29); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action29::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) - } - pub(crate) fn __reduce22< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym => ActionFn(32); - let __sym0 = __pop_Variant10(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action32::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 13) - } - pub(crate) fn __reduce23< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym+, Sym => ActionFn(33); + // Sym+ = Sym+, Sym => ActionFn(29); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant10(__symbols); - let __sym0 = __pop_Variant11(__symbols); + let __sym1 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action33::<>(input, __sym0, __sym1); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (2, 13) + let __nt = super::__action29::<>(input, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (2, 11) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce20< 'input, 's, >( @@ -1220,10 +1128,10 @@ mod __parse__File { let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); let __nt = super::__action4::<>(input, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (3, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (3, 12) } - pub(crate) fn __reduce25< + pub(crate) fn __reduce21< 'input, 's, >( @@ -1237,16 +1145,16 @@ mod __parse__File { assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant1(__symbols); - let __sym2 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action5::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (5, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) } - pub(crate) fn __reduce26< + pub(crate) fn __reduce22< 'input, 's, >( @@ -1256,23 +1164,48 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, RcSlice, ")", RcSlice, ")" => ActionFn(6); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(32); + assert!(__symbols.len() >= 7); + let __sym6 = __pop_Variant0(__symbols); + let __sym5 = __pop_Variant3(__symbols); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym6.2.clone(); + let __nt = super::__action32::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (7, 12) + } + pub(crate) fn __reduce23< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(33); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant0(__symbols); - let __sym6 = __pop_Variant9(__symbols); + let __sym6 = __pop_Variant3(__symbols); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant8(__symbols); - let __sym3 = __pop_Variant10(__symbols); + let __sym4 = __pop_Variant9(__symbols); + let __sym3 = __pop_Variant8(__symbols); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym7.2.clone(); - let __nt = super::__action6::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (8, 14) + let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (8, 12) } - pub(crate) fn __reduce27< + pub(crate) fn __reduce24< 'input, 's, >( @@ -1285,18 +1218,18 @@ mod __parse__File { // Tree = "(", "if", Tree, Tree, Tree, ")" => ActionFn(7); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant12(__symbols); - let __sym3 = __pop_Variant12(__symbols); - let __sym2 = __pop_Variant12(__symbols); + let __sym4 = __pop_Variant10(__symbols); + let __sym3 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant10(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); let __nt = super::__action7::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce28< + pub(crate) fn __reduce25< 'input, 's, >( @@ -1306,21 +1239,44 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", RcSlice, ")", RcSlice, ")" => ActionFn(8); + // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(34); + assert!(__symbols.len() >= 5); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant3(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym4.2.clone(); + let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) + } + pub(crate) fn __reduce26< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(35); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant9(__symbols); + let __sym4 = __pop_Variant3(__symbols); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant9(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action8::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce29< + pub(crate) fn __reduce27< 'input, 's, >( @@ -1335,45 +1291,10 @@ mod __parse__File { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action9::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } - pub(crate) fn __reduce30< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = => ActionFn(30); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action30::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (0, 15) - } - pub(crate) fn __reduce31< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = Tree+ => ActionFn(31); - let __sym0 = __pop_Variant3(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action31::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 15) - } - pub(crate) fn __reduce32< + pub(crate) fn __reduce28< 'input, 's, >( @@ -1384,14 +1305,14 @@ mod __parse__File { ) -> (usize, usize) { // Tree+ = Tree => ActionFn(24); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 16) + (1, 13) } - pub(crate) fn __reduce33< + pub(crate) fn __reduce29< 'input, 's, >( @@ -1403,15 +1324,15 @@ mod __parse__File { { // Tree+ = Tree+, Tree => ActionFn(25); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant12(__symbols); + let __sym1 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); let __nt = super::__action25::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (2, 16) + (2, 13) } - pub(crate) fn __reduce34< + pub(crate) fn __reduce30< 'input, 's, >( @@ -1427,9 +1348,9 @@ mod __parse__File { let __end = __sym0.2.clone(); let __nt = super::__action3::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 17) + (1, 14) } - pub(crate) fn __reduce36< + pub(crate) fn __reduce32< 'input, 's, >( @@ -1440,12 +1361,12 @@ mod __parse__File { ) -> (usize, usize) { // __Tree = Tree => ActionFn(1); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action1::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 19) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 16) } } pub(crate) use self::__parse__File::FileParser; @@ -1474,95 +1395,103 @@ mod __parse__Tree { Variant5(core::option::Option<()>), Variant6(Literal), Variant7(f64), - Variant8(Rc<[String]>), - Variant9(Rc<[Tree]>), - Variant10(String), - Variant11(alloc::vec::Vec), - Variant12(Tree), + Variant8(String), + Variant9(alloc::vec::Vec), + Variant10(Tree), } const __ACTION: &[i8] = &[ // State 0 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 1 - 21, 0, 22, 2, 0, 4, 5, 6, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 4, 5, 6, 0, 0, 26, 27, // State 2 - 21, 0, 22, 2, 27, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 30, 0, 0, 0, 0, 0, 26, 27, // State 3 - 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 27, // State 4 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 5 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 27, // State 6 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 7 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, // State 8 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 9 - 0, 0, 0, 0, -17, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 27, // State 10 - 0, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 11 - 21, 0, 22, 2, 0, 0, 0, 0, 0, 0, 23, 24, + 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 27, // State 12 - 21, 0, 22, 2, -18, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 13 - 21, 0, 22, 2, -19, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 14 - 21, 0, 22, 2, -18, 0, 0, 0, 0, 0, 23, 24, + 24, 0, 25, 2, -31, 0, 0, 0, 0, 0, 26, 27, // State 15 - -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, + 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 27, // State 16 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 17 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, // State 18 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, -14, -14, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - // State 20 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, - // State 21 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, - // State 22 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, - // State 23 - -20, 0, -20, -20, -20, 0, 0, 0, 0, 0, -20, -20, - // State 24 - -33, 0, -33, -33, -33, 0, 0, 0, 0, 0, -33, -33, - // State 25 - -34, 0, -34, -34, -34, 0, 0, 0, 0, 0, -34, -34, - // State 26 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, - // State 27 - 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, - // State 28 - 0, 0, 0, 0, -23, 0, 0, 0, 0, 0, 0, -23, - // State 29 - 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, - // State 30 - 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, - // State 31 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, - // State 32 - 0, 0, 0, 0, -24, 0, 0, 0, 0, 0, 0, -24, - // State 33 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, - // State 34 - 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, - // State 35 - 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 0, 0, - // State 36 - 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, - // State 37 -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, - // State 38 + // State 20 + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + // State 21 + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + // State 22 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 23 + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + // State 24 + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + // State 25 + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + // State 26 + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, -16, -16, + // State 27 -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, + // State 28 + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + // State 29 + -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, -21, -21, + // State 30 + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, -19, + // State 31 + 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, + // State 32 + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, + // State 33 + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + // State 34 + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, -20, + // State 35 + 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, + // State 36 + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, -22, -22, + // State 37 + 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, + // State 38 + 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, // State 39 - 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, // State 40 + 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, + // State 41 + -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + // State 42 -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + // State 43 + 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, + // State 44 + -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, -23, -23, + // State 45 + -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, -24, -24, ]; fn __action(state: i8, integer: usize) -> i8 { __ACTION[(state as usize) * 12 + integer] @@ -1599,35 +1528,35 @@ mod __parse__Tree { // State 14 0, // State 15 - -14, + 0, // State 16 - -30, + 0, // State 17 - -13, + 0, // State 18 - -12, + -14, // State 19 - -37, + -28, // State 20 - -3, + -13, // State 21 - -2, + -12, // State 22 - -15, + -33, // State 23 - -20, + -3, // State 24 - 0, + -2, // State 25 - 0, + -15, // State 26 - -25, + -16, // State 27 0, // State 28 0, // State 29 - 0, + -21, // State 30 0, // State 31 @@ -1635,57 +1564,68 @@ mod __parse__Tree { // State 32 0, // State 33 - -26, + 0, // State 34 0, // State 35 0, // State 36 - 0, + -22, // State 37 - -28, - // State 38 - -29, - // State 39 0, + // State 38 + 0, + // State 39 + -26, // State 40 + 0, + // State 41 + -25, + // State 42 -27, + // State 43 + 0, + // State 44 + -23, + // State 45 + -24, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 0 => 29, - 1 => 15, - 2 => 30, - 7 => 16, - 8 => 17, + 0 => 31, + 1 => 18, + 2 => 32, + 7 => 19, + 8 => 20, 9 => match state { - 10 => 34, - _ => 27, - }, - 10 => match state { - 14 => 39, - _ => 36, + 3 => 6, + 7 => 11, + 5 | 11 => 30, + 9 | 15 => 34, + _ => 21, }, 11 => match state { - 3 => 6, - 7 => 10, - 5 | 10 => 28, - 9 => 32, - _ => 18, + 11 => 15, + _ => 9, }, - 13 => 9, - 14 => match state { + 12 => match state { 4 => 8, - 8 => 11, - 0 => 19, - 2 | 13 => 25, - 6 => 31, - 11 => 35, - _ => 24, + 8 => 12, + 0 => 22, + 2 | 14 => 28, + 6 => 33, + 12 => 37, + _ => 27, }, - 16 => match state { + 13 => match state { 1 => 2, - _ => 13, + _ => 14, + }, + 14 => match state { + 13 => 38, + 16 => 40, + 17 => 43, + _ => 35, }, _ => 0, } @@ -1995,20 +1935,8 @@ mod __parse__Tree { __reduce31(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } 32 => { - __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 33 => { - __reduce33(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 34 => { - __reduce34(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 35 => { - __reduce35(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) - } - 36 => { // __Tree = Tree => ActionFn(1); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action1::<>(input, __sym0); @@ -2064,54 +1992,32 @@ mod __parse__Tree { 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[String]>, usize) + ) -> (usize, String, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant8(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant9< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Rc<[Tree]>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } fn __pop_Variant10< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, String, usize) + ) -> (usize, Tree, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant12< - 'input, - >( - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Tree, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant11< + fn __pop_Variant9< 'input, >( __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, alloc::vec::Vec, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -2235,7 +2141,7 @@ mod __parse__Tree { ) -> (usize, usize) { // Box = Tree => ActionFn(21); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action21::<>(input, __sym0); @@ -2252,13 +2158,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(34); + // File = Lang, Trees => ActionFn(30); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant3(__symbols); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action34::<>(input, __sym0, __sym1); + let __nt = super::__action30::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -2272,11 +2178,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(35); + // File = Trees => ActionFn(31); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action35::<>(input, __sym0); + let __nt = super::__action31::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -2382,7 +2288,7 @@ mod __parse__Tree { ) -> (usize, usize) { // Literal = Sym => ActionFn(11); - let __sym0 = __pop_Variant10(__symbols); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action11::<>(input, __sym0); @@ -2453,12 +2359,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(36); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action36::<>(input, &__start, &__end); + // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action14::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (0, 9) + (1, 9) } pub(crate) fn __reduce16< 'input, @@ -2470,13 +2377,12 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Sym+ => ActionFn(37); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action37::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (1, 9) + // Sym* = => ActionFn(22); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action22::<>(input, &__start, &__end); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (0, 10) } pub(crate) fn __reduce17< 'input, @@ -2488,12 +2394,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = => ActionFn(38); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action38::<>(input, &__start, &__end); + // Sym* = Sym+ => ActionFn(23); + let __sym0 = __pop_Variant9(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action23::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (0, 10) + (1, 10) } pub(crate) fn __reduce18< 'input, @@ -2505,13 +2412,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // RcSlice = Tree+ => ActionFn(39); - let __sym0 = __pop_Variant3(__symbols); + // Sym+ = Sym => ActionFn(28); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, __sym0); + let __nt = super::__action28::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + (1, 11) } pub(crate) fn __reduce19< 'input, @@ -2523,88 +2430,17 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); - let __sym0 = __pop_Variant0(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action14::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) - } - pub(crate) fn __reduce20< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = => ActionFn(28); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action28::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (0, 12) - } - pub(crate) fn __reduce21< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym* = Sym+ => ActionFn(29); - let __sym0 = __pop_Variant11(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action29::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) - } - pub(crate) fn __reduce22< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym => ActionFn(32); - let __sym0 = __pop_Variant10(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action32::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 13) - } - pub(crate) fn __reduce23< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Sym+ = Sym+, Sym => ActionFn(33); + // Sym+ = Sym+, Sym => ActionFn(29); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant10(__symbols); - let __sym0 = __pop_Variant11(__symbols); + let __sym1 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action33::<>(input, __sym0, __sym1); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (2, 13) + let __nt = super::__action29::<>(input, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (2, 11) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce20< 'input, 's, >( @@ -2622,10 +2458,10 @@ mod __parse__Tree { let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); let __nt = super::__action4::<>(input, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (3, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (3, 12) } - pub(crate) fn __reduce25< + pub(crate) fn __reduce21< 'input, 's, >( @@ -2639,16 +2475,16 @@ mod __parse__Tree { assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant1(__symbols); - let __sym2 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action5::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (5, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) } - pub(crate) fn __reduce26< + pub(crate) fn __reduce22< 'input, 's, >( @@ -2658,23 +2494,48 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, RcSlice, ")", RcSlice, ")" => ActionFn(6); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(32); + assert!(__symbols.len() >= 7); + let __sym6 = __pop_Variant0(__symbols); + let __sym5 = __pop_Variant3(__symbols); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym6.2.clone(); + let __nt = super::__action32::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (7, 12) + } + pub(crate) fn __reduce23< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(33); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant0(__symbols); - let __sym6 = __pop_Variant9(__symbols); + let __sym6 = __pop_Variant3(__symbols); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant8(__symbols); - let __sym3 = __pop_Variant10(__symbols); + let __sym4 = __pop_Variant9(__symbols); + let __sym3 = __pop_Variant8(__symbols); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym7.2.clone(); - let __nt = super::__action6::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (8, 14) + let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (8, 12) } - pub(crate) fn __reduce27< + pub(crate) fn __reduce24< 'input, 's, >( @@ -2687,18 +2548,18 @@ mod __parse__Tree { // Tree = "(", "if", Tree, Tree, Tree, ")" => ActionFn(7); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant12(__symbols); - let __sym3 = __pop_Variant12(__symbols); - let __sym2 = __pop_Variant12(__symbols); + let __sym4 = __pop_Variant10(__symbols); + let __sym3 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant10(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); let __nt = super::__action7::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce28< + pub(crate) fn __reduce25< 'input, 's, >( @@ -2708,21 +2569,44 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", RcSlice, ")", RcSlice, ")" => ActionFn(8); + // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(34); + assert!(__symbols.len() >= 5); + let __sym4 = __pop_Variant0(__symbols); + let __sym3 = __pop_Variant3(__symbols); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym4.2.clone(); + let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (5, 12) + } + pub(crate) fn __reduce26< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(35); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant9(__symbols); + let __sym4 = __pop_Variant3(__symbols); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant9(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action8::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (6, 14) + let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (6, 12) } - pub(crate) fn __reduce29< + pub(crate) fn __reduce27< 'input, 's, >( @@ -2737,45 +2621,10 @@ mod __parse__Tree { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action9::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 14) + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } - pub(crate) fn __reduce30< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = => ActionFn(30); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action30::<>(input, &__start, &__end); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (0, 15) - } - pub(crate) fn __reduce31< - 'input, - 's, - >( - input: &'input str, - __lookahead_start: Option<&usize>, - __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, - _: core::marker::PhantomData<(&'input (), &'s ())>, - ) -> (usize, usize) - { - // Tree* = Tree+ => ActionFn(31); - let __sym0 = __pop_Variant3(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action31::<>(input, __sym0); - __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 15) - } - pub(crate) fn __reduce32< + pub(crate) fn __reduce28< 'input, 's, >( @@ -2786,14 +2635,14 @@ mod __parse__Tree { ) -> (usize, usize) { // Tree+ = Tree => ActionFn(24); - let __sym0 = __pop_Variant12(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 16) + (1, 13) } - pub(crate) fn __reduce33< + pub(crate) fn __reduce29< 'input, 's, >( @@ -2805,15 +2654,15 @@ mod __parse__Tree { { // Tree+ = Tree+, Tree => ActionFn(25); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant12(__symbols); + let __sym1 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); let __nt = super::__action25::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (2, 16) + (2, 13) } - pub(crate) fn __reduce34< + pub(crate) fn __reduce30< 'input, 's, >( @@ -2829,9 +2678,9 @@ mod __parse__Tree { let __end = __sym0.2.clone(); let __nt = super::__action3::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 17) + (1, 14) } - pub(crate) fn __reduce35< + pub(crate) fn __reduce31< 'input, 's, >( @@ -2847,7 +2696,7 @@ mod __parse__Tree { let __end = __sym0.2.clone(); let __nt = super::__action0::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); - (1, 18) + (1, 15) } } pub(crate) use self::__parse__Tree::TreeParser; @@ -2943,12 +2792,12 @@ fn __action6<'input, 's>( (_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize), (_, name, _): (usize, String, usize), - (_, args, _): (usize, Rc<[String]>, usize), + (_, args, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), - (_, body, _): (usize, Rc<[Tree]>, usize), + (_, body, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), ) -> Tree { - Tree::Define(name, Box::new(Tree::Lambda(Lambda(args, body)))) + Tree::Define(name, Box::new(Tree::Func(Rc::new(Func { args, body })))) } #[allow(unused_variables)] @@ -2969,12 +2818,15 @@ fn __action8<'input, 's>( input: &'input str, (_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize), - (_, __0, _): (usize, Rc<[String]>, usize), + (_, args, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), - (_, __1, _): (usize, Rc<[Tree]>, usize), + (_, body, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), ) -> Tree { - Tree::Lambda(Lambda(__0, __1)) + Tree::Func(Rc::new(Func { + args: args, + body: body, + })) } #[allow(unused_variables)] @@ -3055,17 +2907,18 @@ fn __action21<'input, 's>(input: &'input str, (_, __0, _): (usize, Tree, usize)) #[allow(unused_variables)] fn __action22<'input, 's>( input: &'input str, - (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> Rc<[Tree]> { - __0.into() + __lookbehind: &usize, + __lookahead: &usize, +) -> alloc::vec::Vec { + alloc::vec![] } #[allow(unused_variables)] fn __action23<'input, 's>( input: &'input str, - (_, __0, _): (usize, alloc::vec::Vec, usize), -) -> Rc<[String]> { - __0.into() + (_, v, _): (usize, alloc::vec::Vec, usize), +) -> alloc::vec::Vec { + v } #[allow(unused_variables)] @@ -3108,40 +2961,6 @@ fn __action27<'input, 's>( #[allow(unused_variables)] fn __action28<'input, 's>( - input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> alloc::vec::Vec { - alloc::vec![] -} - -#[allow(unused_variables)] -fn __action29<'input, 's>( - input: &'input str, - (_, v, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { - v -} - -#[allow(unused_variables)] -fn __action30<'input, 's>( - input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> alloc::vec::Vec { - alloc::vec![] -} - -#[allow(unused_variables)] -fn __action31<'input, 's>( - input: &'input str, - (_, v, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { - v -} - -#[allow(unused_variables)] -fn __action32<'input, 's>( input: &'input str, (_, __0, _): (usize, String, usize), ) -> alloc::vec::Vec { @@ -3149,7 +2968,7 @@ fn __action32<'input, 's>( } #[allow(unused_variables)] -fn __action33<'input, 's>( +fn __action29<'input, 's>( input: &'input str, (_, v, _): (usize, alloc::vec::Vec, usize), (_, e, _): (usize, String, usize), @@ -3162,7 +2981,7 @@ fn __action33<'input, 's>( } #[allow(unused_variables)] -fn __action34<'input, 's>( +fn __action30<'input, 's>( input: &'input str, __0: (usize, (), usize), __1: (usize, alloc::vec::Vec, usize), @@ -3175,7 +2994,7 @@ fn __action34<'input, 's>( } #[allow(unused_variables)] -fn __action35<'input, 's>( +fn __action31<'input, 's>( input: &'input str, __0: (usize, alloc::vec::Vec, usize), ) -> alloc::vec::Vec { @@ -3187,53 +3006,73 @@ fn __action35<'input, 's>( } #[allow(unused_variables)] -fn __action36<'input, 's>( +fn __action32<'input, 's>( input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> Rc<[String]> { - let __start0 = __lookbehind.clone(); - let __end0 = __lookahead.clone(); - let __temp0 = __action28(input, &__start0, &__end0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, &'input str, usize), + __3: (usize, String, usize), + __4: (usize, &'input str, usize), + __5: (usize, alloc::vec::Vec, usize), + __6: (usize, &'input str, usize), +) -> Tree { + let __start0 = __3.2.clone(); + let __end0 = __4.0.clone(); + let __temp0 = __action22(input, &__start0, &__end0); let __temp0 = (__start0, __temp0, __end0); - __action23(input, __temp0) + __action6(input, __0, __1, __2, __3, __temp0, __4, __5, __6) } #[allow(unused_variables)] -fn __action37<'input, 's>( +fn __action33<'input, 's>( input: &'input str, - __0: (usize, alloc::vec::Vec, usize), -) -> Rc<[String]> { - let __start0 = __0.0.clone(); - let __end0 = __0.2.clone(); - let __temp0 = __action29(input, __0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, &'input str, usize), + __3: (usize, String, usize), + __4: (usize, alloc::vec::Vec, usize), + __5: (usize, &'input str, usize), + __6: (usize, alloc::vec::Vec, usize), + __7: (usize, &'input str, usize), +) -> Tree { + let __start0 = __4.0.clone(); + let __end0 = __4.2.clone(); + let __temp0 = __action23(input, __4); let __temp0 = (__start0, __temp0, __end0); - __action23(input, __temp0) + __action6(input, __0, __1, __2, __3, __temp0, __5, __6, __7) } #[allow(unused_variables)] -fn __action38<'input, 's>( +fn __action34<'input, 's>( input: &'input str, - __lookbehind: &usize, - __lookahead: &usize, -) -> Rc<[Tree]> { - let __start0 = __lookbehind.clone(); - let __end0 = __lookahead.clone(); - let __temp0 = __action30(input, &__start0, &__end0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, &'input str, usize), + __3: (usize, alloc::vec::Vec, usize), + __4: (usize, &'input str, usize), +) -> Tree { + let __start0 = __1.2.clone(); + let __end0 = __2.0.clone(); + let __temp0 = __action22(input, &__start0, &__end0); let __temp0 = (__start0, __temp0, __end0); - __action22(input, __temp0) + __action8(input, __0, __1, __temp0, __2, __3, __4) } #[allow(unused_variables)] -fn __action39<'input, 's>( +fn __action35<'input, 's>( input: &'input str, - __0: (usize, alloc::vec::Vec, usize), -) -> Rc<[Tree]> { - let __start0 = __0.0.clone(); - let __end0 = __0.2.clone(); - let __temp0 = __action31(input, __0); + __0: (usize, &'input str, usize), + __1: (usize, &'input str, usize), + __2: (usize, alloc::vec::Vec, usize), + __3: (usize, &'input str, usize), + __4: (usize, alloc::vec::Vec, usize), + __5: (usize, &'input str, usize), +) -> Tree { + let __start0 = __2.0.clone(); + let __end0 = __2.2.clone(); + let __temp0 = __action23(input, __2); let __temp0 = (__start0, __temp0, __end0); - __action22(input, __temp0) + __action8(input, __0, __1, __temp0, __3, __4, __5) } pub trait __ToTriple<'input, 's> { diff --git a/src/main.rs b/src/main.rs index 1f83267..f7ec21c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,9 @@ #![feature(crate_visibility_modifier)] #![feature(let_else)] +use std::cell::RefCell; use std::io; +use std::rc::Rc; use rustyline::validate::{ MatchingBracketValidator, ValidationContext, ValidationResult, Validator, @@ -33,9 +35,9 @@ fn main() { fn run_file(file: &str) -> io::Result<()> { let src = std::fs::read_to_string(file)?; let tree = grammar::FileParser::new().parse(&src).unwrap(); - let mut env = eval::default_env(); + let env = Rc::new(RefCell::new(eval::default_env())); for i in tree { - eval::eval(&i, &mut env).unwrap(); + eval::eval(&i, Rc::clone(&env)).unwrap(); } Ok(()) } @@ -46,14 +48,23 @@ fn repl() { brackets: MatchingBracketValidator::new(), })); - let mut env = eval::default_env(); + let env = Rc::new(RefCell::new(eval::default_env())); while let Ok(line) = rl.readline("> ") { rl.add_history_entry(&line); let tree = grammar::TreeParser::new().parse(&line).unwrap(); // dbg!(&tree); - println!("< {:?}", eval::eval(&tree, &mut env)) + match eval::eval(&tree, Rc::clone(&env)) { + Ok(v) => { + // Cant use == because it will panic. This is the only + // valid comparison to trap + if !matches!(v, value::Value::Trap) { + println!("{}", v) + } + } + Err(e) => println!("! {}", e.0), + } } } diff --git a/src/prims.rs b/src/prims.rs index 62e67ff..45c1232 100644 --- a/src/prims.rs +++ b/src/prims.rs @@ -1,9 +1,12 @@ use crate::eval::{err, RTError}; use crate::value::Value; -crate type Func = fn(&[Value]) -> Result; -crate fn prims() -> &'static [(&'static str, Func)] { +type Result = std::result::Result; + +crate type NativeFunc = for<'a> fn(&'a [Value]) -> Result; + +crate fn prims() -> &'static [(&'static str, NativeFunc)] { &[ ("*", mul), ("+", add), @@ -21,25 +24,27 @@ crate fn prims() -> &'static [(&'static str, Func)] { (">", gt), ("<=", le), (">=", ge), + + ("_Z_debug", z_debug) ] } // TODO: DRY +-/* -fn add(args: &[Value]) -> Result { +fn add(args: &[Value]) -> Result { args.iter() .map(Value::as_num) .try_fold(0.0, |a, b| Ok(a + b?)) .map(Value::Num) } -fn mul(args: &[Value]) -> Result { +fn mul(args: &[Value]) -> Result { args.iter() .map(Value::as_num) .try_fold(1.0, |a, b| Ok(a * b?)) .map(Value::Num) } -fn div(args: &[Value]) -> Result { +fn div(args: &[Value]) -> Result { let init = args .get(0) .ok_or_else(|| RTError("`div` needs at least one argument".to_owned()))? @@ -53,7 +58,7 @@ fn div(args: &[Value]) -> Result { })) } -fn sub(args: &[Value]) -> Result { +fn sub(args: &[Value]) -> Result { let init = args .get(0) .ok_or_else(|| RTError("`sub` needs at least one argument".to_owned()))? @@ -67,17 +72,17 @@ fn sub(args: &[Value]) -> Result { })) } -fn equals(args: &[Value]) -> Result { +fn equals(args: &[Value]) -> Result { Ok(Value::Bool(args.array_windows().all(|[l, r]| l == r))) } -fn display(args: &[Value]) -> Result { +fn display(args: &[Value]) -> Result { let [arg] = args else {return err("To many args to `display`".to_owned())}; - print!("{:?}", arg); + print!("{}", arg); Ok(Value::Trap) } -fn newline(args: &[Value]) -> Result { +fn newline(args: &[Value]) -> Result { if !args.is_empty() { return err("Newline takes no args".to_owned()); } @@ -85,7 +90,7 @@ fn newline(args: &[Value]) -> Result { Ok(Value::Trap) } -fn abs(args: &[Value]) -> Result { +fn abs(args: &[Value]) -> Result { let [v] = args else { return err("abs takes 1 arg".to_owned()) }; let ans = v.as_num()?.abs(); Ok(Value::Num(ans)) @@ -95,7 +100,7 @@ crate fn compare_core( args: &[Value], f: fn(f64, f64) -> bool, name: &'static str, -) -> Result { +) -> Result { for [l, r] in args.array_windows() { let (Value::Num(l), Value::Num(r)) = (l,r) else { @@ -114,11 +119,16 @@ crate fn compare_core( macro_rules! cmps { ($(($name:ident $op:tt))*) => { $( - fn $name(args: &[Value]) -> Result { + fn $name(args: &[Value]) -> Result { compare_core(args, |l, r| l $op r, stringify!($op)) } )* }; } -cmps! { (lt <) (gt >) (le <=) (ge >=) } \ No newline at end of file +cmps! { (lt <) (gt >) (le <=) (ge >=) } + +fn z_debug(args: &[Value]) -> Result { + eprintln!("{:?}", args); + Ok(Value::Trap) +} \ No newline at end of file diff --git a/src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap b/src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap new file mode 100644 index 0000000..657c8a2 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@ambig-scope.scm.snap @@ -0,0 +1,13 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: run-pass ambig-scope.scm + +--- + +42.0 +1.0 +2.0 +3.0 +2.0 +1.0 diff --git a/src/snapshots/handball__tests__run-pass@capture.scm.snap b/src/snapshots/handball__tests__run-pass@capture.scm.snap new file mode 100644 index 0000000..4d73305 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@capture.scm.snap @@ -0,0 +1,9 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: run-pass capture.scm + +--- +# +2.0 + diff --git a/src/snapshots/handball__tests__run-pass@curry.scm.snap b/src/snapshots/handball__tests__run-pass@curry.scm.snap new file mode 100644 index 0000000..7e245c0 --- /dev/null +++ b/src/snapshots/handball__tests__run-pass@curry.scm.snap @@ -0,0 +1,8 @@ +--- +source: src/tests.rs +assertion_line: 41 +expression: run-pass curry.scm + +--- +3.0 + diff --git a/src/test/run-pass/ambig-scope.scm b/src/test/run-pass/ambig-scope.scm new file mode 100644 index 0000000..055e8ac --- /dev/null +++ b/src/test/run-pass/ambig-scope.scm @@ -0,0 +1,18 @@ +#lang scheme + +(define (displayln x) (newline) (display x)) + +(define (ambig1 x) (lambda (x) x)) + +(displayln ((ambig1 13) 42)) + +(define (ambig2 a) + (displayln a) + (define a- a) + (lambda (b) (displayln b) + (lambda (a) + (displayln a) + (displayln b) + (displayln a-)))) + +(((ambig2 1) 2) 3) \ No newline at end of file diff --git a/src/test/run-pass/capture.scm b/src/test/run-pass/capture.scm new file mode 100644 index 0000000..bbf6c99 --- /dev/null +++ b/src/test/run-pass/capture.scm @@ -0,0 +1,12 @@ +#lang scheme + +(define (displayln x) (display x) (newline)) + + +(define (const x) (lambda () x)) + +(define two-thunk (const 2)) + +(displayln two-thunk) +(displayln (two-thunk)) + diff --git a/src/test/run-pass/curry.scm b/src/test/run-pass/curry.scm new file mode 100644 index 0000000..c5bac77 --- /dev/null +++ b/src/test/run-pass/curry.scm @@ -0,0 +1,7 @@ +#lang scheme + +(define (displayln x) (display x) (newline)) + +(define (curry2 f) (lambda (l) (lambda (r) (f l r)))) + +(displayln (((curry2 +) 1) 2)) diff --git a/src/value.rs b/src/value.rs index 09f309a..6ddf6de 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,16 +1,32 @@ -use crate::{ast, eval, prims}; +use crate::{eval, prims}; use std::rc::Rc; -#[derive(Clone)] +#[derive(Clone /*, debug2::Debug*/)] crate enum Value { Num(f64), - Func(prims::Func), - Lambda(ast::Lambda), + // TODO: implement debug2::Debug for `fn` type, and do it right + // https://godbolt.org/z/vr9erGeKq + Func(prims::NativeFunc), + Lambda(eval::Lambda), Bool(bool), /// Result of things that shouldnt have values, like (define x 3) + /// TODO: Figure this out Trap, } +impl std::fmt::Debug for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Num(arg0) => f.debug_tuple("Num").field(arg0).finish(), + // We cant just pass the field because of livetime bs, see https://godbolt.org/z/vr9erGeKq + Self::Func(_) => f.debug_struct("Func").finish_non_exhaustive(), + Self::Lambda(arg0) => f.debug_tuple("Lambda").field(arg0).finish(), + Self::Bool(arg0) => f.debug_tuple("Bool").field(arg0).finish(), + Self::Trap => write!(f, "Trap"), + } + } +} + impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { use Value::*; @@ -18,7 +34,9 @@ impl PartialEq for Value { (Num(l), Num(r)) => l == r, (Func(l), Func(r)) => *l as usize == *r as usize, (Bool(l), Bool(r)) => l == r, - (Lambda(l), Lambda(r)) => Rc::ptr_eq(&l.0, &r.0) && Rc::ptr_eq(&l.1, &r.1), + (Lambda(l), Lambda(r)) => { + Rc::ptr_eq(&l.func, &r.func) && Rc::ptr_eq(&l.captures, &r.captures) + } (Num(_), _) => false, (Func(_), _) => false, @@ -30,10 +48,10 @@ impl PartialEq for Value { } } -impl std::fmt::Debug for Value { +impl std::fmt::Display for Value { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Num(n) => n.fmt(f), + Self::Num(n) => std::fmt::Debug::fmt(n, f), // TODO: Change to displays Self::Func(_) => f.write_str("#"), Self::Lambda(_) => f.write_str("#"), Self::Bool(b) => f.write_str(if *b { "#t" } else { "#f" }), @@ -51,14 +69,11 @@ impl Value { } } - crate fn as_func(&self) -> Result { + crate fn as_func(self) -> Result { match self { - Self::Func(f) => Ok(eval::Callable::Func(*f)), + Self::Func(f) => Ok(eval::Callable::Func(f)), Self::Lambda(l) => Ok(eval::Callable::Lambda(l)), - _ => Err(eval::RTError(format!( - "Expected a function, got {:?}", - self - ))), + _ => Err(eval::RTError(format!("Expected a function, got {}", self))), } } -- 2.41.0 From 03fd228c9bdedf1fa5e0badfcb0649e1647f1df5 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Wed, 29 Dec 2021 02:09:34 +0000 Subject: [PATCH 2/4] Implement mutablility We'll need it eventually, and it lets me steal lox tests --- src/ast.rs | 1 + src/eval.rs | 17 + src/grammar.lalrpop | 1 + src/grammar.rs | 1223 +++++++++++++++++++++++++++---------------- src/tests.rs | 2 +- 5 files changed, 796 insertions(+), 448 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index d4029e6..6d99b4b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -5,6 +5,7 @@ use std::rc::Rc; crate enum Tree { Leaf(Literal), Define(String, Box), + Set(String, Box), If(Box<[Tree; 3]>), // Its easier to box the lambdas in the parser than the vm, as // here we see all of them exactly once diff --git a/src/eval.rs b/src/eval.rs index 5eaf1c6..fb4d850 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -70,6 +70,11 @@ pub(crate) fn eval(t: &ast::Tree, env: Rc>) -> Result { + 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, Rc::clone(&env))?.as_bool()?; let body = if b { tcase } else { fcase }; @@ -134,8 +139,20 @@ impl Env { 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 { diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 3aed6d9..b85479b 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -21,6 +21,7 @@ pub(crate) Tree: Tree = { => Tree::Define(name, Box::new(Tree::Func(Rc::new(Func{args, body})))), "(" "if" ")" => Tree::If(Box::new([<>])), "(" "lambda (" ")" ")" => Tree::Func(Rc::new(Func{<>})), + "(" "set!" ")" => Tree::Set(<>), Literal => Tree::Leaf(<>), } diff --git a/src/grammar.rs b/src/grammar.rs index dea8cd9..8b7d0b8 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -1,13 +1,13 @@ // auto-generated: "lalrpop 0.19.6" -// sha3: e06bc49958cb5e211ea88ac1ea9d95dffc9b12e0e8f9e43b4681a168821c +// 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 { @@ -39,114 +39,122 @@ mod __parse__File { } const __ACTION: &[i8] = &[ // State 0 - 28, 4, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 30, 4, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 1 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 2 - 28, 0, 29, 5, -31, 0, 0, 0, 0, 0, 30, 31, + 30, 0, 31, 5, -32, 0, 0, 0, 0, 0, 0, 32, 33, // State 3 - 0, 0, 0, 0, 0, 0, 0, 0, 35, 36, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 37, 38, 0, 0, 0, // State 4 - 28, 0, 29, 5, 0, 7, 8, 9, 0, 0, 30, 31, + 30, 0, 31, 5, 0, 7, 8, 9, 0, 0, 10, 32, 33, // State 5 - 28, 0, 29, 5, 37, 0, 0, 0, 0, 0, 30, 31, + 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, 31, + 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 33, // State 7 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 8 - 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 31, + 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 33, // State 9 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 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, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 11 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 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, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 13 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 33, // State 14 - 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 15 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 16 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 33, // State 17 - 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 18 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 19 - 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 30, 31, + 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 33, // State 20 - -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 21 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 30, 0, 31, 5, 0, 0, 0, 0, 0, 0, 0, 32, 33, // State 22 - -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, 0, -14, -14, // State 23 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 24 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, 0, -29, -29, // State 25 - -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, 0, -13, -13, // State 26 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, 0, -12, -12, // State 27 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, -30, -30, // State 28 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 29 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, 0, -3, -3, // State 30 - -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, -16, -16, + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, 0, -2, -2, // State 31 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, 0, -15, -15, // State 32 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, 0, -16, -16, // State 33 - -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, -7, -7, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 34 - -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, -11, -11, + -31, 0, -31, -31, -31, 0, 0, 0, 0, 0, 0, -31, -31, // State 35 - -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, -10, -10, + -7, 0, -7, -7, 0, 0, 0, 0, 0, 0, 0, -7, -7, // State 36 - -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, -21, -21, + -11, 0, -11, -11, 0, 0, 0, 0, 0, 0, 0, -11, -11, // State 37 - 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, -19, + -10, 0, -10, -10, 0, 0, 0, 0, 0, 0, 0, -10, -10, // State 38 - 0, 0, 0, 0, 44, 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, -1, 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, -4, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, // State 41 - 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, -20, + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, // State 42 - 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, // State 43 - -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, -22, -22, + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, 0, -20, // State 44 - 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, // State 45 - 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 0, // State 46 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, 0, -22, -22, // State 47 - 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, // State 48 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + 0, 0, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, // State 49 - -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, 0, -26, -26, // State 50 - 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, + -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, 0, -28, -28, // State 51 - -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, -23, -23, + 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, // State 52 - -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, -24, -24, + -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 @@ -154,7 +162,7 @@ mod __parse__File { // State 1 0, // State 2 - -31, + -32, // State 3 0, // State 4 @@ -190,43 +198,43 @@ mod __parse__File { // State 19 0, // State 20 - -14, + 0, // State 21 - -32, + 0, // State 22 - -28, + -14, // State 23 - -13, + -33, // State 24 - -12, - // State 25 -29, + // State 25 + -13, // State 26 - -6, + -12, // State 27 - -3, - // State 28 - -2, - // State 29 - -15, - // State 30 - -16, - // State 31 - -5, - // State 32 -30, + // State 28 + -6, + // State 29 + -3, + // State 30 + -2, + // State 31 + -15, + // State 32 + -16, // State 33 - 0, + -5, // State 34 - 0, + -31, // State 35 0, // State 36 - -21, + 0, // State 37 0, // State 38 - 0, + -21, // State 39 0, // State 40 @@ -236,66 +244,78 @@ mod __parse__File { // State 42 0, // State 43 - -22, + 0, // State 44 0, // State 45 0, // State 46 - -26, + -22, // State 47 0, // State 48 - -25, - // State 49 - -27, - // State 50 0, + // State 49 + -26, + // State 50 + -28, // State 51 - -23, + 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 => 38, - 1 => 20, - 2 => 39, - 3 => 21, + 0 => match state { + 15 => 45, + _ => 40, + }, + 1 => 22, + 2 => 41, + 3 => 23, 4 => 1, - 6 => 33, - 7 => 22, - 8 => 23, + 6 => 35, + 7 => 24, + 8 => 25, 9 => match state { - 6 => 9, - 10 => 14, - 8 | 14 => 37, - 12 | 17 => 41, - _ => 24, + 6 => 10, + 9 => 15, + 11 => 16, + 8 | 16 => 39, + 13 | 19 => 43, + _ => 26, }, 11 => match state { - 14 => 17, - _ => 12, + 16 => 19, + _ => 13, }, 12 => match state { - 7 => 11, - 11 => 15, - 2 | 5 => 32, - 9 => 40, - 15 => 44, - _ => 25, + 7 => 12, + 12 => 17, + 2 | 5 => 34, + 10 | 15 => 42, + 17 => 47, + _ => 27, }, 13 => match state { 4 => 5, _ => 2, }, 14 => match state { - 1 => 31, - 13 => 42, - 16 => 45, - 18 => 47, - 19 => 50, - _ => 26, + 1 => 33, + 14 => 44, + 18 => 48, + 20 => 51, + 21 => 54, + _ => 28, }, _ => 0, } @@ -312,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]*"#"###, ]; @@ -366,7 +387,7 @@ mod __parse__File { #[inline] fn error_action(&self, state: i8) -> i8 { - __action(state, 12 - 1) + __action(state, 13 - 1) } #[inline] @@ -440,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, } } @@ -455,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!(), @@ -602,6 +624,9 @@ mod __parse__File { __reduce30(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } 31 => { + __reduce31(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) + } + 32 => { // __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)); } - 32 => { - __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) + 33 => { + __reduce33(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } _ => panic!("invalid action code {}", __action) }; @@ -756,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) } @@ -774,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) } @@ -792,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) } @@ -810,11 +835,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Box = Tree => ActionFn(21); + // 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) } @@ -828,13 +853,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(30); + // 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::__action30::<>(input, __sym0, __sym1); + let __nt = super::__action31::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -848,11 +873,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(31); + // File = Trees => ActionFn(32); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action31::<>(input, __sym0); + let __nt = super::__action32::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -866,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) } @@ -886,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) } @@ -904,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) } @@ -921,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) } @@ -939,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) } @@ -957,11 +982,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Sym => ActionFn(11); + // 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) } @@ -975,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) } @@ -993,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) } @@ -1011,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) } @@ -1029,11 +1054,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); + // 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::__action14::<>(input, __sym0); + let __nt = super::__action15::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (1, 9) } @@ -1047,10 +1072,10 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym* = => ActionFn(22); + // 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::__action22::<>(input, &__start, &__end); + let __nt = super::__action23::<>(input, &__start, &__end); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (0, 10) } @@ -1064,11 +1089,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym* = Sym+ => ActionFn(23); + // Sym* = Sym+ => ActionFn(24); let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action23::<>(input, __sym0); + let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (1, 10) } @@ -1082,11 +1107,11 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym+ = Sym => ActionFn(28); + // Sym+ = Sym => ActionFn(29); let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action28::<>(input, __sym0); + let __nt = super::__action29::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (1, 11) } @@ -1100,13 +1125,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym+ = Sym+, Sym => ActionFn(29); + // Sym+ = Sym+, Sym => ActionFn(30); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant8(__symbols); let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action29::<>(input, __sym0, __sym1); + let __nt = super::__action30::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (2, 11) } @@ -1164,7 +1189,7 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(32); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(33); assert!(__symbols.len() >= 7); let __sym6 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant3(__symbols); @@ -1175,7 +1200,7 @@ mod __parse__File { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym6.2.clone(); - let __nt = super::__action32::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (7, 12) } @@ -1189,7 +1214,7 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(33); + // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(34); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant0(__symbols); let __sym6 = __pop_Variant3(__symbols); @@ -1201,7 +1226,7 @@ mod __parse__File { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym7.2.clone(); - let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); + let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (8, 12) } @@ -1239,7 +1264,7 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(34); + // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(35); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant3(__symbols); @@ -1248,7 +1273,7 @@ mod __parse__File { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); - let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (5, 12) } @@ -1262,7 +1287,7 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(35); + // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(36); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant3(__symbols); @@ -1272,7 +1297,7 @@ mod __parse__File { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + let __nt = super::__action36::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (6, 12) } @@ -1286,13 +1311,18 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = Literal => ActionFn(9); - let __sym0 = __pop_Variant6(__symbols); + // 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 = __sym0.2.clone(); - let __nt = super::__action9::<>(input, __sym0); + let __end = __sym4.2.clone(); + let __nt = super::__action9::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 12) + (5, 12) } pub(crate) fn __reduce28< 'input, @@ -1304,13 +1334,13 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree+ = Tree => ActionFn(24); - let __sym0 = __pop_Variant10(__symbols); + // Tree = Literal => ActionFn(10); + let __sym0 = __pop_Variant6(__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, 13) + let __nt = super::__action10::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } pub(crate) fn __reduce29< 'input, @@ -1322,17 +1352,35 @@ mod __parse__File { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree+ = Tree+, Tree => ActionFn(25); + // Tree+ = Tree => ActionFn(25); + let __sym0 = __pop_Variant10(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action25::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant3(__nt), __end)); + (1, 13) + } + pub(crate) fn __reduce30< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree+ = Tree+, Tree => ActionFn(26); assert!(__symbols.len() >= 2); 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, 13) } - pub(crate) fn __reduce30< + pub(crate) fn __reduce31< 'input, 's, >( @@ -1350,7 +1398,7 @@ mod __parse__File { __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 14) } - pub(crate) fn __reduce32< + pub(crate) fn __reduce33< 'input, 's, >( @@ -1401,100 +1449,108 @@ mod __parse__Tree { } const __ACTION: &[i8] = &[ // State 0 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 1 - 24, 0, 25, 2, 0, 4, 5, 6, 0, 0, 26, 27, + 26, 0, 27, 2, 0, 4, 5, 6, 0, 0, 7, 28, 29, // State 2 - 24, 0, 25, 2, 30, 0, 0, 0, 0, 0, 26, 27, + 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, 27, + 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 4 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 5 - 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 27, + 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 29, // State 6 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 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, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 8 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 9 - 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 10 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 29, // State 11 - 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 12 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 13 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 29, // State 14 - 24, 0, 25, 2, -31, 0, 0, 0, 0, 0, 26, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 15 - 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 27, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 16 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 26, 0, 27, 2, -32, 0, 0, 0, 0, 0, 0, 28, 29, // State 17 - 24, 0, 25, 2, 0, 0, 0, 0, 0, 0, 26, 27, + 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 29, // State 18 - -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 19 - -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, -28, -28, + 26, 0, 27, 2, 0, 0, 0, 0, 0, 0, 0, 28, 29, // State 20 - -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, -13, -13, + -14, 0, -14, -14, -14, 0, 0, 0, 0, 0, 0, -14, -14, // State 21 - -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, -12, -12, + -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, 0, -29, -29, // State 22 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -13, 0, -13, -13, -13, 0, 0, 0, 0, 0, 0, -13, -13, // State 23 - -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, -3, -3, + -12, 0, -12, -12, -12, 0, 0, 0, 0, 0, 0, -12, -12, // State 24 - -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, -2, -2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 25 - -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, -15, -15, + -3, 0, -3, -3, -3, 0, 0, 0, 0, 0, 0, -3, -3, // State 26 - -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, -16, -16, + -2, 0, -2, -2, -2, 0, 0, 0, 0, 0, 0, -2, -2, // State 27 - -29, 0, -29, -29, -29, 0, 0, 0, 0, 0, -29, -29, + -15, 0, -15, -15, -15, 0, 0, 0, 0, 0, 0, -15, -15, // State 28 - -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, -30, -30, + -16, 0, -16, -16, -16, 0, 0, 0, 0, 0, 0, -16, -16, // State 29 - -21, 0, -21, -21, -21, 0, 0, 0, 0, 0, -21, -21, + -30, 0, -30, -30, -30, 0, 0, 0, 0, 0, 0, -30, -30, // State 30 - 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, -19, + -31, 0, -31, -31, -31, 0, 0, 0, 0, 0, 0, -31, -31, // State 31 - 0, 0, 0, 0, 37, 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, -1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, 0, -19, // State 33 - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, // State 34 - 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, -20, + 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, // State 35 - 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, // State 36 - -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, -22, -22, + 0, 0, 0, 0, -20, 0, 0, 0, 0, 0, 0, 0, -20, // State 37 - 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, // State 38 - 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, // State 39 - -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, -26, -26, + -22, 0, -22, -22, -22, 0, 0, 0, 0, 0, 0, -22, -22, // State 40 - 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 0, // State 41 - -25, 0, -25, -25, -25, 0, 0, 0, 0, 0, -25, -25, + 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, // State 42 - -27, 0, -27, -27, -27, 0, 0, 0, 0, 0, -27, -27, + -26, 0, -26, -26, -26, 0, 0, 0, 0, 0, 0, -26, -26, // State 43 - 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, + -28, 0, -28, -28, -28, 0, 0, 0, 0, 0, 0, -28, -28, // State 44 - -23, 0, -23, -23, -23, 0, 0, 0, 0, 0, -23, -23, + 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, // State 45 - -24, 0, -24, -24, -24, 0, 0, 0, 0, 0, -24, -24, + -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 @@ -1534,33 +1590,33 @@ mod __parse__Tree { // State 17 0, // State 18 - -14, + 0, // State 19 - -28, + 0, // State 20 - -13, + -14, // State 21 - -12, + -29, // State 22 - -33, + -13, // State 23 - -3, + -12, // State 24 - -2, + -34, // State 25 - -15, + -3, // State 26 - -16, + -2, // State 27 - 0, + -15, // State 28 - 0, + -16, // State 29 - -21, + 0, // State 30 0, // State 31 - 0, + -21, // State 32 0, // State 33 @@ -1570,62 +1626,74 @@ mod __parse__Tree { // State 35 0, // State 36 - -22, + 0, // State 37 0, // State 38 0, // State 39 - -26, + -22, // State 40 0, // State 41 - -25, - // State 42 - -27, - // State 43 0, + // State 42 + -26, + // State 43 + -28, // State 44 - -23, + 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 => 31, - 1 => 18, - 2 => 32, - 7 => 19, - 8 => 20, + 0 => match state { + 12 => 38, + _ => 33, + }, + 1 => 20, + 2 => 34, + 7 => 21, + 8 => 22, 9 => match state { - 3 => 6, - 7 => 11, - 5 | 11 => 30, - 9 | 15 => 34, - _ => 21, + 3 => 7, + 6 => 12, + 8 => 13, + 5 | 13 => 32, + 10 | 17 => 36, + _ => 23, }, 11 => match state { - 11 => 15, - _ => 9, + 13 => 17, + _ => 10, }, 12 => match state { - 4 => 8, - 8 => 12, - 0 => 22, - 2 | 14 => 28, - 6 => 33, - 12 => 37, - _ => 27, + 4 => 9, + 9 => 14, + 0 => 24, + 2 | 16 => 30, + 7 | 12 => 35, + 14 => 40, + _ => 29, }, 13 => match state { 1 => 2, - _ => 14, + _ => 16, }, 14 => match state { - 13 => 38, - 16 => 40, - 17 => 43, - _ => 35, + 15 => 41, + 18 => 44, + 19 => 47, + _ => 37, }, _ => 0, } @@ -1642,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]*"#"###, ]; @@ -1696,7 +1765,7 @@ mod __parse__Tree { #[inline] fn error_action(&self, state: i8) -> i8 { - __action(state, 12 - 1) + __action(state, 13 - 1) } #[inline] @@ -1770,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, } } @@ -1785,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!(), @@ -1935,6 +2005,9 @@ mod __parse__Tree { __reduce31(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) } 32 => { + __reduce32(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) + } + 33 => { // __Tree = Tree => ActionFn(1); let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); @@ -2086,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) } @@ -2104,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) } @@ -2122,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) } @@ -2140,11 +2213,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Box = Tree => ActionFn(21); + // 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) } @@ -2158,13 +2231,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Lang, Trees => ActionFn(30); + // 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::__action30::<>(input, __sym0, __sym1); + let __nt = super::__action31::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (2, 3) } @@ -2178,11 +2251,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // File = Trees => ActionFn(31); + // File = Trees => ActionFn(32); let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action31::<>(input, __sym0); + let __nt = super::__action32::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 3) } @@ -2196,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) } @@ -2216,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) } @@ -2234,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) } @@ -2251,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) } @@ -2269,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) } @@ -2287,11 +2360,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Literal = Sym => ActionFn(11); + // 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) } @@ -2305,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) } @@ -2323,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) } @@ -2341,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) } @@ -2359,11 +2432,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(14); + // 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::__action14::<>(input, __sym0); + let __nt = super::__action15::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (1, 9) } @@ -2377,10 +2450,10 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym* = => ActionFn(22); + // 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::__action22::<>(input, &__start, &__end); + let __nt = super::__action23::<>(input, &__start, &__end); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (0, 10) } @@ -2394,11 +2467,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym* = Sym+ => ActionFn(23); + // Sym* = Sym+ => ActionFn(24); let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action23::<>(input, __sym0); + let __nt = super::__action24::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (1, 10) } @@ -2412,11 +2485,11 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym+ = Sym => ActionFn(28); + // Sym+ = Sym => ActionFn(29); let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action28::<>(input, __sym0); + let __nt = super::__action29::<>(input, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (1, 11) } @@ -2430,13 +2503,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Sym+ = Sym+, Sym => ActionFn(29); + // Sym+ = Sym+, Sym => ActionFn(30); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant8(__symbols); let __sym0 = __pop_Variant9(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action29::<>(input, __sym0, __sym1); + let __nt = super::__action30::<>(input, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (2, 11) } @@ -2494,7 +2567,7 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(32); + // Tree = "(", "define", "(", Sym, ")", Trees, ")" => ActionFn(33); assert!(__symbols.len() >= 7); let __sym6 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant3(__symbols); @@ -2505,7 +2578,7 @@ mod __parse__Tree { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym6.2.clone(); - let __nt = super::__action32::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (7, 12) } @@ -2519,7 +2592,7 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(33); + // Tree = "(", "define", "(", Sym, Sym+, ")", Trees, ")" => ActionFn(34); assert!(__symbols.len() >= 8); let __sym7 = __pop_Variant0(__symbols); let __sym6 = __pop_Variant3(__symbols); @@ -2531,7 +2604,7 @@ mod __parse__Tree { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym7.2.clone(); - let __nt = super::__action33::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); + let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (8, 12) } @@ -2569,7 +2642,7 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(34); + // Tree = "(", "lambda (", ")", Trees, ")" => ActionFn(35); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant3(__symbols); @@ -2578,7 +2651,7 @@ mod __parse__Tree { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); - let __nt = super::__action34::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); + let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (5, 12) } @@ -2592,7 +2665,7 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(35); + // Tree = "(", "lambda (", Sym+, ")", Trees, ")" => ActionFn(36); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant3(__symbols); @@ -2602,7 +2675,7 @@ mod __parse__Tree { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action35::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + let __nt = super::__action36::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (6, 12) } @@ -2616,13 +2689,18 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree = Literal => ActionFn(9); - let __sym0 = __pop_Variant6(__symbols); + // 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 = __sym0.2.clone(); - let __nt = super::__action9::<>(input, __sym0); + let __end = __sym4.2.clone(); + let __nt = super::__action9::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 12) + (5, 12) } pub(crate) fn __reduce28< 'input, @@ -2634,13 +2712,13 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree+ = Tree => ActionFn(24); - let __sym0 = __pop_Variant10(__symbols); + // Tree = Literal => ActionFn(10); + let __sym0 = __pop_Variant6(__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, 13) + let __nt = super::__action10::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 12) } pub(crate) fn __reduce29< 'input, @@ -2652,17 +2730,35 @@ mod __parse__Tree { _: core::marker::PhantomData<(&'input (), &'s ())>, ) -> (usize, usize) { - // Tree+ = Tree+, Tree => ActionFn(25); + // Tree+ = Tree => ActionFn(25); + let __sym0 = __pop_Variant10(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action25::<>(input, __sym0); + __symbols.push((__start, __Symbol::Variant3(__nt), __end)); + (1, 13) + } + pub(crate) fn __reduce30< + 'input, + 's, + >( + input: &'input str, + __lookahead_start: Option<&usize>, + __symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: core::marker::PhantomData<(&'input (), &'s ())>, + ) -> (usize, usize) + { + // Tree+ = Tree+, Tree => ActionFn(26); assert!(__symbols.len() >= 2); 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, 13) } - pub(crate) fn __reduce30< + pub(crate) fn __reduce31< 'input, 's, >( @@ -2680,7 +2776,7 @@ mod __parse__Tree { __symbols.push((__start, __Symbol::Variant3(__nt), __end)); (1, 14) } - pub(crate) fn __reduce31< + pub(crate) fn __reduce32< 'input, 's, >( @@ -2725,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), ]; @@ -2734,59 +2831,89 @@ 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), @@ -2796,12 +2923,16 @@ fn __action6<'input, 's>( (_, _, _): (usize, &'input str, usize), (_, body, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), -) -> Tree { - Tree::Define(name, Box::new(Tree::Func(Rc::new(Func { 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), @@ -2809,12 +2940,16 @@ 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), @@ -2822,191 +2957,337 @@ fn __action8<'input, 's>( (_, _, _): (usize, &'input str, usize), (_, body, _): (usize, alloc::vec::Vec, usize), (_, _, _): (usize, &'input str, usize), -) -> Tree { - Tree::Func(Rc::new(Func { - args: args, - body: body, - })) +) -> 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, __lookbehind: &usize, __lookahead: &usize, -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ alloc::vec![] } #[allow(unused_variables)] -fn __action23<'input, 's>( +fn __action24< + 'input, + 's, +>( input: &'input str, (_, v, _): (usize, alloc::vec::Vec, usize), -) -> alloc::vec::Vec { +) -> 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>( +fn __action29< + 'input, + 's, +>( input: &'input str, (_, __0, _): (usize, String, usize), -) -> alloc::vec::Vec { +) -> alloc::vec::Vec +{ alloc::vec![__0] } #[allow(unused_variables)] -fn __action29<'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 __action30<'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 __action31<'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 __action32<'input, 's>( +fn __action33< + 'input, + 's, +>( input: &'input str, __0: (usize, &'input str, usize), __1: (usize, &'input str, usize), @@ -3015,16 +3296,34 @@ fn __action32<'input, 's>( __4: (usize, &'input str, usize), __5: (usize, alloc::vec::Vec, usize), __6: (usize, &'input str, usize), -) -> Tree { +) -> Tree +{ let __start0 = __3.2.clone(); let __end0 = __4.0.clone(); - let __temp0 = __action22(input, &__start0, &__end0); + let __temp0 = __action23( + input, + &__start0, + &__end0, + ); let __temp0 = (__start0, __temp0, __end0); - __action6(input, __0, __1, __2, __3, __temp0, __4, __5, __6) + __action6( + input, + __0, + __1, + __2, + __3, + __temp0, + __4, + __5, + __6, + ) } #[allow(unused_variables)] -fn __action33<'input, 's>( +fn __action34< + 'input, + 's, +>( input: &'input str, __0: (usize, &'input str, usize), __1: (usize, &'input str, usize), @@ -3034,32 +3333,65 @@ fn __action33<'input, 's>( __5: (usize, &'input str, usize), __6: (usize, alloc::vec::Vec, usize), __7: (usize, &'input str, usize), -) -> Tree { +) -> Tree +{ let __start0 = __4.0.clone(); let __end0 = __4.2.clone(); - let __temp0 = __action23(input, __4); + let __temp0 = __action24( + input, + __4, + ); let __temp0 = (__start0, __temp0, __end0); - __action6(input, __0, __1, __2, __3, __temp0, __5, __6, __7) + __action6( + input, + __0, + __1, + __2, + __3, + __temp0, + __5, + __6, + __7, + ) } #[allow(unused_variables)] -fn __action34<'input, 's>( +fn __action35< + 'input, + 's, +>( input: &'input str, __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 { +) -> Tree +{ let __start0 = __1.2.clone(); let __end0 = __2.0.clone(); - let __temp0 = __action22(input, &__start0, &__end0); + let __temp0 = __action23( + input, + &__start0, + &__end0, + ); let __temp0 = (__start0, __temp0, __end0); - __action8(input, __0, __1, __temp0, __2, __3, __4) + __action8( + input, + __0, + __1, + __temp0, + __2, + __3, + __4, + ) } #[allow(unused_variables)] -fn __action35<'input, 's>( +fn __action36< + 'input, + 's, +>( input: &'input str, __0: (usize, &'input str, usize), __1: (usize, &'input str, usize), @@ -3067,40 +3399,37 @@ fn __action35<'input, 's>( __3: (usize, &'input str, usize), __4: (usize, alloc::vec::Vec, usize), __5: (usize, &'input str, usize), -) -> Tree { +) -> Tree +{ let __start0 = __2.0.clone(); let __end0 = __2.2.clone(); - let __temp0 = __action23(input, __2); + let __temp0 = __action24( + input, + __2, + ); let __temp0 = (__start0, __temp0, __end0); - __action8(input, __0, __1, __temp0, __3, __4, __5) + __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/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() -- 2.41.0 From 2338430e0acb38b5c95c15b889631d395ee5d4a7 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Wed, 29 Dec 2021 02:09:51 +0000 Subject: [PATCH 3/4] Many closure tests, mainly from lox --- README.md | 3 ++ ...tests__run-pass@4-1-6-Assignments.scm.snap | 7 ++++ ...__tests__run-pass@assign-closures.scm.snap | 11 +++++++ ...s__run-pass@assign-shadowed-later.scm.snap | 9 ++++++ ...ball__tests__run-pass@bagel-donut.scm.snap | 9 ++++++ ...un-pass@close-over-function-param.scm.snap | 7 ++++ ...un-pass@close-over-later-variable.scm.snap | 8 +++++ ...all__tests__run-pass@close-unused.scm.snap | 7 ++++ ...n-pass@closed-closure-in-function.scm.snap | 7 ++++ ...andball__tests__run-pass@gnarly-i.scm.snap | 10 ++++++ ...ll__tests__run-pass@mutate-levels.scm.snap | 13 ++++++++ ...ll__tests__run-pass@nested-assign.scm.snap | 7 ++++ ...l__tests__run-pass@nested-closure.scm.snap | 10 ++++++ ...s@objects-are-a-poor-mans-closure.scm.snap | 20 ++++++++++++ ...run-pass@open-closure-in-function.scm.snap | 7 ++++ ...@reference-closure-multiple-times.scm.snap | 8 +++++ ...ests__run-pass@reuse-closure-slot.scm.snap | 7 ++++ .../handball__tests__run-pass@scope.scm.snap | 9 ++++++ ...un-pass@shadow-closure-with-local.scm.snap | 9 ++++++ ...s__run-pass@unused-later-closures.scm.snap | 8 +++++ ...__tests__run-pass@use-after-close.scm.snap | 7 ++++ ...dball__tests__run-pass@val-or-var.scm.snap | 9 ++++++ src/test/run-pass/closure/assign-closures.scm | 26 +++++++++++++++ .../closure/assign-shadowed-later.scm | 16 ++++++++++ src/test/run-pass/closure/bagel-donut.scm | 11 +++++++ .../closure/close-over-function-param.scm | 9 ++++++ .../closure/close-over-later-variable.scm | 14 ++++++++ src/test/run-pass/closure/close-unused.scm | 10 ++++++ .../closure/closed-closure-in-function.scm | 11 +++++++ src/test/run-pass/closure/gnarly-i.scm | 19 +++++++++++ src/test/run-pass/closure/mutate-levels.scm | 20 ++++++++++++ src/test/run-pass/closure/nested-assign.scm | 7 ++++ src/test/run-pass/closure/nested-closure.scm | 25 +++++++++++++++ .../objects-are-a-poor-mans-closure.scm | 32 +++++++++++++++++++ .../closure/open-closure-in-function.scm | 9 ++++++ .../reference-closure-multiple-times.scm | 16 ++++++++++ .../run-pass/closure/reuse-closure-slot.scm | 14 ++++++++ src/test/run-pass/closure/scope.scm | 9 ++++++ .../closure/shadow-closure-with-local.scm | 14 ++++++++ .../closure/unused-later-closures.scm | 25 +++++++++++++++ src/test/run-pass/closure/use-after-close.scm | 8 +++++ src/test/run-pass/closure/val-or-var.scm | 17 ++++++++++ .../run-pass/r7rs-spec/4-1-6-Assignments.scm | 4 +++ 43 files changed, 508 insertions(+) create mode 100644 README.md create mode 100644 src/snapshots/handball__tests__run-pass@4-1-6-Assignments.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@assign-closures.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@assign-shadowed-later.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@bagel-donut.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@close-over-function-param.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@close-over-later-variable.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@close-unused.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@closed-closure-in-function.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@gnarly-i.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@mutate-levels.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@nested-assign.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@nested-closure.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@objects-are-a-poor-mans-closure.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@open-closure-in-function.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@reference-closure-multiple-times.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@reuse-closure-slot.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@scope.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@shadow-closure-with-local.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@unused-later-closures.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@use-after-close.scm.snap create mode 100644 src/snapshots/handball__tests__run-pass@val-or-var.scm.snap create mode 100644 src/test/run-pass/closure/assign-closures.scm create mode 100644 src/test/run-pass/closure/assign-shadowed-later.scm create mode 100644 src/test/run-pass/closure/bagel-donut.scm create mode 100644 src/test/run-pass/closure/close-over-function-param.scm create mode 100644 src/test/run-pass/closure/close-over-later-variable.scm create mode 100644 src/test/run-pass/closure/close-unused.scm create mode 100644 src/test/run-pass/closure/closed-closure-in-function.scm create mode 100644 src/test/run-pass/closure/gnarly-i.scm create mode 100644 src/test/run-pass/closure/mutate-levels.scm create mode 100644 src/test/run-pass/closure/nested-assign.scm create mode 100644 src/test/run-pass/closure/nested-closure.scm create mode 100644 src/test/run-pass/closure/objects-are-a-poor-mans-closure.scm create mode 100644 src/test/run-pass/closure/open-closure-in-function.scm create mode 100644 src/test/run-pass/closure/reference-closure-multiple-times.scm create mode 100644 src/test/run-pass/closure/reuse-closure-slot.scm create mode 100644 src/test/run-pass/closure/scope.scm create mode 100644 src/test/run-pass/closure/shadow-closure-with-local.scm create mode 100644 src/test/run-pass/closure/unused-later-closures.scm create mode 100644 src/test/run-pass/closure/use-after-close.scm create mode 100644 src/test/run-pass/closure/val-or-var.scm create mode 100644 src/test/run-pass/r7rs-spec/4-1-6-Assignments.scm 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/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@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@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@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/closure/assign-closures.scm b/src/test/run-pass/closure/assign-closures.scm new file mode 100644 index 0000000..ca65638 --- /dev/null +++ b/src/test/run-pass/closure/assign-closures.scm @@ -0,0 +1,26 @@ +; 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) \ No newline at end of file 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..b8986b5 --- /dev/null +++ b/src/test/run-pass/closure/assign-shadowed-later.scm @@ -0,0 +1,16 @@ +; 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) \ No newline at end of file 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..b40e8c5 --- /dev/null +++ b/src/test/run-pass/closure/bagel-donut.scm @@ -0,0 +1,11 @@ +(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) \ No newline at end of file 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..ed6c9a9 --- /dev/null +++ b/src/test/run-pass/closure/close-over-function-param.scm @@ -0,0 +1,9 @@ +(define f #f) + +(define (foo param) + (define (f_) (display param)) + (set! f f_)) + +(foo 77) + +(f) \ No newline at end of file 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..81370e8 --- /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) \ No newline at end of file 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..b237a89 --- /dev/null +++ b/src/test/run-pass/closure/close-unused.scm @@ -0,0 +1,10 @@ +((lambda () + (define a 1) + + (if #f + (lambda () a) + 0 + ) +)) + +(display 7) \ No newline at end of file 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..3c9874e --- /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) \ No newline at end of file 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..870b38d --- /dev/null +++ b/src/test/run-pass/closure/gnarly-i.scm @@ -0,0 +1,19 @@ +#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) \ No newline at end of file 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..d43ccbf --- /dev/null +++ b/src/test/run-pass/closure/mutate-levels.scm @@ -0,0 +1,20 @@ +(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..df1a580 --- /dev/null +++ b/src/test/run-pass/closure/nested-assign.scm @@ -0,0 +1,7 @@ +(define (outer) + (define x 0) + (define (y) (set! x 1)) + (y) + (display x)) + +(outer) \ No newline at end of file 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..c0f58cb --- /dev/null +++ b/src/test/run-pass/closure/nested-closure.scm @@ -0,0 +1,25 @@ +; 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) \ No newline at end of file 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..2e4e182 --- /dev/null +++ b/src/test/run-pass/closure/objects-are-a-poor-mans-closure.scm @@ -0,0 +1,32 @@ +#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) \ No newline at end of file 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..a261912 --- /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))) \ No newline at end of file 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..2a41c5e --- /dev/null +++ b/src/test/run-pass/closure/reference-closure-multiple-times.scm @@ -0,0 +1,16 @@ +#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..44f1d73 --- /dev/null +++ b/src/test/run-pass/closure/reuse-closure-slot.scm @@ -0,0 +1,14 @@ +#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..12c1842 --- /dev/null +++ b/src/test/run-pass/closure/scope.scm @@ -0,0 +1,9 @@ +(define x 2) + +(define (displayln x) (display x) (newline)) + +(define (gy y) x) +(define (gx x) x) + +(displayln (gx 7)) +(displayln (gy 7)) \ No newline at end of file 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..6a8b94b --- /dev/null +++ b/src/test/run-pass/closure/shadow-closure-with-local.scm @@ -0,0 +1,14 @@ +; 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))) \ No newline at end of file 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..8ed1c15 --- /dev/null +++ b/src/test/run-pass/closure/unused-later-closures.scm @@ -0,0 +1,25 @@ +(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..e6f91e9 --- /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..cc40067 --- /dev/null +++ b/src/test/run-pass/closure/val-or-var.scm @@ -0,0 +1,17 @@ +(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) \ No newline at end of file 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)) -- 2.41.0 From a7e44f432cb3e6fb240a0899771eac5df8756925 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Wed, 29 Dec 2021 02:32:43 +0000 Subject: [PATCH 4/4] /src/test/run-pass$ ~/pres/racket/bin/raco fmt -i **/*.scm --- src/test/run-pass/ambig-scope.scm | 12 +++++--- src/test/run-pass/capture.scm | 9 +++--- src/test/run-pass/closure/assign-closures.scm | 30 ++++++++++--------- .../closure/assign-shadowed-later.scm | 19 ++++++------ src/test/run-pass/closure/bagel-donut.scm | 11 ++++--- .../closure/close-over-function-param.scm | 7 +++-- .../closure/close-over-later-variable.scm | 16 +++++----- src/test/run-pass/closure/close-unused.scm | 10 ++----- .../closure/closed-closure-in-function.scm | 10 +++---- src/test/run-pass/closure/gnarly-i.scm | 23 +++++++------- src/test/run-pass/closure/mutate-levels.scm | 24 ++++++++------- src/test/run-pass/closure/nested-assign.scm | 11 +++---- src/test/run-pass/closure/nested-closure.scm | 9 +++--- .../objects-are-a-poor-mans-closure.scm | 25 +++++++++++----- .../closure/open-closure-in-function.scm | 6 ++-- .../reference-closure-multiple-times.scm | 2 -- .../run-pass/closure/reuse-closure-slot.scm | 3 +- src/test/run-pass/closure/scope.scm | 12 +++++--- .../closure/shadow-closure-with-local.scm | 11 +++---- .../closure/unused-later-closures.scm | 24 ++++++--------- src/test/run-pass/closure/use-after-close.scm | 10 +++---- src/test/run-pass/closure/val-or-var.scm | 16 +++++----- src/test/run-pass/curry.scm | 7 +++-- src/test/run-pass/fib.scm | 29 +++++++++++------- src/test/run-pass/funcs.scm | 9 ++++-- src/test/run-pass/lambda-calc.scm | 30 +++++++++++-------- src/test/run-pass/multi.scm | 7 +++-- src/test/run-pass/nested-defs.scm | 11 ++++--- src/test/run-pass/sqrt.scm | 11 ++++--- 29 files changed, 226 insertions(+), 178 deletions(-) diff --git a/src/test/run-pass/ambig-scope.scm b/src/test/run-pass/ambig-scope.scm index 055e8ac..57a27ff 100644 --- a/src/test/run-pass/ambig-scope.scm +++ b/src/test/run-pass/ambig-scope.scm @@ -1,18 +1,22 @@ #lang scheme -(define (displayln x) (newline) (display x)) +(define (displayln x) + (newline) + (display x)) -(define (ambig1 x) (lambda (x) x)) +(define (ambig1 x) + (lambda (x) x)) (displayln ((ambig1 13) 42)) (define (ambig2 a) (displayln a) (define a- a) - (lambda (b) (displayln b) + (lambda (b) + (displayln b) (lambda (a) (displayln a) (displayln b) (displayln a-)))) -(((ambig2 1) 2) 3) \ No newline at end of file +(((ambig2 1) 2) 3) diff --git a/src/test/run-pass/capture.scm b/src/test/run-pass/capture.scm index bbf6c99..83898ef 100644 --- a/src/test/run-pass/capture.scm +++ b/src/test/run-pass/capture.scm @@ -1,12 +1,13 @@ #lang scheme -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) - -(define (const x) (lambda () x)) +(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 index ca65638..69895e4 100644 --- a/src/test/run-pass/closure/assign-closures.scm +++ b/src/test/run-pass/closure/assign-closures.scm @@ -3,24 +3,26 @@ (define f #f) (define g #f) -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) ((lambda () - (define local 1) - - (define (f_) - (displayln local) - (set! local 2) - (displayln local)) + (define local 1) - (set! f f_) + (define (f_) + (displayln local) + (set! local 2) + (displayln local)) - (define (g_) - (displayln local) - (set! local 3) - (displayln local)) + (set! f f_) - (set! g g_))) + (define (g_) + (displayln local) + (set! local 3) + (displayln local)) + + (set! g g_))) (f) -(g) \ No newline at end of file +(g) diff --git a/src/test/run-pass/closure/assign-shadowed-later.scm b/src/test/run-pass/closure/assign-shadowed-later.scm index b8986b5..5a4275c 100644 --- a/src/test/run-pass/closure/assign-shadowed-later.scm +++ b/src/test/run-pass/closure/assign-shadowed-later.scm @@ -2,15 +2,16 @@ (define a 0) -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) +((lambda () + (define (assign) + (set! a 1)) -((lambda () - (define (assign) (set! a 1)) + (define a 2) + (assign) + (displayln a))) - (define a 2) - (assign) - (displayln a) -)) - -(displayln a) \ No newline at end of file +(displayln a) diff --git a/src/test/run-pass/closure/bagel-donut.scm b/src/test/run-pass/closure/bagel-donut.scm index b40e8c5..ac06159 100644 --- a/src/test/run-pass/closure/bagel-donut.scm +++ b/src/test/run-pass/closure/bagel-donut.scm @@ -1,11 +1,14 @@ -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) (define (make-print x) - (define (print) (displayln x)) - print) + (define (print) + (displayln x)) + print) (define print-2 (make-print 2)) (define print-4 (make-print 4)) (print-4) -(print-2) \ No newline at end of file +(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 index ed6c9a9..df024aa 100644 --- a/src/test/run-pass/closure/close-over-function-param.scm +++ b/src/test/run-pass/closure/close-over-function-param.scm @@ -1,9 +1,10 @@ (define f #f) (define (foo param) - (define (f_) (display param)) - (set! f f_)) + (define (f_) + (display param)) + (set! f f_)) (foo 77) -(f) \ No newline at end of file +(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 index 81370e8..9a1a978 100644 --- a/src/test/run-pass/closure/close-over-later-variable.scm +++ b/src/test/run-pass/closure/close-over-later-variable.scm @@ -1,14 +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 a 1) + (define b 2) - (define (g) - (display b) - (newline) - (display a)) + (define (g) + (display b) + (newline) + (display a)) - (g)) + (g)) -(f) \ No newline at end of file +(f) diff --git a/src/test/run-pass/closure/close-unused.scm b/src/test/run-pass/closure/close-unused.scm index b237a89..ab70eb0 100644 --- a/src/test/run-pass/closure/close-unused.scm +++ b/src/test/run-pass/closure/close-unused.scm @@ -1,10 +1,6 @@ ((lambda () - (define a 1) + (define a 1) - (if #f - (lambda () a) - 0 - ) -)) + (if #f (lambda () a) 0))) -(display 7) \ No newline at end of file +(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 index 3c9874e..11d8dd0 100644 --- a/src/test/run-pass/closure/closed-closure-in-function.scm +++ b/src/test/run-pass/closure/closed-closure-in-function.scm @@ -3,9 +3,9 @@ (define f #f) ((lambda () - (define local 1) - (define (f_) (display local)) - (set! f f_) -)) + (define local 1) + (define (f_) + (display local)) + (set! f f_))) -(f) \ No newline at end of file +(f) diff --git a/src/test/run-pass/closure/gnarly-i.scm b/src/test/run-pass/closure/gnarly-i.scm index 870b38d..6190093 100644 --- a/src/test/run-pass/closure/gnarly-i.scm +++ b/src/test/run-pass/closure/gnarly-i.scm @@ -1,19 +1,22 @@ #lang scheme -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) (define (outer) - (define x 1) - - (define (middle) - (define (inner) (displayln x)) - (displayln 2) - inner) + (define x 1) - (displayln 3) + (define (middle) + (define (inner) + (displayln x)) + (displayln 2) + inner) - middle) + (displayln 3) + + middle) (define mid (outer)) (define in (mid)) -(in) \ No newline at end of file +(in) diff --git a/src/test/run-pass/closure/mutate-levels.scm b/src/test/run-pass/closure/mutate-levels.scm index d43ccbf..61f7d3d 100644 --- a/src/test/run-pass/closure/mutate-levels.scm +++ b/src/test/run-pass/closure/mutate-levels.scm @@ -1,20 +1,24 @@ (define x 2) -(define (show-x) (display x) (newline)) +(define (show-x) + (display x) + (newline)) (show-x) (set! x 3) (show-x) ((lambda () - (define x 7) - (show-x) - (set! x 8) - (show-x))) + (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))) + (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 index df1a580..5bd5b1e 100644 --- a/src/test/run-pass/closure/nested-assign.scm +++ b/src/test/run-pass/closure/nested-assign.scm @@ -1,7 +1,8 @@ (define (outer) - (define x 0) - (define (y) (set! x 1)) - (y) - (display x)) + (define x 0) + (define (y) + (set! x 1)) + (y) + (display x)) -(outer) \ No newline at end of file +(outer) diff --git a/src/test/run-pass/closure/nested-closure.scm b/src/test/run-pass/closure/nested-closure.scm index c0f58cb..9e84874 100644 --- a/src/test/run-pass/closure/nested-closure.scm +++ b/src/test/run-pass/closure/nested-closure.scm @@ -1,12 +1,13 @@ ; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/nested_closure.lox #lang scheme - -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) (define f #f) -(define (f1) +(define (f1) (define a 1) (define (f2) (define b 2) @@ -22,4 +23,4 @@ (f1) -(f) \ No newline at end of file +(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 index 2e4e182..0a00e31 100644 --- 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 @@ -5,18 +5,29 @@ (define do-print 3) (define add 4) -(define (displayln x) (display x) (newline)) +(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)))))))) + (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)) @@ -29,4 +40,4 @@ (v-8-2 do-print) (define v-9-9 ((v-8-2 add) v-1-7)) -(v-9-9 do-print) \ No newline at end of file +(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 index a261912..904424e 100644 --- a/src/test/run-pass/closure/open-closure-in-function.scm +++ b/src/test/run-pass/closure/open-closure-in-function.scm @@ -2,8 +2,8 @@ ; https://github.com/munificent/craftinginterpreters/blob/master/test/closure/open_closure_in_function.lox - ((lambda () (define local 1) - (define (f) (display local)) - (f))) \ No newline at end of file + (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 index 2a41c5e..71ce1d7 100644 --- a/src/test/run-pass/closure/reference-closure-multiple-times.scm +++ b/src/test/run-pass/closure/reference-closure-multiple-times.scm @@ -12,5 +12,3 @@ (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 index 44f1d73..d963162 100644 --- a/src/test/run-pass/closure/reuse-closure-slot.scm +++ b/src/test/run-pass/closure/reuse-closure-slot.scm @@ -6,7 +6,8 @@ (define f #f) ((lambda () (define a 1) - (define (f_) (display a)) + (define (f_) + (display a)) (set! f f_))) ((lambda () diff --git a/src/test/run-pass/closure/scope.scm b/src/test/run-pass/closure/scope.scm index 12c1842..7c636b8 100644 --- a/src/test/run-pass/closure/scope.scm +++ b/src/test/run-pass/closure/scope.scm @@ -1,9 +1,13 @@ (define x 2) -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) -(define (gy y) x) -(define (gx x) x) +(define (gy y) + x) +(define (gx x) + x) (displayln (gx 7)) -(displayln (gy 7)) \ No newline at end of file +(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 index 6a8b94b..2d19f4e 100644 --- a/src/test/run-pass/closure/shadow-closure-with-local.scm +++ b/src/test/run-pass/closure/shadow-closure-with-local.scm @@ -1,14 +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)) +(define (displayln x) + (display x) + (newline)) ((lambda () (define foo 0) - (define (f) + (define (f) ((lambda () (displayln foo) (define foo 1) - (displayln foo)))) - (f))) \ No newline at end of file + (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 index 8ed1c15..e556b15 100644 --- a/src/test/run-pass/closure/unused-later-closures.scm +++ b/src/test/run-pass/closure/unused-later-closures.scm @@ -1,25 +1,19 @@ (define closure #f) ((lambda () - (define a 1) + (define a 1) + ((lambda () + (define b 2) - ((lambda () - (define b 2) + (define (get-a) + a) - (define (get-a) a) + (set! closure get-a) - (set! closure get-a) + (if #f (lambda () b) 0))) - (if #f - (lambda () b) - 0) - - )) - - (display (closure)) - -)) + (display (closure)))) (newline) - (display (closure)) +(display (closure)) diff --git a/src/test/run-pass/closure/use-after-close.scm b/src/test/run-pass/closure/use-after-close.scm index e6f91e9..355c468 100644 --- a/src/test/run-pass/closure/use-after-close.scm +++ b/src/test/run-pass/closure/use-after-close.scm @@ -1,8 +1,8 @@ (define (outer) - (define x 1) - (define (inner) (display x)) - inner) + (define x 1) + (define (inner) + (display x)) + inner) (define clousre (outer)) -(clousre) - +(clousre) diff --git a/src/test/run-pass/closure/val-or-var.scm b/src/test/run-pass/closure/val-or-var.scm index cc40067..2404e4d 100644 --- a/src/test/run-pass/closure/val-or-var.scm +++ b/src/test/run-pass/closure/val-or-var.scm @@ -2,16 +2,18 @@ (define globalGet #f) (define (main) - (define a 0) + (define a 0) - (define (set) (set! a 1)) - (define (get) (display a) (newline)) + (define (set) + (set! a 1)) + (define (get) + (display a) + (newline)) - (set! globalSet set) - (set! globalGet get) -) + (set! globalSet set) + (set! globalGet get)) (main) (globalGet) (globalSet) -(globalGet) \ No newline at end of file +(globalGet) diff --git a/src/test/run-pass/curry.scm b/src/test/run-pass/curry.scm index c5bac77..7fd510d 100644 --- a/src/test/run-pass/curry.scm +++ b/src/test/run-pass/curry.scm @@ -1,7 +1,10 @@ #lang scheme -(define (displayln x) (display x) (newline)) +(define (displayln x) + (display x) + (newline)) -(define (curry2 f) (lambda (l) (lambda (r) (f l r)))) +(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/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)) -- 2.41.0