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 with one diverging arm beside a nil-init variable is
//! sized by the type the other arms push.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const N: &str = "(defvar *n* (length (list 1 2)))";
const MAKES: &str = "(do ((i 0 (+ i 1)) (x nil (make-pt :x x))) ((= i 2) x))";
const PT: &str = "(defstruct pt x)";
fn stepped(step: &str) -> String {
format!("(block b (do ((i 0 (+ i 1)) (v nil {step})) ((= i *n*) v)))")
}
fn rows() -> Vec<Row> {
vec![
row("F1", &[N, &stepped("(if (= i 5) (return-from b 9) 7)")]),
row("F2", &[N, &stepped("(if (= i 5) 7 (return-from b 9))")]),
row(
"F3",
&[N, &stepped("(cond ((> i 5) 1) (t (return-from b 4)))")],
),
"F4",
&[
N,
"(handler-case (do ((i 0 (+ i 1)) (v nil (if (> i 100) i (error 'boom \"x\")))) ((= i *n*) v)) (boom (e) 5))",
],
"F5",
"(defun die (i) (if (> i 100) i (error 'boom \"x\")))",
"(handler-case (do ((i 0 (+ i 1)) (v nil (die i))) ((= i *n*) v)) (boom (e) 5))",
row("F6", &[N, &stepped("(and (> i 5) (return-from b 3))")]),
row("F7", &[N, &stepped("(or (> i 5) (return-from b 3))")]),
row("F8", &[N, &stepped("(progn (return-from b 3) 5)")]),
"F9",
PT,
"(defun mk (x) (make-pt :x x))",
"(do ((i 0 (+ i 1)) (v nil (mk i))) ((= i *n*) v))",
row("G1", &[PT, &format!("(defvar *q* {MAKES})"), "*q*"]),
"G2",
"(defvar *q* nil)",
&format!("(setf *q* {MAKES})"),
"*q*",
]
/// CL: F1 7, F2 9, F3 4, F4 5, F5 5, F8 3.
const CL: &[(&str, &[&str])] = &[
("F1", &["-", "7"]),
("F2", &["-", "9"]),
("F3", &["-", "4"]),
("F4", &["-", "5"]),
("F5", &["-", "die", "5"]),
("F6", &["-", "nil"]),
("F7", &["-", "3"]),
("F8", &["-", "3"]),
("F9", &["pt", "-", "mk", "#S(PT :X 1)"]),
("G1", &["pt", "-", "#S(PT :X #S(PT :X nil))"]),
(
"pt",
"-",
"#S(PT :X #S(PT :X nil))",
];
#[test]
fn every_row_reads_as_common_lisp() {
assert_pinned(&rows(), CL);