mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
always Cond on a symbol
this will make 'beans' easier
This commit is contained in:
parent
3dbdb64a93
commit
2bb69f333f
6 changed files with 192 additions and 104 deletions
|
@ -1105,16 +1105,32 @@ fn decide_to_branching<'a>(
|
|||
jumps,
|
||||
));
|
||||
|
||||
let cond = boolean_all(env.arena, tests);
|
||||
let condition = boolean_all(env.arena, tests);
|
||||
|
||||
let cond_layout = Layout::Builtin(Builtin::Bool);
|
||||
|
||||
Expr::Cond {
|
||||
cond: env.arena.alloc(cond),
|
||||
cond_layout,
|
||||
pass,
|
||||
fail,
|
||||
ret_layout,
|
||||
if let Expr::Load(symbol) = condition {
|
||||
Expr::Cond {
|
||||
cond: symbol,
|
||||
cond_layout,
|
||||
pass,
|
||||
fail,
|
||||
ret_layout,
|
||||
}
|
||||
} else {
|
||||
let cond_symbol = env.fresh_symbol();
|
||||
let stores = vec![(cond_symbol, cond_layout.clone(), condition)];
|
||||
|
||||
Expr::Store(
|
||||
env.arena.alloc(stores),
|
||||
env.arena.alloc(Expr::Cond {
|
||||
cond: cond_symbol,
|
||||
cond_layout,
|
||||
pass,
|
||||
fail,
|
||||
ret_layout,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
FanOut {
|
||||
|
|
|
@ -152,7 +152,7 @@ pub enum Expr<'a> {
|
|||
// The left-hand side of the conditional comparison and the right-hand side.
|
||||
// These are stored separately because there are different machine instructions
|
||||
// for e.g. "compare float and jump" vs. "compare integer and jump"
|
||||
cond: &'a Expr<'a>,
|
||||
cond: Symbol,
|
||||
cond_layout: Layout<'a>,
|
||||
// What to do if the condition either passes or fails
|
||||
pass: &'a Expr<'a>,
|
||||
|
@ -646,13 +646,22 @@ fn from_can<'a>(
|
|||
for (loc_cond, loc_then) in branches.into_iter().rev() {
|
||||
let cond = from_can(env, loc_cond.value, procs, None);
|
||||
let then = from_can(env, loc_then.value, procs, None);
|
||||
expr = Expr::Cond {
|
||||
cond: env.arena.alloc(cond),
|
||||
|
||||
let cond_symbol = env.fresh_symbol();
|
||||
|
||||
let cond_expr = Expr::Cond {
|
||||
cond: cond_symbol,
|
||||
cond_layout: cond_layout.clone(),
|
||||
pass: env.arena.alloc(then),
|
||||
fail: env.arena.alloc(expr),
|
||||
ret_layout: ret_layout.clone(),
|
||||
};
|
||||
|
||||
expr = Expr::Store(
|
||||
env.arena
|
||||
.alloc(vec![(cond_symbol, Layout::Builtin(Builtin::Bool), cond)]),
|
||||
env.arena.alloc(cond_expr),
|
||||
);
|
||||
}
|
||||
|
||||
expr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue