Skip to content

Commit

Permalink
MatchVal -> Match
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 24, 2023
1 parent 0d1f8ac commit 083c8f4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/lem/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
52 changes: 26 additions & 26 deletions src/lem/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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);
Expand All @@ -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)
}
Expand All @@ -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);
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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);
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lem/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/lem/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
$(
Expand All @@ -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)+ ) => {
Expand Down Expand Up @@ -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)+ ) => {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
Expand All @@ -713,7 +713,7 @@ mod tests {
);

assert!(
moo == match_val(
moo == match_(
mptr("www"),
vec![
(
Expand Down
12 changes: 6 additions & 6 deletions src/lem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tag, Block>, Option<Box<Block>>),
/// `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<Lit, Block>, Option<Box<Block>>),
Match(Var, IndexMap<Lit, Block>, Option<Box<Block>>),
/// `IfEq(x, y, eq_block, else_block)` runs `eq_block` if `x == y`, and
/// otherwise runs `else_block`
IfEq(Var, Var, Box<Block>, Box<Block>),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)?;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lem/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/lem/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 083c8f4

Please sign in to comment.