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 S4 fix round 2 rows with their Common Lisp values: a cell that
6
//! holds an earlier unit's value no constant holds is lost until a store ran.
7

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

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

            
13
const ALWAYS: &str = "(> (entity-count) -1)";
14
const NEVER: &str = "(> (entity-count) 99)";
15
const CLOSURE: &str = "(defvar *k* (lambda (x) x))";
16
const RISKY: &str = "(defun risky () (if (> (entity-count) -1) (error 'boom \"m\") 10))";
17

            
18
4
fn caught_store() -> String {
19
4
    format!("(handler-case (progn (when {ALWAYS} (error 'boom \"m\")) (setf *k* 6)) (t (e) 0))")
20
4
}
21

            
22
1
fn rows() -> Vec<Row> {
23
1
    vec![
24
1
        row("L1a", &[CLOSURE, &format!("{} (list *k*)", caught_store())]),
25
1
        row(
26
1
            "L1b",
27
1
            &[
28
1
                CLOSURE,
29
1
                RISKY,
30
1
                "(handler-case (progn (setf *k* (risky)) 0) (t (e) 0)) (list *k*)",
31
1
            ],
32
1
        ),
33
1
        row(
34
1
            "L1c",
35
1
            &[
36
1
                CLOSURE,
37
1
                &format!("(let ((x 1)) {} (list *k* x))", caught_store()),
38
1
            ],
39
1
        ),
40
1
        row(
41
1
            "L1d",
42
1
            &[
43
1
                CLOSURE,
44
1
                &format!("{} (defun getk () *k*)", caught_store()),
45
1
                "(getk)",
46
1
            ],
47
1
        ),
48
1
        row(
49
1
            "L1e",
50
1
            &[
51
1
                CLOSURE,
52
1
                &format!("(unwind-protect {} 0) (list *k*)", caught_store()),
53
1
            ],
54
1
        ),
55
1
        row(
56
1
            "L1f",
57
1
            &[CLOSURE, &format!("(when {NEVER} (setf *k* 6)) (list *k*)")],
58
1
        ),
59
1
        row(
60
1
            "L1g",
61
1
            &[CLOSURE, &format!("(when {ALWAYS} (setf *k* 6)) (list *k*)")],
62
1
        ),
63
1
        row(
64
1
            "L6a",
65
1
            &[&format!(
66
1
                "(block b (defvar *f* (progn (when {ALWAYS} (return-from b 1)) (lambda (x) x))) 0)"
67
1
            )],
68
1
        ),
69
1
        row(
70
1
            "L6b",
71
1
            &[&format!(
72
1
                "(block b (defvar *f* (progn (when {NEVER} (return-from b 1)) (lambda (x) x))) 0) (funcall *f* 4)"
73
1
            )],
74
1
        ),
75
1
        row(
76
1
            "L1h",
77
1
            &[
78
1
                CLOSURE,
79
1
                &format!("(when {NEVER} (setf *k* 6))"),
80
1
                "(setf *k* 7) (list *k*)",
81
1
            ],
82
1
        ),
83
    ]
84
1
}
85

            
86
/// What each row prints; CL reads the closure in the loud rows.
87
const TODAY: &[(&str, &[&str])] = &[
88
    ("L1a", &["-", LOST]),
89
    ("L1b", &["-", "risky", LOST]),
90
    ("L1c", &["-", LOST]),
91
    ("L1d", &["-", "getk", "#<closure:0>"]),
92
    ("L1e", &["-", LOST]),
93
    ("L1f", &["-", LOST]),
94
    ("L1g", &["-", "(6)"]),
95
    ("L6a", &["1"]),
96
    ("L6b", &["4"]),
97
    ("L1h", &["-", "nil", "(7)"]),
98
];
99

            
100
const LOST: &str = "err: VALUE-LOST: *K*: its closure value does not ";
101

            
102
#[test]
103
1
fn every_row_reads_as_common_lisp() {
104
1
    assert_pinned(&rows(), TODAY);
105
1
}