implement multiterm synthetic expressions

This commit is contained in:
Scott Richmond 2025-06-03 19:13:40 -04:00
parent fc245348b4
commit c497b90a16
2 changed files with 23 additions and 11 deletions

View File

@ -860,8 +860,27 @@ impl Compiler {
_ => unreachable!(), _ => unreachable!(),
} }
// TODO: implement longer synthetic expressions // TODO: implement longer synthetic expressions
for term in rest { for (term, _) in rest {
todo!() match term {
Keyword(str) => {
self.emit_constant(Value::Keyword(str));
self.emit_op(Op::GetKey);
self.stack_depth -= 1;
}
Arguments(args) => {
self.emit_op(Op::Stash);
self.pop();
let arity = args.len();
for arg in args {
self.visit(arg);
}
self.emit_op(Op::Load);
self.emit_op(Op::Call);
self.emit_byte(arity);
self.stack_depth -= arity;
}
_ => unreachable!(),
}
} }
} }
When(clauses) => { When(clauses) => {

View File

@ -76,16 +76,9 @@ pub fn run(src: &'static str) {
pub fn main() { pub fn main() {
env::set_var("RUST_BACKTRACE", "1"); env::set_var("RUST_BACKTRACE", "1");
let src = " let src = "
fn foo () -> { fn foo () -> fn () -> fn () -> #{:foo :bar}
let x = :foo
let y = :bar
(x, y)
}
let a = foo () foo () () () :foo
let b = foo ()
(a, b)
"; ";
run(src); run(src);
} }