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!(),
}
// TODO: implement longer synthetic expressions
for term in rest {
todo!()
for (term, _) in rest {
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) => {

View File

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