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: a DO step that always diverges, however it is wrapped, never
//! yields a value, so it cannot mistype the nil-seeded variable.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const N: &str = "(defvar *n* (length (list 1 2)))";
const G: &str = "(defvar *g* 0)";
const DIE0: &str = "(defun die0 () (error 'boom \"x\"))";
fn exiting(step: &str) -> String {
format!("(block b (do ((i 0 (+ i 1)) (v nil {step})) ((= i *n*) v)))")
}
fn caught(step: &str) -> String {
format!("(handler-case (do ((i 0 (+ i 1)) (v nil {step})) ((= i *n*) v)) (boom (e) 5))")
fn rows() -> Vec<Row> {
vec![
row("T2a", &[N, &exiting("(block c (return-from b 9))")]),
row("T2b", &[N, &exiting("(let ((k 1)) (return-from b k))")]),
row(
"T2c",
&[
N,
&exiting("(handler-case (error 'boom \"x\") (boom (e) (return-from b 5)))"),
],
),
"T2d",
"(tagbody (do ((i 0 (+ i 1)) (v nil (go out))) ((= i *n*) v)) out)",
row("T2e", &[N, DIE0, &caught("(die0)")]),
row("T2f", &[N, &caught("(let ((k 1)) (error 'boom \"x\"))")]),
"T2h",
G,
&exiting("(block c (setf *g* (+ *g* 1)) (return-from b *g*))"),
"*g*",
"T2g",
&[N, &exiting("(cond ((> i 5) nil) (t (return-from b 4)))")],
]
/// T2d: a TAGBODY leaves no value here, as CL's NIL.
const CL: &[(&str, &[&str])] = &[
("T2a", &["-", "9"]),
("T2b", &["-", "1"]),
("T2c", &["-", "5"]),
("T2d", &["-", "-"]),
("T2e", &["-", "die0", "5"]),
("T2f", &["-", "5"]),
("T2h", &["-", "-", "1", "1"]),
("T2g", &["-", "4"]),
];
#[test]
fn every_row_reads_as_common_lisp() {
assert_pinned(&rows(), CL);