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 head names only a function and an operand only a variable (plan L2-3):
//! a variable is never called and a function name never read as a value. Each
//! row ends in the SBCL outcome, an undefined function or an unbound variable.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
fn whole(label: &'static str, forms: &[&str]) -> Row {
row(label, &[&forms.join(" ")])
}
const DEFUN_DBL: &str = "(defun dbl (x) (* x 2))";
const DEFUN_POS: &str = "(defun pos (x) (> x 0))";
fn rows() -> Vec<Row> {
vec![
row(
"S1",
&["(defun app (f v) (f v))", "(app (lambda (x) (+ x 1)) 4)"],
),
row("S2", &["(defun add (a b) (+ a b))", "(funcall add 1 2)"]),
whole("S3", &[DEFUN_DBL, "(map dbl (list 1 2))"]),
whole("S4", &["(fold + 0 (list 1 2))"]),
whole("S5", &[DEFUN_POS, "(filter pos (list 1 -2))"]),
whole("S6", &[DEFUN_POS, "(apply pos (list 1))"]),
whole("S7", &["(funcall entity-count)"]),
"S8",
&[
"(defmacro call1 (g) `(,g 1))",
"(let ((k (lambda (x) x))) (call1 k))",
],
whole("S9", &["(let ((f (lambda (x) (+ x 1)))) (f 4))"]),
whole("S10", &["(defvar *k* (lambda (x) x)) (*k* 3)"]),
row("S11", &["(defun add (a b) (+ a b))", "(funcall #'add 1 2)"]),
whole("S12", &[DEFUN_DBL, "(map #'dbl (list 1 2))"]),
whole("S13", &["(fold #'+ 0 (list 1 2))"]),
whole("S14", &[DEFUN_POS, "(filter #'pos (list 1 -2))"]),
whole("S15", &[DEFUN_POS, "(apply #'pos (list 1))"]),
"S16",
"(defun app (f v) (funcall f v))",
"(app (lambda (x) (+ x 1)) 4)",
]
const HEAD_F: &str = "err: Compile error: undefined function F; use (fu";
const HEAD_K: &str = "err: Compile error: undefined function K; use (fu";
const UNBOUND_ADD: &str = "err: Compile error: variable ADD is unbound; use ";
const UNBOUND_POS: &str = "err: Compile error: variable POS is unbound; use ";
const UNBOUND_DBL: &str = "err: Compile error: variable DBL is unbound; use ";
const UNBOUND_PLUS: &str = "err: Compile error: variable + is unbound; use '+";
/// SBCL: S1, S8, S9, S10 undefined function; S2-S7 unbound variable (MAP,
/// FOLD and FILTER read a function name as a value before any call is built);
/// S11-S16 are the strict spellings of the same calls.
const TODAY: &[(&str, &[&str])] = &[
("S1", &["app", HEAD_F]),
("S2", &["add", UNBOUND_ADD]),
("S3", &[UNBOUND_DBL]),
("S4", &[UNBOUND_PLUS]),
("S5", &[UNBOUND_POS]),
("S6", &[UNBOUND_POS]),
("S7", &["err: Compile error: variable ENTITY-COUNT is unbo"]),
("S8", &["call1", HEAD_K]),
("S9", &[HEAD_F]),
(
"S10",
&["err: Compile error: undefined function *K*; use ("],
("S11", &["add", "3"]),
("S12", &["(2 4)"]),
("S13", &["3"]),
("S14", &["(1)"]),
("S15", &["t"]),
("S16", &["app", "5"]),
];
#[test]
fn a_head_is_a_function_and_an_operand_is_a_variable() {
assert_pinned(&rows(), TODAY);