Lines
45 %
Functions
83.33 %
Branches
100 %
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! PERSIST review rows of Q46-1: a lambda built while a macro expands must
//! not read the caller's variables; each SBCL value is next to its row.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
struct Case {
label: &'static str,
units: &'static [&'static str],
pinned: &'static [&'static str],
}
const fn case(
) -> Case {
Case {
label,
units,
pinned,
const UNDEFINED_X: &str = "err: Undefined symbol: X";
const CASES: &[Case] = &[
case(
"P1",
&[
"(defmacro m () (let ((n 5)) (list 'quote (list (lambda () n)))))",
"(let ((n 7)) (funcall (car (m))))",
],
&["m", "5"],
),
"P2",
"(defmacro m (x) (list 'quote (list (lambda () x))))",
"(let ((x 7)) (funcall (car (m 3))))",
&["m", "3"],
"P2b",
"(let ((y 9)) (funcall (car (m y))))",
&["m", "y"],
"P5",
"(defmacro m () (let ((n 5)) (funcall (car (list (lambda () n))))))",
"(let ((n 7)) (m))",
"P7",
"(defmacro inner () (let ((n 5)) (list 'quote (list (lambda () n)))))",
"(defmacro outer () (list 'funcall (list 'car (list 'inner))))",
"(let ((n 7)) (outer))",
&["inner", "outer", "5"],
"P8",
"(let ((n 7)) (let ((f (lambda () (funcall (car (m)))))) (funcall f)))",
"P9",
"(defvar *k* (m))",
"(let ((n 7)) (funcall (car *k*)))",
&["m", "-", "5"],
"P11",
"(defmacro m (k) (let ((f (lambda (z) (+ z k)))) (list 'quote (list f))))",
"(funcall (car (m 10)) 1)",
&["m", "11"],
"P12",
"(defmacro m () (list 'quote (list (lambda () x))))",
"(let ((x 7)) (handler-case (funcall (car (m))) (t (e) 99)))",
&["m", UNDEFINED_X],
"P14",
"(defun g (n) (funcall (car (m))))",
"(g 7)",
&["m", "g", "5"],
"P15",
"(let ((r 0)) (dolist (n (list 1 2)) (setf r (+ r (the index (funcall (car (m))))))) r)",
&["m", "10"],
"W1",
"(defmacro m () (let ((s 'foo)) (list 'quote (list (lambda () s)))))",
"(let ((foo 7)) (funcall (car (m))))",
&["m", "foo"],
"W4",
"(defun g (y) (funcall (car (m y))))",
"(g 9)",
&["m", "g", "y"],
"V1",
"(defmacro m (x) (list 'quote (cons (lambda () x) nil)))",
"V2",
"(defmacro m (x) (list 'funcall (lambda () x)))",
"(let ((y 9)) (m y))",
"V3",
"(defmacro m () (list 'quote (cons (lambda () x) nil)))",
"V4",
"(defmacro m () (list 'funcall (lambda () x)))",
"(let ((x 7)) (handler-case (m) (t (e) 99)))",
"V5",
"(defmacro m (x) `(funcall ,(lambda () x)))",
"V6",
"(defmacro m (x) (let ((f (lambda () x))) (list 'funcall f)))",
"V7",
"(defmacro m (x) (cons 'funcall (cons (lambda () x) nil)))",
"V8",
"(defmacro m (x) (list 'quote (list (lambda () (list x x)))))",
"(let ((y 9)) (funcall (car (m (+ y 1)))))",
&["m", "((+ y 1) (+ y 1))"],
"V9",
"(let ((y 9)) (funcall (car (m \"s\"))))",
&["m", "\"s\""],
];
fn rows() -> Vec<Row> {
CASES.iter().map(|c| row(c.label, c.units)).collect()
fn pinned() -> Vec<(&'static str, &'static [&'static str])> {
CASES.iter().map(|c| (c.label, c.pinned)).collect()
#[test]
fn macro_lambda_scope_rows_read_as_pinned() {
assert_pinned(&rows(), &pinned());