Lines
100 %
Functions
90 %
Branches
//! The fold predicate's obligations (0014 Stage 2): default-deny over both
//! registries, the five obligations on sample forms, and the per-head lemma
//! — every whitelisted head's eval, fed malformed constant inputs, answers a
//! datum or an error, never a placeholder, and leaves the table untouched.
use super::*;
use crate::ast::WasmType;
use crate::reader::Reader;
use crate::runtime::{Symbol, SymbolKind};
pub(super) fn form(source: &str) -> Expr {
Reader::parse(source)
.ok()
.and_then(|program| program.exprs.into_iter().next())
.unwrap_or(Expr::Nil)
}
/// The value a quoted source evaluates to.
pub(super) fn datum(source: &str) -> Expr {
eval_value(&mut table(), &form(source)).unwrap_or(Expr::Nil)
pub(super) fn table() -> SymbolTable {
SymbolTable::with_builtins_for_wasm()
pub(super) fn with_runtime(name: &str) -> SymbolTable {
let mut symbols = table();
symbols.define(
Symbol::new(name, SymbolKind::Variable).with_value(Expr::WasmRuntime(WasmType::PairRef(
crate::ast::PairElement::I32,
))),
);
symbols
pub(super) fn with_constant(name: &str, value: &str) -> SymbolTable {
symbols.define(Symbol::new(name, SymbolKind::Variable).with_value(datum(value)));
/// `fold_value` on the live table, asserting the lemma's table obligation:
/// the table is as it was on `Ok` and on the "compile it" answer alike.
pub(super) fn fold_checked(symbols: &mut SymbolTable, source: &str) -> Option<Expr> {
let before = symbols.state_digest();
let folded = fold_value(symbols, &form(source));
let after = symbols.state_digest();
let folded = folded.unwrap_or_else(|err| panic!("{source}: {err}"));
assert_eq!(
strip_charge(&before),
strip_charge(&after),
"{source} changed the table"
folded
/// The digest without the work counter: evaluation charges work by design.
pub(super) fn strip_charge(digest: &str) -> String {
digest
.lines()
.filter(|line| !line.starts_with("charged:"))
.collect::<Vec<_>>()
.join("\n")
mod folding;
mod instances;
mod lemma;
mod probe;
mod refusal;