add inc field to Inc instruction

This commit is contained in:
Folkert 2021-01-22 00:16:20 +01:00
parent 5a2b2cbcac
commit 15cbadf652
6 changed files with 21 additions and 14 deletions

View File

@ -2026,7 +2026,7 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
// This doesn't currently do anything
context.i64_type().const_zero().into()
}
Inc(symbol, cont) => {
Inc(symbol, _inc, cont) => {
let (value, layout) = load_symbol_and_layout(env, scope, symbol);
let layout = layout.clone();

View File

@ -381,7 +381,7 @@ where
self.set_last_seen(*sym, stmt);
}
Stmt::Rethrow => {}
Stmt::Inc(sym, following) => {
Stmt::Inc(sym, _inc, following) => {
self.set_last_seen(*sym, stmt);
self.scan_ast(following);
}

View File

@ -168,7 +168,7 @@ impl<'a> ParamMap<'a> {
stack.extend(branches.iter().map(|b| &b.1));
stack.push(default_branch);
}
Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"),
Inc(_, _, _) | Dec(_, _) => unreachable!("these have not been introduced yet"),
Ret(_) | Rethrow | Jump(_, _) | RuntimeError(_) => {
// these are terminal, do nothing
@ -513,7 +513,7 @@ impl<'a> BorrowInfState<'a> {
}
self.collect_stmt(default_branch);
}
Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"),
Inc(_, _, _) | Dec(_, _) => unreachable!("these have not been introduced yet"),
Ret(_) | RuntimeError(_) | Rethrow => {
// these are terminal, do nothing

View File

@ -52,7 +52,7 @@ pub fn occuring_variables(stmt: &Stmt<'_>) -> (MutSet<Symbol>, MutSet<Symbol>) {
Rethrow => {}
Inc(symbol, cont) | Dec(symbol, cont) => {
Inc(symbol, _, cont) | Dec(symbol, cont) => {
result.insert(*symbol);
stack.push(cont);
}
@ -275,7 +275,7 @@ impl<'a> Context<'a> {
return stmt;
}
self.arena.alloc(Stmt::Inc(symbol, stmt))
self.arena.alloc(Stmt::Inc(symbol, 1, stmt))
}
fn add_dec(&self, symbol: Symbol, stmt: &'a Stmt<'a>) -> &'a Stmt<'a> {
@ -851,7 +851,7 @@ impl<'a> Context<'a> {
(switch, case_live_vars)
}
RuntimeError(_) | Inc(_, _) | Dec(_, _) => (stmt, MutSet::default()),
RuntimeError(_) | Inc(_, _, _) | Dec(_, _) => (stmt, MutSet::default()),
}
}
}
@ -902,7 +902,7 @@ pub fn collect_stmt(
vars
}
Inc(symbol, cont) | Dec(symbol, cont) => {
Inc(symbol, _, cont) | Dec(symbol, cont) => {
vars.insert(*symbol);
collect_stmt(cont, jp_live_vars, vars)
}

View File

@ -766,7 +766,7 @@ pub enum Stmt<'a> {
},
Ret(Symbol),
Rethrow,
Inc(Symbol, &'a Stmt<'a>),
Inc(Symbol, u64, &'a Stmt<'a>),
Dec(Symbol, &'a Stmt<'a>),
Join {
id: JoinPointId,
@ -1263,12 +1263,19 @@ impl<'a> Stmt<'a> {
.append(alloc.intersperse(it, alloc.space()))
.append(";")
}
Inc(symbol, cont) => alloc
Inc(symbol, 1, cont) => alloc
.text("inc ")
.append(symbol_to_doc(alloc, *symbol))
.append(";")
.append(alloc.hardline())
.append(cont.to_doc(alloc)),
Inc(symbol, n, cont) => alloc
.text("inc ")
.append(alloc.text(format!("{}", n)))
.append(symbol_to_doc(alloc, *symbol))
.append(";")
.append(alloc.hardline())
.append(cont.to_doc(alloc)),
Dec(symbol, cont) => alloc
.text("dec ")
.append(symbol_to_doc(alloc, *symbol))
@ -4666,8 +4673,8 @@ fn substitute_in_stmt_help<'a>(
Some(s) => Some(arena.alloc(Ret(s))),
None => None,
},
Inc(symbol, cont) => match substitute_in_stmt_help(arena, cont, subs) {
Some(cont) => Some(arena.alloc(Inc(*symbol, cont))),
Inc(symbol, inc, cont) => match substitute_in_stmt_help(arena, cont, subs) {
Some(cont) => Some(arena.alloc(Inc(*symbol, *inc, cont))),
None => None,
},
Dec(symbol, cont) => match substitute_in_stmt_help(arena, cont, subs) {

View File

@ -228,8 +228,8 @@ fn insert_jumps<'a>(
None
}
}
Inc(symbol, cont) => match insert_jumps(arena, cont, goal_id, needle) {
Some(cont) => Some(arena.alloc(Inc(*symbol, cont))),
Inc(symbol, inc, cont) => match insert_jumps(arena, cont, goal_id, needle) {
Some(cont) => Some(arena.alloc(Inc(*symbol, *inc, cont))),
None => None,
},
Dec(symbol, cont) => match insert_jumps(arena, cont, goal_id, needle) {