diff --git a/src/lem/circuit.rs b/src/lem/circuit.rs index 181072d301..62e93230b1 100644 --- a/src/lem/circuit.rs +++ b/src/lem/circuit.rs @@ -665,8 +665,8 @@ impl Func { // Retrieve preimage hashes and tags create the full preimage pointers // and add them to bound allocations for i in 0..preallocated_preimg.len() / 2 { - let preimg_tag = &preallocated_preimg[2*i]; - let preimg_hash = &preallocated_preimg[2*i + 1]; + let preimg_tag = &preallocated_preimg[2 * i]; + let preimg_hash = &preallocated_preimg[2 * i + 1]; let preimg_ptr = AllocatedPtr::from_parts(preimg_tag.clone(), preimg_hash.clone()); bound_allocations.insert($preimg[i].clone(), preimg_ptr); diff --git a/src/lem/eval.rs b/src/lem/eval.rs index d76e65078a..c73f85644d 100644 --- a/src/lem/eval.rs +++ b/src/lem/eval.rs @@ -9,7 +9,7 @@ pub(crate) fn eval_step() -> Func { let apply_cont = apply_cont(); let make_thunk = make_thunk(); - func!((expr, env, cont): 3 => { + func!(step(expr, env, cont): 3 => { let (expr, env, cont, ctrl) = reduce(expr, env, cont); let (expr, env, cont, ctrl) = apply_cont(expr, env, cont, ctrl); let (expr, env, cont, _ctrl) = make_thunk(expr, env, cont, ctrl); @@ -18,7 +18,7 @@ pub(crate) fn eval_step() -> Func { } fn safe_uncons() -> Func { - func!((xs): 2 => { + func!(safe_uncons(xs): 2 => { let nil: Expr::Nil; let nilstr = Symbol(""); match xs.tag { @@ -41,7 +41,7 @@ fn safe_uncons() -> Func { } fn make_tail_continuation() -> Func { - func!((env, continuation): 1 => { + func!(make_tail_continuation(env, continuation): 1 => { match continuation.tag { Cont::Tail => { return (continuation); @@ -55,7 +55,7 @@ fn make_tail_continuation() -> Func { fn reduce() -> Func { // Auxiliary functions let safe_uncons = safe_uncons(); - let env_to_use = func!((smaller_env, smaller_rec_env): 1 => { + let env_to_use = func!(env_to_use(smaller_env, smaller_rec_env): 1 => { match smaller_rec_env.tag { Expr::Nil => { return (smaller_env) @@ -64,7 +64,7 @@ fn reduce() -> Func { let env: Expr::Cons = hash2(smaller_rec_env, smaller_env); return (env) }); - let extract_arg = func!((args): 2 => { + let extract_arg = func!(extract_arg(args): 2 => { match args.tag { Expr::Nil => { let dummy = Symbol("dummy"); @@ -77,7 +77,7 @@ fn reduce() -> Func { } } }); - let expand_bindings = func!((head, body, body1, rest_bindings): 1 => { + let expand_bindings = func!(expand_bindings(head, body, body1, rest_bindings): 1 => { match rest_bindings.tag { Expr::Nil => { return (body1) @@ -87,7 +87,7 @@ fn reduce() -> Func { let expanded: Expr::Cons = hash2(head, expanded_0); return (expanded) }); - let choose_let_cont = func!((head, var, env, expanded, cont): 1 => { + let choose_let_cont = func!(choose_let_cont(head, var, env, expanded, cont): 1 => { match head.val { Symbol("let") => { let cont: Cont::Let = hash4(var, env, expanded, cont); @@ -99,7 +99,7 @@ fn reduce() -> Func { } } }); - let choose_unop = func!((head): 1 => { + let choose_unop = func!(choose_unop(head): 1 => { let nil: Expr::Nil; let t = Symbol("t"); match head.val { @@ -120,7 +120,7 @@ fn reduce() -> Func { return (nil) }); - let choose_binop = func!((head): 1 => { + let choose_binop = func!(choose_binop(head): 1 => { let nil: Expr::Nil; let t = Symbol("t"); match head.val { @@ -144,7 +144,7 @@ fn reduce() -> Func { }; return (nil) }); - let is_potentially_fun = func!((head): 1 => { + let is_potentially_fun = func!(is_potentially_fun(head): 1 => { let t = Symbol("t"); let nil: Expr::Nil; match head.tag { @@ -164,7 +164,7 @@ fn reduce() -> Func { return (nil) }); - func!((expr, env, cont): 4 => { + func!(reduce(expr, env, cont): 4 => { // Useful constants let ret: Ctrl::Return; let apply: Ctrl::ApplyContinuation; @@ -440,7 +440,7 @@ fn reduce() -> Func { fn apply_cont() -> Func { let safe_uncons = safe_uncons(); let make_tail_continuation = make_tail_continuation(); - let extend_rec = func!((env, var, result): 1 => { + let extend_rec = func!(extend_rec(env, var, result): 1 => { let (binding_or_env, rest) = unhash2(env); let (var_or_binding, _val_or_more_bindings) = unhash2(binding_or_env); @@ -462,7 +462,7 @@ fn apply_cont() -> Func { } } }); - func!((result, env, cont, ctrl): 4 => { + func!(apply_cont(result, env, cont, ctrl): 4 => { // Useful constants let ret: Ctrl::Return; let makethunk: Ctrl::MakeThunk; @@ -790,7 +790,7 @@ fn apply_cont() -> Func { } fn make_thunk() -> Func { - func!((expr, env, cont, ctrl): 4 => { + func!(make_thunk(expr, env, cont, ctrl): 4 => { let ret: Ctrl::Return; match ctrl.tag { Ctrl::MakeThunk => { diff --git a/src/lem/macros.rs b/src/lem/macros.rs index 39ca402780..bd3b62f93a 100644 --- a/src/lem/macros.rs +++ b/src/lem/macros.rs @@ -475,8 +475,9 @@ macro_rules! block { #[macro_export] macro_rules! func { - (($( $in:ident ),*): $size:expr => $lem:tt) => { + ($name:ident($( $in:ident ),*): $size:expr => $lem:tt) => { $crate::lem::Func::new( + stringify!($name).into(), vec![$($crate::var!($in)),*], $size, $crate::block!($lem), diff --git a/src/lem/mod.rs b/src/lem/mod.rs index 76228bc3e7..0c29826108 100644 --- a/src/lem/mod.rs +++ b/src/lem/mod.rs @@ -83,6 +83,7 @@ pub type AString = Arc; /// function body, which is a `Block` #[derive(Debug, Clone, PartialEq, Eq)] pub struct Func { + name: String, input_params: Vec, output_size: usize, body: Block, @@ -266,8 +267,14 @@ pub enum Op { impl Func { /// Instantiates a `Func` with the appropriate transformations and checks - pub fn new(input_params: Vec, output_size: usize, body: Block) -> Result { + pub fn new( + name: String, + input_params: Vec, + output_size: usize, + body: Block, + ) -> Result { let func = Func { + name, input_params, output_size, body, @@ -501,7 +508,12 @@ impl Func { ops.extend_from_slice(&self.body.ops); let ctrl = self.body.ctrl.clone(); let body = Block { ops, ctrl }; - Self::new(self.input_params.clone(), self.output_size, body) + Self::new( + self.name.clone(), + self.input_params.clone(), + self.output_size, + body, + ) } } @@ -707,7 +719,7 @@ mod tests { #[test] fn accepts_virtual_nested_match_tag() { - let lem = func!((expr_in, env_in, cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, cont_in): 3 => { match expr_in.tag { Expr::Num => { let cont_out_terminal: Cont::Terminal; @@ -746,7 +758,7 @@ mod tests { #[test] fn resolves_conflicts_of_clashing_names_in_parallel_branches() { - let lem = func!((expr_in, env_in, _cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, _cont_in): 3 => { match expr_in.tag { // This match is creating `cont_out_terminal` on two different // branches, which, in theory, would cause troubles at allocation @@ -770,7 +782,7 @@ mod tests { #[test] fn handles_non_ssa() { - let func = func!((expr_in, _env_in, _cont_in): 3 => { + let func = func!(foo(expr_in, _env_in, _cont_in): 3 => { let x: Expr::Cons = hash2(expr_in, expr_in); // The next line rewrites `x` and it should move on smoothly, matching // the expected number of constraints accordingly @@ -785,7 +797,7 @@ mod tests { #[test] fn test_simple_all_paths_delta() { - let lem = func!((expr_in, env_in, _cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, _cont_in): 3 => { let cont_out_terminal: Cont::Terminal; return (expr_in, env_in, cont_out_terminal); }); @@ -796,7 +808,7 @@ mod tests { #[test] fn test_match_all_paths_delta() { - let lem = func!((expr_in, env_in, _cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, _cont_in): 3 => { match expr_in.tag { Expr::Num => { let cont_out_terminal: Cont::Terminal; @@ -815,7 +827,7 @@ mod tests { #[test] fn test_hash_slots() { - let lem = func!((expr_in, env_in, cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, cont_in): 3 => { let _x: Expr::Cons = hash2(expr_in, env_in); let _y: Expr::Cons = hash3(expr_in, env_in, cont_in); let _z: Expr::Cons = hash4(expr_in, env_in, cont_in, cont_in); @@ -846,7 +858,7 @@ mod tests { #[test] fn test_unhash_slots() { - let lem = func!((expr_in, env_in, cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, cont_in): 3 => { let _x: Expr::Cons = hash2(expr_in, env_in); let _y: Expr::Cons = hash3(expr_in, env_in, cont_in); let _z: Expr::Cons = hash4(expr_in, env_in, cont_in, cont_in); @@ -880,7 +892,7 @@ mod tests { #[test] fn test_unhash_nested_slots() { - let lem = func!((expr_in, env_in, cont_in): 3 => { + let lem = func!(foo(expr_in, env_in, cont_in): 3 => { let _x: Expr::Cons = hash2(expr_in, env_in); let _y: Expr::Cons = hash3(expr_in, env_in, cont_in); let _z: Expr::Cons = hash4(expr_in, env_in, cont_in, cont_in);