mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 09:15:32 +01:00
Moving to TCO
This commit is contained in:
29
src/eval.rs
29
src/eval.rs
@ -176,20 +176,26 @@ mod tests {
|
||||
|
||||
use crate::env::Env;
|
||||
|
||||
macro_rules! load {
|
||||
macro_rules! load2 {
|
||||
($input:expr) => {{
|
||||
use crate::env::cdr;
|
||||
use crate::reader::{read_str, Reader};
|
||||
|
||||
let r = Reader::new();
|
||||
r.push($input);
|
||||
cdr(&match read_str(&r) {
|
||||
&match read_str(&r) {
|
||||
Ok(v) => match v {
|
||||
MalType::List(v) => v,
|
||||
_ => panic!("Bad command"),
|
||||
_ => panic!("Not a list"),
|
||||
},
|
||||
_ => panic!("Bad command"),
|
||||
})
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! load {
|
||||
($input:expr) => {{
|
||||
use crate::env::cdr;
|
||||
cdr(load2!($input))
|
||||
}};
|
||||
}
|
||||
|
||||
@ -232,7 +238,8 @@ mod tests {
|
||||
use crate::env::env_get;
|
||||
use crate::eval::tests::_env_empty;
|
||||
use crate::eval::{
|
||||
def_bang_form, do_form, eval_ast, eval_func, fn_star_form, if_form, let_star_form,
|
||||
apply, def_bang_form, do_form, eval_ast, eval_func, fn_star_form, if_form,
|
||||
let_star_form,
|
||||
};
|
||||
use crate::types::MalType;
|
||||
|
||||
@ -396,5 +403,15 @@ mod tests {
|
||||
Ok(MalType::Int(1))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn _apply() {
|
||||
let env = _env_empty();
|
||||
assert!(matches!(
|
||||
apply(load2!("(def! a 1)"), env.clone()),
|
||||
Ok(MalType::Int(1))
|
||||
));
|
||||
assert!(matches!(env_get(&env, "a"), Ok(MalType::Int(1))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ mod mal_tests;
|
||||
mod parse_tools;
|
||||
mod printer;
|
||||
mod reader;
|
||||
mod step4_if_fn_do;
|
||||
mod step5_tco;
|
||||
mod types;
|
||||
|
||||
use core::ns_init;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::env::Env;
|
||||
use crate::reader::Reader;
|
||||
use crate::step4_if_fn_do::rep;
|
||||
use crate::step5_tco::rep;
|
||||
use crate::types::{MalErr, MalRet, MalType::Nil};
|
||||
use regex::Regex;
|
||||
use std::fs::File;
|
||||
|
||||
Reference in New Issue
Block a user