Backup commit

My backspace key started ghosting. Nothing works atm.
This commit is contained in:
2024-01-27 14:50:33 +00:00
parent f77e4fd90a
commit a8887227e5
236 changed files with 10946 additions and 8977 deletions

View File

@@ -0,0 +1,30 @@
//! Convert IR to the interpreter's NORT representation
use super::ir;
use crate::interpreter::nort;
use crate::interpreter::nort_builder::NortBuilder;
fn expr(expr: &ir::Expr, ctx: NortBuilder<(), usize>) -> nort::Expr {
clause(&expr.value, ctx).to_expr(expr.location.clone())
}
fn clause(cls: &ir::Clause, ctx: NortBuilder<(), usize>) -> nort::Clause {
match cls {
ir::Clause::Constant(name) => nort::Clause::Constant(name.clone()),
ir::Clause::Atom(a) => nort::Clause::Atom(a.run()),
ir::Clause::LambdaArg(n) => {
ctx.arg_logic(n);
nort::Clause::LambdaArg
},
ir::Clause::Apply(f, x) => ctx.apply_logic(|c| expr(f, c), |c| expr(x, c)),
ir::Clause::Lambda(body) => ctx.lambda_logic(&(), |c| expr(body, c)),
}
}
pub fn ir_to_nort(expr: &ir::Expr) -> nort::Expr {
let c = NortBuilder::new(&|count| {
let mut count: usize = *count;
Box::new(move |()| count.checked_sub(1).map(|v| count = v).is_none())
});
nort::ClauseInst::new(clause(&expr.value, c)).to_expr(expr.location.clone())
}