The pipeline is finally reasonably clean

This commit is contained in:
2023-09-12 01:26:46 +01:00
parent 6693d93944
commit 8c866967a9
86 changed files with 1959 additions and 1393 deletions

View File

@@ -4,6 +4,7 @@ use super::Return;
use crate::foreign::AtomicReturn;
use crate::representations::interpreted::{Clause, ExprInst};
use crate::representations::{PathSet, Primitive};
use crate::utils::never::{unwrap_always, Always};
use crate::utils::Side;
/// Process the clause at the end of the provided path. Note that paths always
@@ -53,16 +54,12 @@ fn map_at<E>(
.map(|p| p.0)
}
/// TODO replace when `!` gets stabilized
#[derive(Debug)]
enum Never {}
/// Replace the [Clause::LambdaArg] placeholders at the ends of the [PathSet]
/// with the value in the body. Note that a path may point to multiple
/// placeholders.
fn substitute(paths: &PathSet, value: Clause, body: ExprInst) -> ExprInst {
let PathSet { steps, next } = paths;
map_at(steps, body, &mut |checkpoint| -> Result<Clause, Never> {
unwrap_always(map_at(steps, body, &mut |checkpoint| -> Always<Clause> {
match (checkpoint, next) {
(Clause::Lambda { .. }, _) => unreachable!("Handled by map_at"),
(Clause::Apply { f, x }, Some((left, right))) => Ok(Clause::Apply {
@@ -77,8 +74,7 @@ fn substitute(paths: &PathSet, value: Clause, body: ExprInst) -> ExprInst {
panic!("Substitution path leads into something other than Apply")
},
}
})
.unwrap()
}))
}
/// Apply a function-like expression to a parameter.