1
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
2
// Cranelift backend refuses to run under Miri.
3
#![cfg(not(miri))]
4

            
5
//! PERSIST rows with their Common Lisp values: a struct or list flows through
6
//! a recursive function whose return guess comes from its non-recursive exit.
7

            
8
#[path = "persist/rows.rs"]
9
mod persist;
10

            
11
use persist::{Row, assert_pinned, row};
12

            
13
const PT: &str = "(defstruct pt x)";
14
const CNT: &str = "(defun cnt (p n) (if (= n 0) 0 (+ 1 (cnt p (- n 1)))))";
15
const CNT2: &str = "(defun cnt2 (n p) (if (= n 0) 0 (+ 1 (cnt2 (- n 1) p))))";
16
const PICKF: &str = "(defun pickf (p n) (if (= n 0) p (pickf p (- n 1))))";
17
const PICK: &str = "(defun pick (n p) (if (= n 0) p (pick (- n 1) p)))";
18
const COLLECT: &str = "(defun f (p n) (if (= n 0) nil (cons n (f p (- n 1)))))";
19
const DEEP: &str =
20
    "(defun deep (p n) (if (= n 0) p (let ((q (deep p (- n 1)))) (setf (pt-x q) n) q)))";
21
const LISTEXIT: &str = "(defun f (p n) (if (= n 0) (list 0) (cons n (f p (- n 1)))))";
22
const STORE: &str =
23
    "(defun cnt (n p) (if (= n 0) 0 (progn (setf (pt-x p) (cnt (- n 1) p)) (+ 1 (pt-x p)))))";
24

            
25
1
fn rows() -> Vec<Row> {
26
1
    vec![
27
1
        row("H2a", &[PT, CNT, "(cnt (make-pt) 3)"]),
28
1
        row("H2b", &[CNT, "(cnt (list (entity-count)) 3)"]),
29
1
        row("H2c", &[PT, COLLECT, "(f (make-pt) 3)"]),
30
1
        row("H2d", &[PT, STORE, "(cnt 3 (make-pt :x 0))"]),
31
1
        row(
32
1
            "H2e",
33
1
            &[PT, CNT, "(defvar *k* (cnt (make-pt) 3))", "(+ *k* 1)"],
34
1
        ),
35
1
        row(
36
1
            "H2f",
37
1
            &[
38
1
                PT,
39
1
                CNT,
40
1
                "(defvar *k* nil)",
41
1
                "(setf *k* (cnt (make-pt) 3))",
42
1
                "(+ *k* 1)",
43
1
            ],
44
1
        ),
45
1
        row("J3a", &[PT, DEEP, "(deep (make-pt :x 0) 3)"]),
46
1
        row("J3b", &[PT, DEEP, "(pt-x (deep (make-pt :x 0) 3))"]),
47
1
        row("J3c", &[PT, LISTEXIT, "(f (make-pt) 3)"]),
48
1
        row("G3b", &[PT, CNT2, "(cnt2 3 (make-pt))"]),
49
1
        row("G3c", &[PT, PICK, "(pt-x (pick 3 (make-pt :x 7)))"]),
50
1
        row("G3d", &[PT, PICKF, "(pt-x (pickf (make-pt :x 7) 3))"]),
51
    ]
52
1
}
53

            
54
const CL: &[(&str, &[&str])] = &[
55
    ("H2a", &["pt", "cnt", "3"]),
56
    ("H2b", &["cnt", "3"]),
57
    ("H2c", &["pt", "f", "(3 2 1)"]),
58
    ("H2d", &["pt", "cnt", "3"]),
59
    ("H2e", &["pt", "cnt", "-", "4"]),
60
    ("H2f", &["pt", "cnt", "-", "3", "4"]),
61
    ("J3a", &["pt", "deep", "#S(PT :X 3)"]),
62
    ("J3b", &["pt", "deep", "3"]),
63
    ("J3c", &["pt", "f", "(3 2 1 0)"]),
64
    ("G3b", &["pt", "cnt2", "3"]),
65
    ("G3c", &["pt", "pick", "7"]),
66
    ("G3d", &["pt", "pickf", "7"]),
67
];
68

            
69
#[test]
70
1
fn every_row_reads_as_common_lisp() {
71
1
    assert_pinned(&rows(), CL);
72
1
}