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 4 rows with their Common Lisp values: where a
6
//! definition an exit may skip is refused.
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) 0)";
15

            
16
1
fn rows() -> Vec<Row> {
17
1
    vec![
18
1
        row(
19
1
            "H1a",
20
1
            &[&format!(
21
1
                "(handler-case (progn (when {ALWAYS} (error 'boom \"m\")) (defun f () 2) 0) (t (e) 0)) (f)"
22
1
            )],
23
1
        ),
24
1
        row(
25
1
            "H1b",
26
1
            &[&format!(
27
1
                "(handler-case (progn (when {ALWAYS} (error 'boom \"m\")) (defun f () 2) nil) (t (e) 0)) (f)"
28
1
            )],
29
1
        ),
30
1
        row(
31
1
            "H1c",
32
1
            &[&format!(
33
1
                "(block outer (handler-case (progn (when {ALWAYS} (error 'boom \"m\")) (defun f () 2) 0) (t (e) 0)) (f))"
34
1
            )],
35
1
        ),
36
1
        row(
37
1
            "H1d",
38
1
            &[&format!(
39
1
                "(defvar *total* 0) (defun load-rows () (if {ALWAYS} (error 'no-data \"none\") 5)) (handler-case (progn (setf *total* (load-rows)) (defun report () (* *total* 2)) nil) (t (e) (print \"load failed\"))) (report)"
40
1
            )],
41
1
        ),
42
1
        row(
43
1
            "R2a",
44
1
            &[
45
1
                &format!(
46
1
                    "(block b (when {NEVER} (return-from b 1)) (defun f () 2) (defun f () 3) 0)"
47
1
                ),
48
1
                "(f)",
49
1
            ],
50
1
        ),
51
1
        row(
52
1
            "R2b",
53
1
            &[
54
1
                &format!(
55
1
                    "(block b (when {NEVER} (return-from b 1)) (defun f () 2) (defun f () 3) (quote z))"
56
1
                ),
57
1
                "(f)",
58
1
            ],
59
1
        ),
60
1
        row(
61
1
            "R2c",
62
1
            &[
63
1
                &format!(
64
1
                    "(block b (when {ALWAYS} (return-from b 1)) (defun f () 2) (defun f () 3) 0)"
65
1
                ),
66
1
                "(f)",
67
1
            ],
68
1
        ),
69
1
        row(
70
1
            "I3a",
71
1
            &[
72
1
                "(block outer (when (> (entity-count) 99) (return-from outer 1)) (block inner (defun f () 2) 0) (f))",
73
1
            ],
74
1
        ),
75
1
        row(
76
1
            "I3b",
77
1
            &[
78
1
                "(block outer (when (> (entity-count) 99) (return-from outer 1)) (tagbody (defun f () 2)) (f))",
79
1
            ],
80
1
        ),
81
1
        row(
82
1
            "I3c",
83
1
            &[
84
1
                "(block outer (when (> (entity-count) 99) (return-from outer 1)) (handler-case (progn (defun f () 2) 0) (t (e) 0)) (f))",
85
1
            ],
86
1
        ),
87
1
        row(
88
1
            "I3d",
89
1
            &[
90
1
                "(block outer (when (> (entity-count) 99) (return-from outer 1)) (block inner (when (> (entity-count) 99) (return-from inner 1)) (defun f () 2) 0) (f))",
91
1
            ],
92
1
        ),
93
1
        row(
94
1
            "L4a",
95
1
            &[
96
1
                "(defvar v (lambda (x) (+ x 2))) (setf v (lambda (x) (+ x 1)))",
97
1
                "(let ((v 5)) (funcall v 1))",
98
1
                "(let ((v 5)) (list (funcall v 1)))",
99
1
                "(funcall v 1)",
100
1
            ],
101
1
        ),
102
    ]
103
1
}
104

            
105
const TODAY: &[(&str, &[&str])] = &[
106
    // Q1: refused at the definition, not at the use after the region
107
    (
108
        "H1a",
109
        &["err: Compile error: DEFUN F follows a form that m"],
110
    ),
111
    (
112
        "H1b",
113
        &["err: Compile error: DEFUN F follows a form that m"],
114
    ),
115
    (
116
        "H1c",
117
        &["err: Compile error: DEFUN F follows a form that m"],
118
    ),
119
    (
120
        "H1d",
121
        &["err: Compile error: DEFUN REPORT follows a form t"],
122
    ),
123
    // Q1: the first definition after the exit is refused
124
    (
125
        "R2a",
126
        &[
127
            "err: Compile error: DEFUN F follows a form that m",
128
            "err: Undefined symbol: F",
129
        ],
130
    ),
131
    (
132
        "R2b",
133
        &[
134
            "err: Compile error: DEFUN F follows a form that m",
135
            "err: Undefined symbol: F",
136
        ],
137
    ),
138
    (
139
        "R2c",
140
        &[
141
            "err: Compile error: DEFUN F follows a form that m",
142
            "err: Undefined symbol: F",
143
        ],
144
    ),
145
    // Q1: refused although the inner region itself has no exit; the outer exit precedes it
146
    (
147
        "I3a",
148
        &["err: Compile error: DEFUN F follows a form that m"],
149
    ),
150
    (
151
        "I3b",
152
        &["err: Compile error: DEFUN F follows a form that m"],
153
    ),
154
    (
155
        "I3c",
156
        &["err: Compile error: DEFUN F follows a form that m"],
157
    ),
158
    (
159
        "I3d",
160
        &["err: Compile error: DEFUN F follows a form that m"],
161
    ),
162
    (
163
        "L4a",
164
        &[
165
            "#<closure:1>",
166
            "err: Compile error: not callable: #<global:3:i32>",
167
            "err: Compile error: not callable: #<global:3:i32>",
168
            "2",
169
        ],
170
    ),
171
];
172

            
173
#[test]
174
1
fn every_row_reads_as_common_lisp() {
175
1
    assert_pinned(&rows(), TODAY);
176
1
}