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
//! A head names only a function and an operand only a variable (plan L2-3):
6
//! a variable is never called and a function name never read as a value. Each
7
//! row ends in the SBCL outcome, an undefined function or an unbound variable.
8

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

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

            
14
11
fn whole(label: &'static str, forms: &[&str]) -> Row {
15
11
    row(label, &[&forms.join(" ")])
16
11
}
17

            
18
const DEFUN_DBL: &str = "(defun dbl (x) (* x 2))";
19
const DEFUN_POS: &str = "(defun pos (x) (> x 0))";
20

            
21
1
fn rows() -> Vec<Row> {
22
1
    vec![
23
1
        row(
24
1
            "S1",
25
1
            &["(defun app (f v) (f v))", "(app (lambda (x) (+ x 1)) 4)"],
26
1
        ),
27
1
        row("S2", &["(defun add (a b) (+ a b))", "(funcall add 1 2)"]),
28
1
        whole("S3", &[DEFUN_DBL, "(map dbl (list 1 2))"]),
29
1
        whole("S4", &["(fold + 0 (list 1 2))"]),
30
1
        whole("S5", &[DEFUN_POS, "(filter pos (list 1 -2))"]),
31
1
        whole("S6", &[DEFUN_POS, "(apply pos (list 1))"]),
32
1
        whole("S7", &["(funcall entity-count)"]),
33
1
        row(
34
1
            "S8",
35
1
            &[
36
1
                "(defmacro call1 (g) `(,g 1))",
37
1
                "(let ((k (lambda (x) x))) (call1 k))",
38
1
            ],
39
1
        ),
40
1
        whole("S9", &["(let ((f (lambda (x) (+ x 1)))) (f 4))"]),
41
1
        whole("S10", &["(defvar *k* (lambda (x) x)) (*k* 3)"]),
42
1
        row("S11", &["(defun add (a b) (+ a b))", "(funcall #'add 1 2)"]),
43
1
        whole("S12", &[DEFUN_DBL, "(map #'dbl (list 1 2))"]),
44
1
        whole("S13", &["(fold #'+ 0 (list 1 2))"]),
45
1
        whole("S14", &[DEFUN_POS, "(filter #'pos (list 1 -2))"]),
46
1
        whole("S15", &[DEFUN_POS, "(apply #'pos (list 1))"]),
47
1
        row(
48
1
            "S16",
49
1
            &[
50
1
                "(defun app (f v) (funcall f v))",
51
1
                "(app (lambda (x) (+ x 1)) 4)",
52
1
            ],
53
1
        ),
54
    ]
55
1
}
56

            
57
const HEAD_F: &str = "err: Compile error: undefined function F; use (fu";
58
const HEAD_K: &str = "err: Compile error: undefined function K; use (fu";
59
const UNBOUND_ADD: &str = "err: Compile error: variable ADD is unbound; use ";
60
const UNBOUND_POS: &str = "err: Compile error: variable POS is unbound; use ";
61
const UNBOUND_DBL: &str = "err: Compile error: variable DBL is unbound; use ";
62
const UNBOUND_PLUS: &str = "err: Compile error: variable + is unbound; use '+";
63

            
64
/// SBCL: S1, S8, S9, S10 undefined function; S2-S7 unbound variable (MAP,
65
/// FOLD and FILTER read a function name as a value before any call is built);
66
/// S11-S16 are the strict spellings of the same calls.
67
const TODAY: &[(&str, &[&str])] = &[
68
    ("S1", &["app", HEAD_F]),
69
    ("S2", &["add", UNBOUND_ADD]),
70
    ("S3", &[UNBOUND_DBL]),
71
    ("S4", &[UNBOUND_PLUS]),
72
    ("S5", &[UNBOUND_POS]),
73
    ("S6", &[UNBOUND_POS]),
74
    ("S7", &["err: Compile error: variable ENTITY-COUNT is unbo"]),
75
    ("S8", &["call1", HEAD_K]),
76
    ("S9", &[HEAD_F]),
77
    (
78
        "S10",
79
        &["err: Compile error: undefined function *K*; use ("],
80
    ),
81
    ("S11", &["add", "3"]),
82
    ("S12", &["(2 4)"]),
83
    ("S13", &["3"]),
84
    ("S14", &["(1)"]),
85
    ("S15", &["t"]),
86
    ("S16", &["app", "5"]),
87
];
88

            
89
#[test]
90
1
fn a_head_is_a_function_and_an_operand_is_a_variable() {
91
1
    assert_pinned(&rows(), TODAY);
92
1
}