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: a nil-init DO variable is sized by the value its step yields,
6
//! whatever the step's leading forms. An Index or scalar cannot hold the nil
7
//! seed, so its home is any value.
8

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

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

            
14
const PT: &str = "(defstruct pt x)";
15
const G: &str = "(defvar *g* 0)";
16

            
17
8
fn counting(step: &str) -> String {
18
8
    format!(
19
8
        "(let ((p (make-pt)) (n (length (list 1 2)))) (do ((i 0 (+ i 1)) (v nil {step})) ((= i n) v)))"
20
    )
21
8
}
22

            
23
1
fn rows() -> Vec<Row> {
24
1
    vec![
25
1
        row("H3a", &[PT, G, &counting("(progn (setf *g* i) i)")]),
26
1
        row("H3b", &[PT, G, &counting("(setf (pt-x p) i)")]),
27
1
        row("H3c", &[PT, G, &counting("(progn (setf *g* i) 1/2)")]),
28
1
        row("H3d", &[PT, G, &counting("i")]),
29
1
        row("H3e", &[PT, G, &counting("(progn (setf *g* i) \"s\")")]),
30
1
        row(
31
1
            "H3f",
32
1
            &[PT, G, &counting("(progn (setf *g* i) (cons i v))")],
33
1
        ),
34
1
        row("H3g", &[PT, G, &counting("(make-pt :x v)")]),
35
1
        row("H3h", &[PT, G, &counting("(cons i v)")]),
36
    ]
37
1
}
38

            
39
/// CL: H3a 1, H3b 1, H3c 1/2, H3d 1, H3e "s", H3f (1 0), H3g
40
/// #S(PT :X #S(PT :X nil)), H3h (1 0).
41
const CL: &[(&str, &[&str])] = &[
42
    ("H3a", &["pt", "-", "1"]),
43
    ("H3b", &["pt", "-", "1"]),
44
    ("H3c", &["pt", "-", "1/2"]),
45
    ("H3d", &["pt", "-", "1"]),
46
    ("H3e", &["pt", "-", "\"s\""]),
47
    ("H3f", &["pt", "-", "(1 0)"]),
48
    ("H3g", &["pt", "-", "#S(PT :X #S(PT :X nil))"]),
49
    ("H3h", &["pt", "-", "(1 0)"]),
50
];
51

            
52
#[test]
53
1
fn every_row_reads_as_common_lisp() {
54
1
    assert_pinned(&rows(), CL);
55
1
}