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 function defined inside a
6
//! binder sees the binder's variables when it is called after the binder.
7

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

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

            
13
const MUL: &str = "(let ((r 2)) (defun mul (x) (* x r)))";
14

            
15
1
fn rows() -> Vec<Row> {
16
1
    vec![
17
1
        row("L1", &[MUL, "(mul 4)"]),
18
1
        row("L2", &[MUL, "(defun twice (y) (mul y))", "(twice 5)"]),
19
1
        row(
20
1
            "L3",
21
1
            &["(let ((r (entity-count))) (defun cnt () r))", "(cnt)"],
22
1
        ),
23
1
        row(
24
1
            "L4",
25
1
            &["(progn (let ((r (entity-count))) (defun cnt () r)) (cnt))"],
26
1
        ),
27
1
        row(
28
1
            "L5",
29
1
            &[
30
1
                "(defvar *g* 7)",
31
1
                "(let ((r 2)) (let ((s 3)) (defun f () (+ r s *g*))))",
32
1
                "(f)",
33
1
            ],
34
1
        ),
35
1
        row(
36
1
            "L6",
37
1
            &["(let ((r 2)) (defun bump () (setf r (+ r 1))))", "(bump)"],
38
1
        ),
39
1
        row("L7", &["(let ((r 2)) (defun f () r) (setf r 5) (f))"]),
40
1
        row("L8", &[MUL, "(let ((r 50)) (mul 4))"]),
41
1
        row("L9", &[MUL, "(let ((r 50)) (mul 4))", "(mul 4)"]),
42
    ]
43
1
}
44

            
45
const RUNTIME: &str = "err: Compile error: CNT: reads R, a runtime varia";
46
const REBOUND: &str = "err: Compile error: BUMP: stores R, which the cal";
47
const REBOUND_MUL: &str = "err: Compile error: MUL: reads R, which the call ";
48

            
49
/// CL: L1 8, L2 10, L3 0, L4 0, L5 12, L6 3, L7 5, L8 8, L9 8 8. L3 and L6
50
/// stay loud: a runtime variable does not outlive its unit, and a captured
51
/// store has no shared place yet. L8 and L9 stay loud while a call site
52
/// rebinds the name.
53
const TODAY: &[(&str, &[&str])] = &[
54
    ("L1", &["mul", "8"]),
55
    ("L2", &["mul", "twice", "10"]),
56
    ("L3", &["cnt", RUNTIME]),
57
    ("L4", &["0"]),
58
    ("L5", &["-", "f", "12"]),
59
    ("L6", &["bump", REBOUND]),
60
    ("L7", &["5"]),
61
    ("L8", &["mul", REBOUND_MUL]),
62
    ("L9", &["mul", REBOUND_MUL, "8"]),
63
];
64

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