add Expect ir::Stmt node

This commit is contained in:
Folkert 2022-05-26 16:46:10 +02:00
parent 70df1ff9c7
commit b29c7d6fb2
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
10 changed files with 239 additions and 17 deletions

View file

@ -1326,6 +1326,13 @@ pub enum Stmt<'a> {
},
Ret(Symbol),
Refcounting(ModifyRc, &'a Stmt<'a>),
Expect {
condition: Symbol,
lookups: &'a [Symbol],
layouts: &'a [Layout<'a>],
/// what happens after the expect
remainder: &'a Stmt<'a>,
},
/// a join point `join f <params> = <continuation> in remainder`
Join {
id: JoinPointId,
@ -1912,6 +1919,10 @@ impl<'a> Stmt<'a> {
.append(alloc.hardline())
.append(cont.to_doc(alloc)),
Expect{condition, .. } =>
alloc.text("expect ")
.append(symbol_to_doc(alloc, *condition)),
Ret(symbol) => alloc
.text("ret ")
.append(symbol_to_doc(alloc, *symbol))
@ -5931,22 +5942,20 @@ pub fn from_can<'a>(
Expect {
loc_condition,
loc_continuation,
lookups_in_cond: _ ,
lookups_in_cond,
} => {
let rest = from_can(env, variable, loc_continuation.value, procs, layout_cache);
let cond_symbol = env.unique_symbol();
let mut stmt = Stmt::Let(
env.unique_symbol(),
Expr::Call(self::Call {
call_type: CallType::LowLevel {
op: LowLevel::ExpectTrue,
update_mode: env.next_update_mode_id(),
},
arguments: env.arena.alloc([cond_symbol]),
}),
Layout::Builtin(Builtin::Bool),
env.arena.alloc(rest),
);
let lookups = Vec::from_iter_in(lookups_in_cond.iter().map(|t| t.0), env.arena);
// let layouts = Vec::from_iter_in(lookups_in_cond.iter().map(|t| t.1), env.arena);
let mut stmt = Stmt::Expect {
condition: cond_symbol,
lookups: lookups.into_bump_slice(),
layouts: &[],
remainder: env.arena.alloc(rest),
};
stmt = with_hole(
env,
@ -5958,7 +5967,6 @@ pub fn from_can<'a>(
env.arena.alloc(stmt),
);
stmt
}
@ -6300,6 +6308,14 @@ fn substitute_in_stmt_help<'a>(
}
}
Expect { condition, lookups, layouts, remainder } => {
// TODO should we substitute in the ModifyRc?
match substitute_in_stmt_help(arena, remainder, subs) {
Some(cont) => Some(arena.alloc(Expect { condition: *condition , lookups, layouts, remainder: cont} )),
None => None,
}
}
Jump(id, args) => {
let mut did_change = false;
let new_args = Vec::from_iter_in(