diff --git a/src/lem/eval.rs b/src/lem/eval.rs index 6d432c0b94..ea5d8e8e24 100644 --- a/src/lem/eval.rs +++ b/src/lem/eval.rs @@ -831,8 +831,7 @@ fn reduce(cprocs: &[(&Symbol, usize)]) -> Func { } return (expr, smaller_env, not_found, binding) } - // This is a hack to signal that the binding came from a letrec - Expr::Thunk => { + Expr::RecVar => { let eq_val = eq_val(var, expr); if eq_val { return (val, env, rec, binding) @@ -1299,8 +1298,8 @@ fn apply_cont(cprocs: &[(&Symbol, usize)], ivc: bool) -> Func { } Cont::LetRec => { let (var, saved_env, body, cont) = decons4(cont); - // This is a hack to signal that the binding came from a letrec - let var = cast(var, Expr::Thunk); + // Since the variable came from a letrec, it is a recursive variable + let var = cast(var, Expr::RecVar); let binding: Expr::Cons = cons2(var, result); let extended_env: Expr::Cons = cons2(binding, saved_env); return (body, extended_env, cont, ret) @@ -1746,8 +1745,8 @@ mod tests { expected.assert_eq(&computed.to_string()); }; expect_eq(cs.num_inputs(), expect!["1"]); - expect_eq(cs.aux().len(), expect!["8883"]); - expect_eq(cs.num_constraints(), expect!["10830"]); + expect_eq(cs.aux().len(), expect!["8884"]); + expect_eq(cs.num_constraints(), expect!["10831"]); assert_eq!(func.num_constraints(&store), cs.num_constraints()); } } diff --git a/src/lem/store.rs b/src/lem/store.rs index 9f732f2efc..dd29c05e1a 100644 --- a/src/lem/store.rs +++ b/src/lem/store.rs @@ -23,7 +23,7 @@ use crate::{ self, Binop, Binop2, Call, Call0, Call2, Dummy, Emit, If, Let, LetRec, Lookup, Outermost, Tail, Terminal, Unop, }, - tag::ExprTag::{Char, Comm, Cons, Cproc, Fun, Key, Nil, Num, Str, Sym, Thunk, U64}, + tag::ExprTag::{Char, Comm, Cons, Cproc, Fun, Key, Nil, Num, RecVar, Str, Sym, Thunk, U64}, }; use super::pointers::{Ptr, RawPtr, ZPtr}; @@ -1004,6 +1004,13 @@ impl Ptr { "".into() } } + RecVar => { + if let Some(sym) = store.fetch_sym(&self.cast(Tag::Expr(Sym))) { + state.fmt_to_string(&sym.into()) + } else { + "".into() + } + } Key => { if let Some(key) = store.fetch_key(self) { state.fmt_to_string(&key.into()) diff --git a/src/tag.rs b/src/tag.rs index af2bc41673..bf6a644c1a 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -51,6 +51,7 @@ pub enum ExprTag { U64, Key, Cproc, + RecVar, } impl From for u16 { @@ -80,6 +81,7 @@ impl fmt::Display for ExprTag { ExprTag::Comm => write!(f, "comm#"), ExprTag::U64 => write!(f, "u64#"), ExprTag::Cproc => write!(f, "cproc#"), + ExprTag::RecVar => write!(f, "rec_var#"), } } }