Fix assign; make reduced ir test pass

This commit is contained in:
Greg Shuflin 2021-10-24 22:55:12 -07:00
parent 856a0808de
commit 630420b114
3 changed files with 12 additions and 5 deletions

View File

@ -38,5 +38,6 @@ fn test_ir() {
"#;
let reduced = build_ir(src);
assert!(1 == 2);
assert_eq!(reduced.functions.len(), 3);
//assert!(1 == 2);
}

View File

@ -130,6 +130,12 @@ enum Primitive {
*/
}
impl Primitive {
fn unit() -> Self {
Primitive::Tuple(vec![])
}
}
impl From<Literal> for Primitive {
fn from(lit: Literal) -> Self {
Primitive::Literal(lit)
@ -240,9 +246,9 @@ impl<'a> State<'a> {
},
Expression::Assign { ref lval, box rval } => {
let mem = lval.into();
let _ = rval;
let _env = self.environments.lookup(&mem);
return Err("Assign not implemented".into());
let evaluated = self.expression(rval)?;
self.environments.insert(mem, RuntimeValue::Primitive(evaluated));
Primitive::unit()
},
Expression::Call { box f, args } => self.call_expression(f, args)?,
Expression::Callable(func) => Primitive::Callable(func),

View File

@ -20,7 +20,7 @@ fn eval_assert(input: &str, expected: &str) {
#[test]
fn test_basic_eval() {
eval_assert("1 + 2", "3");
//eval_assert("let mut a = 1; a = 2", "()");
eval_assert("let mut a = 1; a = 2", "()");
/*
test_in_fresh_env!("let mut a = 1; a = 2; a", "2");
test_in_fresh_env!(r#"("a", 1 + 2)"#, r#"("a", 3)"#);