Lines
100 %
Functions
Branches
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! PERSIST rows with their Common Lisp values: a function defined inside a
//! binder sees the binder's variables when it is called after the binder.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const MUL: &str = "(let ((r 2)) (defun mul (x) (* x r)))";
fn rows() -> Vec<Row> {
vec![
row("L1", &[MUL, "(mul 4)"]),
row("L2", &[MUL, "(defun twice (y) (mul y))", "(twice 5)"]),
row(
"L3",
&["(let ((r (entity-count))) (defun cnt () r))", "(cnt)"],
),
"L4",
&["(progn (let ((r (entity-count))) (defun cnt () r)) (cnt))"],
"L5",
&[
"(defvar *g* 7)",
"(let ((r 2)) (let ((s 3)) (defun f () (+ r s *g*))))",
"(f)",
],
"L6",
&["(let ((r 2)) (defun bump () (setf r (+ r 1))))", "(bump)"],
row("L7", &["(let ((r 2)) (defun f () r) (setf r 5) (f))"]),
row("L8", &[MUL, "(let ((r 50)) (mul 4))"]),
row("L9", &[MUL, "(let ((r 50)) (mul 4))", "(mul 4)"]),
]
}
const RUNTIME: &str = "err: Compile error: CNT: reads R, a runtime varia";
const REBOUND: &str = "err: Compile error: BUMP: stores R, which the cal";
const REBOUND_MUL: &str = "err: Compile error: MUL: reads R, which the call ";
/// CL: L1 8, L2 10, L3 0, L4 0, L5 12, L6 3, L7 5, L8 8, L9 8 8. L3 and L6
/// stay loud: a runtime variable does not outlive its unit, and a captured
/// store has no shared place yet. L8 and L9 stay loud while a call site
/// rebinds the name.
const TODAY: &[(&str, &[&str])] = &[
("L1", &["mul", "8"]),
("L2", &["mul", "twice", "10"]),
("L3", &["cnt", RUNTIME]),
("L4", &["0"]),
("L5", &["-", "f", "12"]),
("L6", &["bump", REBOUND]),
("L7", &["5"]),
("L8", &["mul", REBOUND_MUL]),
("L9", &["mul", REBOUND_MUL, "8"]),
];
#[test]
fn every_row_reads_as_common_lisp() {
assert_pinned(&rows(), TODAY);