Lines
100 %
Functions
Branches
use std::collections::HashMap;
use super::*;
use crate::ast::{Number, PairElement};
use crate::runtime::{Symbol, SymbolKind};
fn zero() -> Expr {
Expr::Number(Number::Index(0))
}
fn key() -> HomeKey {
HomeKey::Binder(None, 7, "X".to_string(), 9)
#[test]
fn a_binder_without_a_fact_has_no_hint() {
let mut symbols = SymbolTable::new();
symbols.begin_home_attempt(HashMap::new());
assert_eq!(symbols.hint(&key()), None);
fn a_binder_store_the_home_cannot_hold_widens_the_next_attempt() {
symbols.open_binder(
&key(),
Arm::NumberLiteral(WasmType::I32),
None,
WasmType::I32,
);
symbols.note_store(&key(), Arm::Value(WasmType::I32));
assert_eq!(symbols.widened_homes(), None);
symbols.note_store(&key(), Arm::Nil);
assert_eq!(
symbols.widened_homes(),
Some(HashMap::from([(key(), WasmType::AnyRef)]))
fn a_binder_fact_is_the_hint_of_the_next_attempt_and_joins_with_its_stores() {
let hint = HashMap::from([(key(), WasmType::PairRef(PairElement::I32))]);
symbols.begin_home_attempt(hint);
symbols.hint(&key()),
Some(WasmType::PairRef(PairElement::I32))
symbols.open_binder(&key(), Arm::Nil, None, WasmType::PairRef(PairElement::I32));
symbols.note_store(&key(), Arm::Value(WasmType::PairRef(PairElement::Ratio)));
Some(HashMap::from([(
key(),
WasmType::PairRef(PairElement::AnyRef)
)]))
fn the_first_instance_of_a_binder_site_decides_its_home() {
symbols.open_binder(&key(), Arm::Value(WasmType::I32), None, WasmType::I32);
symbols.open_binder(&key(), Arm::Value(WasmType::Ratio), None, WasmType::Ratio);
symbols.note_store(&key(), Arm::Value(WasmType::Ratio));
fn binder_homes_are_counted_with_the_sites_and_named_by_their_variable() {
symbols.open_binder(&key(), Arm::Nil, None, WasmType::Bool);
assert_eq!(symbols.site_home_count(), 1);
assert_eq!(key().to_string(), "variable X");
fn a_binder_probe_reads_the_constant_its_init_kept() {
symbols.define(
Symbol::new("X", SymbolKind::Variable).with_value(Expr::WasmLocal(0, WasmType::I32)),
Some(zero()),
let probe = symbols.probe_at_init(&key(), "X").expect("probe");
probe.lookup("X").and_then(|symbol| symbol.value().cloned()),
Some(zero())
assert!(probe.probe_at_init(&key(), "X").is_none());