feat: SCC analysis (thunk capture WIP)

This commit is contained in:
2025-06-17 11:53:54 +08:00
parent b2d2490327
commit 7f6848c9e5
19 changed files with 501 additions and 458 deletions

View File

@@ -16,7 +16,9 @@ use super::eval;
#[inline]
fn test_expr(expr: &str, expected: Value) {
let (downgraded, _) = downgrade(rnix::Root::parse(expr).tree().expr().unwrap()).unwrap();
println!("{expr}");
let downgraded = downgrade(rnix::Root::parse(expr).tree().expr().unwrap()).unwrap();
println!("{downgraded:?}");
assert_eq!(eval(downgraded).unwrap(), expected);
}
@@ -148,6 +150,13 @@ fn test_attrs() {
symbol!("a") => int!(1)
},
);
test_expr(
"rec { a = 1; b = a; }",
attrs! {
symbol!("a") => int!(1),
symbol!("b") => thunk!()
},
);
test_expr("{ a = 1; }.a", int!(1));
test_expr("{ a = 1; }.b or 1", int!(1));
test_expr(
@@ -193,7 +202,7 @@ fn test_let() {
fn test_func() {
test_expr("(x: x) 1", int!(1));
test_expr("(x: x) (x: x) 1", int!(1));
test_expr("(x: y: x + y) 1 1", int!(2));
test_expr("(x: y: x / y) 1 2", int!(0));
test_expr("({ x, y }: x + y) { x = 1; y = 2; }", int!(3));
test_expr("({ x, y, ... }: x + y) { x = 1; y = 2; z = 3; }", int!(3));
test_expr(