Lines
100 %
Functions
Branches
use crate::ast::{Expr, PairElement, WasmType};
use crate::compiler::context::CompileContext;
use crate::compiler::emit::FunctionEmitter;
use crate::compiler::expr::{compile_for_stack, eval_value};
use crate::error::Result;
use crate::reader::Reader;
use crate::runtime::SymbolTable;
use super::spill::lambda_runs_at_runtime;
fn form(source: &str) -> Expr {
Reader::parse(source)
.expect("source parses")
.exprs
.into_iter()
.next()
.expect("one form")
}
fn stack_type(source: &str) -> Result<WasmType> {
let mut ctx = CompileContext::new_with_host_fns(&[])?;
let mut emit = FunctionEmitter::new();
let mut symbols = SymbolTable::with_builtins_for_wasm();
compile_for_stack(&mut ctx, &mut emit, &mut symbols, &form(source))
#[test]
fn a_lambda_literal_is_found_among_resolved_members() {
let lambda = eval_value(
&mut SymbolTable::with_builtins_for_wasm(),
&form("(lambda (x) x)"),
);
let symbols = SymbolTable::with_builtins_for_wasm();
assert!(lambda_runs_at_runtime(
&symbols,
&[Expr::Nil, lambda.expect("lambda")]
));
assert!(!lambda_runs_at_runtime(&symbols, &[Expr::Nil, Expr::T]));
fn a_list_with_a_lambda_literal_is_untyped_on_the_eval_surface() {
let value = eval_value(
&form("(list 1 (lambda (x) x))"),
assert_eq!(
value.expect("evaluates"),
Expr::WasmRuntime(WasmType::AnyRef)
fn a_list_of_one_lambda_rides_its_own_closure_cell() {
assert!(matches!(
stack_type("(list (lambda (x) x))"),
Ok(WasmType::PairRef(PairElement::Closure(_)))
fn a_lambda_beside_another_kind_widens_the_cell() {
stack_type("(list 1 (lambda (x) x) \"s\")").expect("compiles"),
WasmType::PairRef(PairElement::AnyRef)
fn lambdas_of_different_signatures_widen_the_cell() {
stack_type("(list (lambda (x) x) (lambda (x y) x))").expect("compiles"),