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 struct or list flows through
//! a recursive function whose return guess comes from its non-recursive exit.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const PT: &str = "(defstruct pt x)";
const CNT: &str = "(defun cnt (p n) (if (= n 0) 0 (+ 1 (cnt p (- n 1)))))";
const CNT2: &str = "(defun cnt2 (n p) (if (= n 0) 0 (+ 1 (cnt2 (- n 1) p))))";
const PICKF: &str = "(defun pickf (p n) (if (= n 0) p (pickf p (- n 1))))";
const PICK: &str = "(defun pick (n p) (if (= n 0) p (pick (- n 1) p)))";
const COLLECT: &str = "(defun f (p n) (if (= n 0) nil (cons n (f p (- n 1)))))";
const DEEP: &str =
"(defun deep (p n) (if (= n 0) p (let ((q (deep p (- n 1)))) (setf (pt-x q) n) q)))";
const LISTEXIT: &str = "(defun f (p n) (if (= n 0) (list 0) (cons n (f p (- n 1)))))";
const STORE: &str =
"(defun cnt (n p) (if (= n 0) 0 (progn (setf (pt-x p) (cnt (- n 1) p)) (+ 1 (pt-x p)))))";
fn rows() -> Vec<Row> {
vec![
row("H2a", &[PT, CNT, "(cnt (make-pt) 3)"]),
row("H2b", &[CNT, "(cnt (list (entity-count)) 3)"]),
row("H2c", &[PT, COLLECT, "(f (make-pt) 3)"]),
row("H2d", &[PT, STORE, "(cnt 3 (make-pt :x 0))"]),
row(
"H2e",
&[PT, CNT, "(defvar *k* (cnt (make-pt) 3))", "(+ *k* 1)"],
),
"H2f",
&[
PT,
CNT,
"(defvar *k* nil)",
"(setf *k* (cnt (make-pt) 3))",
"(+ *k* 1)",
],
row("J3a", &[PT, DEEP, "(deep (make-pt :x 0) 3)"]),
row("J3b", &[PT, DEEP, "(pt-x (deep (make-pt :x 0) 3))"]),
row("J3c", &[PT, LISTEXIT, "(f (make-pt) 3)"]),
row("G3b", &[PT, CNT2, "(cnt2 3 (make-pt))"]),
row("G3c", &[PT, PICK, "(pt-x (pick 3 (make-pt :x 7)))"]),
row("G3d", &[PT, PICKF, "(pt-x (pickf (make-pt :x 7) 3))"]),
]
}
const CL: &[(&str, &[&str])] = &[
("H2a", &["pt", "cnt", "3"]),
("H2b", &["cnt", "3"]),
("H2c", &["pt", "f", "(3 2 1)"]),
("H2d", &["pt", "cnt", "3"]),
("H2e", &["pt", "cnt", "-", "4"]),
("H2f", &["pt", "cnt", "-", "3", "4"]),
("J3a", &["pt", "deep", "#S(PT :X 3)"]),
("J3b", &["pt", "deep", "3"]),
("J3c", &["pt", "f", "(3 2 1 0)"]),
("G3b", &["pt", "cnt2", "3"]),
("G3c", &["pt", "pick", "7"]),
("G3d", &["pt", "pickf", "7"]),
];
#[test]
fn every_row_reads_as_common_lisp() {
assert_pinned(&rows(), CL);