diff --git a/src/lem/circuit.rs b/src/lem/circuit.rs index 888709629d..461d94e8da 100644 --- a/src/lem/circuit.rs +++ b/src/lem/circuit.rs @@ -1163,7 +1163,7 @@ impl Func { ) .with_context(|| " couldn't constrain `enforce_selector_with_premise`") } - Ctrl::MatchVal(match_var, cases, def) => { + Ctrl::Match(match_var, cases, def) => { let match_lit = bound_allocations.get(match_var)?.clone(); let mut selector = Vec::with_capacity(cases.len() + 2); let mut branch_slots = Vec::with_capacity(cases.len()); @@ -1439,7 +1439,7 @@ impl Func { }; num_constraints } - Ctrl::MatchVal(_, cases, def) => { + Ctrl::Match(_, cases, def) => { // We allocate one boolean per case and constrain it twice // per case. Then we add 1 constraint to enforce only one // case was selected diff --git a/src/lem/eval.rs b/src/lem/eval.rs index e06cde12c0..c98f3ebf5d 100644 --- a/src/lem/eval.rs +++ b/src/lem/eval.rs @@ -124,7 +124,7 @@ fn reduce() -> Func { return (expanded) }); let choose_let_cont = func!(choose_let_cont(head, var, env, expanded, cont): 1 => { - match head.val { + match head { Symbol("let") => { let cont: Cont::Let = hash4(var, env, expanded, cont); return (cont) @@ -139,7 +139,7 @@ fn reduce() -> Func { let nil = Symbol("nil"); let nil = cast(nil, Expr::Nil); let t = Symbol("t"); - match head.val { + match head { Symbol("car") | Symbol("cdr") | Symbol("commit") @@ -161,7 +161,7 @@ fn reduce() -> Func { let nil = Symbol("nil"); let nil = cast(nil, Expr::Nil); let t = Symbol("t"); - match head.val { + match head { Symbol("cons") | Symbol("strcons") | Symbol("hide") @@ -219,7 +219,7 @@ fn reduce() -> Func { return (thunk_expr, env, thunk_continuation, apply) } Expr::Sym => { - match expr.val { + match expr { Symbol("nil") | Symbol("t") => { return (expr, env, cont, apply) } @@ -293,7 +293,7 @@ fn reduce() -> Func { return (expr, env, err, errctrl); } }; - match head.val { + match head { Symbol("lambda") => { let (args, body) = safe_uncons(rest); let (arg, cdr_args) = extract_arg(args); @@ -573,7 +573,7 @@ fn apply_cont() -> Func { match result.tag { Expr::Fun => { let (arg, body, closed_env) = unhash3(result); - match arg.val { + match arg { Symbol("dummy") => { match body.tag { Expr::Nil => { @@ -610,7 +610,7 @@ fn apply_cont() -> Func { match function.tag { Expr::Fun => { let (arg, body, closed_env) = unhash3(function); - match arg.val { + match arg { Symbol("dummy") => { return (result, env, err, errctrl) } @@ -649,7 +649,7 @@ fn apply_cont() -> Func { } Cont::Unop => { let (operator, continuation) = unhash2(cont); - match operator.val { + match operator { Symbol("car") => { // Almost like safe_uncons, except it returns // an error in case it can't unhash it @@ -791,7 +791,7 @@ fn apply_cont() -> Func { Cont::Binop => { let (operator, saved_env, unevaled_args, continuation) = unhash4(cont); let (arg2, rest) = safe_uncons(unevaled_args); - match operator.val { + match operator { Symbol("begin") => { match rest.tag { Expr::Nil => { @@ -814,7 +814,7 @@ fn apply_cont() -> Func { Cont::Binop2 => { let (operator, evaled_arg, continuation) = unhash3(cont); let (args_num_type) = args_num_type(evaled_arg, result); - match operator.val { + match operator { Symbol("eval") => { return (evaled_arg, result, continuation, ret) } @@ -849,7 +849,7 @@ fn apply_cont() -> Func { let eq_tag = eq_tag(evaled_arg, result); let eq_val = eq_val(evaled_arg, result); let eq = mul(eq_tag, eq_val); - match eq.val { + match eq { Num(0) => { return (nil, env, continuation, makethunk) } @@ -859,7 +859,7 @@ fn apply_cont() -> Func { } } Symbol("+") => { - match args_num_type.val { + match args_num_type { Num(0) => { return (result, env, err, errctrl) } @@ -870,7 +870,7 @@ fn apply_cont() -> Func { Num(2) => { let val = add(evaled_arg, result); let not_overflow = lt(val, size_u64); - match not_overflow.val { + match not_overflow { Num(0) => { let val = sub(val, size_u64); let val = cast(val, Expr::U64); @@ -885,7 +885,7 @@ fn apply_cont() -> Func { } } Symbol("-") => { - match args_num_type.val { + match args_num_type { Num(0) => { return (result, env, err, errctrl) } @@ -899,7 +899,7 @@ fn apply_cont() -> Func { // to add 2^64 to get back to U64 domain. let val = sub(evaled_arg, result); let is_neg = lt(val, zero); - match is_neg.val { + match is_neg { Num(1) => { let val = add(val, size_u64); let val = cast(val, Expr::U64); @@ -914,7 +914,7 @@ fn apply_cont() -> Func { } } Symbol("*") => { - match args_num_type.val { + match args_num_type { Num(0) => { return (result, env, err, errctrl) } @@ -933,12 +933,12 @@ fn apply_cont() -> Func { } Symbol("/") => { let is_z = eq_val(result, zero); - match is_z.val { + match is_z { Num(1) => { return (result, env, err, errctrl) } }; - match args_num_type.val { + match args_num_type { Num(0) => { return (result, env, err, errctrl) } @@ -955,12 +955,12 @@ fn apply_cont() -> Func { } Symbol("%") => { let is_z = eq_val(result, zero); - match is_z.val { + match is_z { Num(1) => { return (result, env, err, errctrl) } }; - match args_num_type.val { + match args_num_type { Num(2) => { let (_div, rem) = div_rem64(evaled_arg, result); let rem = cast(rem, Expr::U64); @@ -970,13 +970,13 @@ fn apply_cont() -> Func { return (result, env, err, errctrl) } Symbol("=") => { - match args_num_type.val { + match args_num_type { Num(0) => { return (result, env, err, errctrl) } }; let eq = eq_val(evaled_arg, result); - match eq.val { + match eq { Num(0) => { return (nil, env, continuation, makethunk) } @@ -987,7 +987,7 @@ fn apply_cont() -> Func { } Symbol("<") => { let val = lt(evaled_arg, result); - match val.val { + match val { Num(0) => { return (nil, env, continuation, makethunk) } @@ -998,7 +998,7 @@ fn apply_cont() -> Func { } Symbol(">") => { let val = lt(result, evaled_arg); - match val.val { + match val { Num(0) => { return (nil, env, continuation, makethunk) } @@ -1009,7 +1009,7 @@ fn apply_cont() -> Func { } Symbol("<=") => { let val = lt(result, evaled_arg); - match val.val { + match val { Num(0) => { return (t, env, continuation, makethunk) } @@ -1020,7 +1020,7 @@ fn apply_cont() -> Func { } Symbol(">=") => { let val = lt(evaled_arg, result); - match val.val { + match val { Num(0) => { return (t, env, continuation, makethunk) } diff --git a/src/lem/interpreter.rs b/src/lem/interpreter.rs index d0984e09ee..f2be67b115 100644 --- a/src/lem/interpreter.rs +++ b/src/lem/interpreter.rs @@ -379,7 +379,7 @@ impl Block { } } } - Ctrl::MatchVal(match_var, cases, def) => { + Ctrl::Match(match_var, cases, def) => { let ptr = bindings.get(match_var)?; let Some(lit) = Lit::from_ptr(ptr, store) else { // If we can't find it in the store, it most certaily is not equal to any diff --git a/src/lem/macros.rs b/src/lem/macros.rs index 10869a34be..5f42db262a 100644 --- a/src/lem/macros.rs +++ b/src/lem/macros.rs @@ -201,7 +201,7 @@ macro_rules! ctrl { $crate::lem::Ctrl::MatchTag($crate::var!($sii), cases, default) } }; - ( match $sii:ident.val { $( $cnstr:ident($val:literal) $(| $other_cnstr:ident($other_val:literal))* => $case_ops:tt )* } $(; $($def:tt)*)? ) => { + ( match $sii:ident { $( $cnstr:ident($val:literal) $(| $other_cnstr:ident($other_val:literal))* => $case_ops:tt )* } $(; $($def:tt)*)? ) => { { let mut cases = indexmap::IndexMap::new(); $( @@ -221,7 +221,7 @@ macro_rules! ctrl { )* )* let default = None $( .or (Some(Box::new($crate::block!( @seq {}, $($def)* )))) )?; - $crate::lem::Ctrl::MatchVal($crate::var!($sii), cases, default) + $crate::lem::Ctrl::Match($crate::var!($sii), cases, default) } }; ( if $x:ident == $y:ident { $($true_block:tt)+ } $($false_block:tt)+ ) => { @@ -508,13 +508,13 @@ macro_rules! block { $crate::ctrl!( match $sii.tag { $( $kind::$tag $(| $other_kind::$other_tag)* => $case_ops )* } $(; $($def)*)? ) ) }; - (@seq {$($limbs:expr)*}, match $sii:ident.val { $( $cnstr:ident($val:literal) $(| $other_cnstr:ident($other_val:literal))* => $case_ops:tt )* } $(; $($def:tt)*)?) => { + (@seq {$($limbs:expr)*}, match $sii:ident { $( $cnstr:ident($val:literal) $(| $other_cnstr:ident($other_val:literal))* => $case_ops:tt )* } $(; $($def:tt)*)?) => { $crate::block! ( @end { $($limbs)* }, - $crate::ctrl!( match $sii.val { $( $cnstr($val) $(| $other_cnstr($other_val))* => $case_ops )* } $(; $($def)*)? ) + $crate::ctrl!( match $sii { $( $cnstr($val) $(| $other_cnstr($other_val))* => $case_ops )* } $(; $($def)*)? ) ) }; (@seq {$($limbs:expr)*}, if $x:ident == $y:ident { $($true_block:tt)+ } $($false_block:tt)+ ) => { @@ -587,8 +587,8 @@ mod tests { } #[inline] - fn match_val(i: Var, cases: Vec<(Lit, Block)>, def: Block) -> Ctrl { - Ctrl::MatchVal(i, indexmap::IndexMap::from_iter(cases), Some(Box::new(def))) + fn match_(i: Var, cases: Vec<(Lit, Block)>, def: Block) -> Ctrl { + Ctrl::Match(i, indexmap::IndexMap::from_iter(cases), Some(Box::new(def))) } #[test] @@ -698,7 +698,7 @@ mod tests { ); let moo = ctrl!( - match www.val { + match www { Symbol("nil") => { return (foo, foo, foo); // a single Ctrl will not turn into a Seq } @@ -713,7 +713,7 @@ mod tests { ); assert!( - moo == match_val( + moo == match_( mptr("www"), vec![ ( diff --git a/src/lem/mod.rs b/src/lem/mod.rs index ae6d147e9e..a0cbffdb5e 100644 --- a/src/lem/mod.rs +++ b/src/lem/mod.rs @@ -231,10 +231,10 @@ pub enum Ctrl { /// `MatchTag(x, cases)` performs a match on the tag of `x`, choosing the /// appropriate `Block` among the ones provided in `cases` MatchTag(Var, IndexMap, Option>), - /// `MatchSymbol(x, cases, def)` checks whether `x` matches some symbol among + /// `Match(x, cases, def)` checks whether `x` matches some `Lit` among /// the ones provided in `cases`. If so, run the corresponding `Block`. Run /// `def` otherwise - MatchVal(Var, IndexMap, Option>), + Match(Var, IndexMap, Option>), /// `IfEq(x, y, eq_block, else_block)` runs `eq_block` if `x == y`, and /// otherwise runs `else_block` IfEq(Var, Var, Box, Box), @@ -470,7 +470,7 @@ impl Func { None => (), } } - Ctrl::MatchVal(var, cases, def) => { + Ctrl::Match(var, cases, def) => { is_bound(var, map)?; let mut lits = HashSet::new(); let mut kind = None; @@ -717,7 +717,7 @@ impl Block { }; Ctrl::MatchTag(var, IndexMap::from_iter(new_cases), new_def) } - Ctrl::MatchVal(var, cases, def) => { + Ctrl::Match(var, cases, def) => { let var = map.get_cloned(&var)?; let mut new_cases = Vec::with_capacity(cases.len()); for (lit, case) in cases { @@ -728,7 +728,7 @@ impl Block { Some(def) => Some(Box::new(def.deconflict(map, uniq)?)), None => None, }; - Ctrl::MatchVal(var, IndexMap::from_iter(new_cases), new_def) + Ctrl::Match(var, IndexMap::from_iter(new_cases), new_def) } Ctrl::IfEq(x, y, eq_block, else_block) => { let x = map.get_cloned(&x)?; @@ -763,7 +763,7 @@ impl Block { def.intern_lits(store); } } - Ctrl::MatchVal(_, cases, def) => { + Ctrl::Match(_, cases, def) => { for (lit, b) in cases { lit.to_ptr(store); b.intern_lits(store); diff --git a/src/lem/path.rs b/src/lem/path.rs index 061dbaeb63..47421302be 100644 --- a/src/lem/path.rs +++ b/src/lem/path.rs @@ -119,7 +119,7 @@ impl Block { .values() .fold(init, |acc, block| acc + block.num_paths()) } - Ctrl::MatchVal(_, cases, def) => { + Ctrl::Match(_, cases, def) => { let init = def.as_ref().map_or(0, |def| def.num_paths()); cases .values() diff --git a/src/lem/slot.rs b/src/lem/slot.rs index 6456e7c2c2..842d71c928 100644 --- a/src/lem/slot.rs +++ b/src/lem/slot.rs @@ -204,7 +204,7 @@ impl Block { .values() .fold(init, |acc, block| acc.max(block.count_slots())) } - Ctrl::MatchVal(_, cases, def) => { + Ctrl::Match(_, cases, def) => { let init = def .as_ref() .map_or(SlotsCounter::default(), |def| def.count_slots());