Lines
100 %
Functions
Branches
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! A function operand named by a variable is the variable's value, never the
//! function of the same name (plan L2-2); the SBCL value is in each row.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, assert_pinned_wide, row};
fn whole(label: &'static str, forms: &[&str]) -> Row {
row(label, &[&forms.join(" ")])
}
const G_AND_F: &str = "(defun g (x) 7) (defun f (x) 100)";
fn value_rows() -> Vec<Row> {
vec![
whole(
"A1",
&["(defun f (x) 100) (defun app (f v) (funcall f v)) (app 'car (list 1 2))"],
),
whole("A2", &[G_AND_F, "(let ((f 'g)) (funcall f 1))"]),
whole("A4", &[G_AND_F, "(let ((f 'g)) (map f (list 1 2)))"]),
"A5",
&["(defun g (a x) (+ a x)) (defun f (a b) 100) (let ((f 'g)) (fold f 0 (list 1 2)))"],
"A6",
&["(defun g (x) (< x 2)) (defun f (x) nil) (let ((f 'g)) (filter f (list 1 2)))"],
whole("A14", &[G_AND_F, "(defvar f 'g) (funcall f 1)"]),
"A38",
&[
G_AND_F,
"(let ((f 'g)) (list (f 1) (funcall f 1) (apply f (list 1))))",
],
]
/// SBCL: A1 1, A2 7, A4 (7 7), A5 3, A6 (1), A14 7, A38 (100 7 7).
const VALUES: &[(&str, &[&str])] = &[
("A1", &["1"]),
("A2", &["7"]),
("A4", &["(7 7)"]),
("A5", &["3"]),
("A6", &["(1)"]),
("A14", &["7"]),
("A38", &["(100 7 7)"]),
];
#[test]
fn a_variable_operand_is_its_value() {
assert_pinned(&value_rows(), VALUES);
fn closure_element_rows() -> Vec<Row> {
"B1",
"(defun f (x) 100) (let ((r 0)) (dolist (f (list (lambda (x) 1))) (setf r (funcall f 0))) r)",
"B6",
"(labels ((f (x) 100)) (let ((r 0)) (dolist (f (list (lambda (x) 1))) (setf r (funcall f 0))) r))",
"A31",
"(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)",
/// SBCL B1 1, B6 1, A31 203: a closure element of a list is called as the
/// closure, never read as the function `f`.
const PINNED: &[(&str, &[&str])] = &[("B1", &["1"]), ("B6", &["1"]), ("A31", &["203"])];
fn a_closure_element_is_never_read_as_the_function() {
assert_pinned_wide(&closure_element_rows(), PINNED, 28);