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 S6 rows with their Common Lisp values: a closure whose body names
6
//! a function or macro that does not outlive its unit is not carried.
7

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

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

            
13
const LABELS_K: &str = "(defvar *k* (labels ((h (y) (* y 10))) (lambda (x) (h x))))";
14
const DBL: &str = "(defmacro dbl (x) `(* ,x 2))";
15

            
16
1
fn rows() -> Vec<Row> {
17
1
    vec![
18
1
        row("B1", &[LABELS_K, "'*k*"]),
19
1
        row("B2", &[LABELS_K, "(+ 1 2) '*k*"]),
20
1
        row("B3", &[LABELS_K, "(funcall *k* 3)"]),
21
1
        row(
22
1
            "B4",
23
1
            &[
24
1
                DBL,
25
1
                "(defvar *k* (lambda (y) (dbl y)))",
26
1
                "(defmacro dbl (x) `(* ,x 3))",
27
1
                "(funcall *k* 1)",
28
1
            ],
29
1
        ),
30
1
        row(
31
1
            "B6",
32
1
            &[DBL, "(defvar *k* (lambda (y) (dbl y)))", "(funcall *k* 4)"],
33
1
        ),
34
1
        row(
35
1
            "B7",
36
1
            &[
37
1
                DBL,
38
1
                "(defvar *k* (lambda (y) (mapcar (lambda (z) (dbl z)) (list y))))",
39
1
                "(defmacro dbl (x) `(* ,x 3))",
40
1
                "(funcall *k* 1)",
41
1
            ],
42
1
        ),
43
1
        row(
44
1
            "B5",
45
1
            &[
46
1
                "(defvar *k* (lambda (x) (when (> x 0) 1)))",
47
1
                "(funcall *k* 3)",
48
1
            ],
49
1
        ),
50
    ]
51
1
}
52

            
53
/// CL: B1/B2 `*k*`, B3 30, B4 2, B5 1. B3 stays loud (the LABELS function does not
54
/// survive); B4 keeps the body expanded at creation.
55
const TODAY: &[(&str, &[&str])] = &[
56
    ("B1", &["-", "*k*"]),
57
    ("B2", &["-", "*k*"]),
58
    ("B3", &["-", LOST]),
59
    ("B4", &["dbl", "-", "dbl", "2"]),
60
    ("B6", &["dbl", "-", "8"]),
61
    ("B7", &["dbl", "-", "dbl", "(2)"]),
62
    ("B5", &["-", "1"]),
63
];
64

            
65
const LOST: &str = "err: Compile error: *K*: its closure value does n";
66

            
67
#[test]
68
1
fn every_row_reads_as_common_lisp() {
69
1
    assert_pinned(&rows(), TODAY);
70
1
}