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 function operand named by a variable is the variable's value, never the
6
//! function of the same name (plan L2-2); the SBCL value is in each row.
7

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

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

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

            
17
const G_AND_F: &str = "(defun g (x) 7) (defun f (x) 100)";
18

            
19
1
fn value_rows() -> Vec<Row> {
20
1
    vec![
21
1
        whole(
22
1
            "A1",
23
1
            &["(defun f (x) 100) (defun app (f v) (funcall f v)) (app 'car (list 1 2))"],
24
1
        ),
25
1
        whole("A2", &[G_AND_F, "(let ((f 'g)) (funcall f 1))"]),
26
1
        whole("A4", &[G_AND_F, "(let ((f 'g)) (map f (list 1 2)))"]),
27
1
        whole(
28
1
            "A5",
29
1
            &["(defun g (a x) (+ a x)) (defun f (a b) 100) (let ((f 'g)) (fold f 0 (list 1 2)))"],
30
1
        ),
31
1
        whole(
32
1
            "A6",
33
1
            &["(defun g (x) (< x 2)) (defun f (x) nil) (let ((f 'g)) (filter f (list 1 2)))"],
34
1
        ),
35
1
        whole("A14", &[G_AND_F, "(defvar f 'g) (funcall f 1)"]),
36
1
        whole(
37
1
            "A38",
38
1
            &[
39
1
                G_AND_F,
40
1
                "(let ((f 'g)) (list (f 1) (funcall f 1) (apply f (list 1))))",
41
1
            ],
42
1
        ),
43
    ]
44
1
}
45

            
46
/// SBCL: A1 1, A2 7, A4 (7 7), A5 3, A6 (1), A14 7, A38 (100 7 7).
47
const VALUES: &[(&str, &[&str])] = &[
48
    ("A1", &["1"]),
49
    ("A2", &["7"]),
50
    ("A4", &["(7 7)"]),
51
    ("A5", &["3"]),
52
    ("A6", &["(1)"]),
53
    ("A14", &["7"]),
54
    ("A38", &["(100 7 7)"]),
55
];
56

            
57
#[test]
58
1
fn a_variable_operand_is_its_value() {
59
1
    assert_pinned(&value_rows(), VALUES);
60
1
}
61

            
62
1
fn closure_element_rows() -> Vec<Row> {
63
1
    vec![
64
1
        whole(
65
1
            "B1",
66
1
            &[
67
1
                "(defun f (x) 100) (let ((r 0)) (dolist (f (list (lambda (x) 1))) (setf r (funcall f 0))) r)",
68
1
            ],
69
1
        ),
70
1
        whole(
71
1
            "B6",
72
1
            &[
73
1
                "(labels ((f (x) 100)) (let ((r 0)) (dolist (f (list (lambda (x) 1))) (setf r (funcall f 0))) r))",
74
1
            ],
75
1
        ),
76
1
        whole(
77
1
            "A31",
78
1
            &[
79
1
                "(defun f (x) 100) (let ((r 0)) (dolist (f (list (lambda (x) 1) (lambda (x) 2))) (setf r (+ r (funcall f 0) (f 0)))) r)",
80
1
            ],
81
1
        ),
82
    ]
83
1
}
84

            
85
/// SBCL B1 1, B6 1, A31 203: a closure element of a list is called as the
86
/// closure, never read as the function `f`.
87
const PINNED: &[(&str, &[&str])] = &[("B1", &["1"]), ("B6", &["1"]), ("A31", &["203"])];
88

            
89
#[test]
90
1
fn a_closure_element_is_never_read_as_the_function() {
91
1
    assert_pinned_wide(&closure_element_rows(), PINNED, 28);
92
1
}