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 S4 fix round 2 rows with their Common Lisp values: a cell that
//! holds an earlier unit's value no constant holds is lost until a store ran.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const ALWAYS: &str = "(> (entity-count) -1)";
const NEVER: &str = "(> (entity-count) 99)";
const CLOSURE: &str = "(defvar *k* (lambda (x) x))";
const RISKY: &str = "(defun risky () (if (> (entity-count) -1) (error 'boom \"m\") 10))";
fn caught_store() -> String {
format!("(handler-case (progn (when {ALWAYS} (error 'boom \"m\")) (setf *k* 6)) (t (e) 0))")
}
fn rows() -> Vec<Row> {
vec![
row("L1a", &[CLOSURE, &format!("{} (list *k*)", caught_store())]),
row(
"L1b",
&[
CLOSURE,
RISKY,
"(handler-case (progn (setf *k* (risky)) 0) (t (e) 0)) (list *k*)",
],
),
"L1c",
&format!("(let ((x 1)) {} (list *k* x))", caught_store()),
"L1d",
&format!("{} (defun getk () *k*)", caught_store()),
"(getk)",
"L1e",
&format!("(unwind-protect {} 0) (list *k*)", caught_store()),
"L1f",
&[CLOSURE, &format!("(when {NEVER} (setf *k* 6)) (list *k*)")],
"L1g",
&[CLOSURE, &format!("(when {ALWAYS} (setf *k* 6)) (list *k*)")],
"L6a",
&[&format!(
"(block b (defvar *f* (progn (when {ALWAYS} (return-from b 1)) (lambda (x) x))) 0)"
)],
"L6b",
"(block b (defvar *f* (progn (when {NEVER} (return-from b 1)) (lambda (x) x))) 0) (funcall *f* 4)"
"L1h",
&format!("(when {NEVER} (setf *k* 6))"),
"(setf *k* 7) (list *k*)",
]
/// What each row prints; CL reads the closure in the loud rows.
const TODAY: &[(&str, &[&str])] = &[
("L1a", &["-", LOST]),
("L1b", &["-", "risky", LOST]),
("L1c", &["-", LOST]),
("L1d", &["-", "getk", "#<closure:0>"]),
("L1e", &["-", LOST]),
("L1f", &["-", LOST]),
("L1g", &["-", "(6)"]),
("L6a", &["1"]),
("L6b", &["4"]),
("L1h", &["-", "nil", "(7)"]),
];
const LOST: &str = "err: VALUE-LOST: *K*: its closure value does not ";
#[test]
fn every_row_reads_as_common_lisp() {
assert_pinned(&rows(), TODAY);