add do forms

This commit is contained in:
Scott Richmond 2025-06-05 12:15:49 -04:00
parent 23b8beb291
commit b8b720b877
2 changed files with 35 additions and 22 deletions

View File

@ -851,8 +851,8 @@ impl<'a> Compiler<'a> {
self.emit_op(Op::PushBinding); self.emit_op(Op::PushBinding);
self.stack_depth += 1; self.stack_depth += 1;
let biter = self.bindings.iter().rev(); // let biter = self.bindings.iter().rev();
for binding in biter { for binding in self.bindings.iter() {
if binding.name == *fn_name { if binding.name == *fn_name {
self.emit_byte(binding.stack_pos); self.emit_byte(binding.stack_pos);
break; break;
@ -1261,12 +1261,21 @@ impl<'a> Compiler<'a> {
} }
} }
} }
Arguments(..) Do(terms) => {
| Placeholder let mut terms = terms.iter();
| Do(..) let first = terms.next().unwrap();
| Splat(..) // put the first value on the stack
| InterpolatedPattern(..) self.visit(first);
| Splattern(..) => todo!(), for term in terms {
self.visit(term);
self.emit_op(Op::Call);
self.emit_byte(1);
self.stack_depth -= 1;
}
}
Arguments(..) | Placeholder | Splat(..) | InterpolatedPattern(..) | Splattern(..) => {
todo!()
}
And | Or => unreachable!(), And | Or => unreachable!(),
} }
} }

View File

@ -57,28 +57,32 @@ pub fn run(src: &'static str) {
println!("\n\n") println!("\n\n")
} }
// if DEBUG_RUN { if DEBUG_RUN {
// println!("=== vm run: test ==="); println!("=== vm run: test ===");
// } }
// let vm_chunk = compiler.chunk; let vm_chunk = compiler.chunk;
// let mut vm = Vm::new(vm_chunk); let mut vm = Vm::new(vm_chunk);
// let result = vm.run(); let result = vm.run();
// let output = match result { let output = match result {
// Ok(val) => val.show(), Ok(val) => val.show(),
// Err(panic) => format!("Ludus panicked! {panic}"), Err(panic) => format!("Ludus panicked! {panic}"),
// }; };
// vm.print_stack(); vm.print_stack();
// println!("{output}"); println!("{output}");
} }
pub fn main() { pub fn main() {
env::set_var("RUST_BACKTRACE", "1"); env::set_var("RUST_BACKTRACE", "1");
let src = " let src = "
fn foo () -> :foo fn increase (x) -> add (x, 1)
foo () fn double (x) -> mult (x, 2)
fn halve (x) -> div (x, 2)
do 1 > increase > double > increase > halve
"; ";