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.stack_depth += 1;
let biter = self.bindings.iter().rev();
for binding in biter {
// let biter = self.bindings.iter().rev();
for binding in self.bindings.iter() {
if binding.name == *fn_name {
self.emit_byte(binding.stack_pos);
break;
@ -1261,12 +1261,21 @@ impl<'a> Compiler<'a> {
}
}
}
Arguments(..)
| Placeholder
| Do(..)
| Splat(..)
| InterpolatedPattern(..)
| Splattern(..) => todo!(),
Do(terms) => {
let mut terms = terms.iter();
let first = terms.next().unwrap();
// put the first value on the stack
self.visit(first);
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!(),
}
}

View File

@ -57,28 +57,32 @@ pub fn run(src: &'static str) {
println!("\n\n")
}
// if DEBUG_RUN {
// println!("=== vm run: test ===");
// }
if DEBUG_RUN {
println!("=== vm run: test ===");
}
// let vm_chunk = compiler.chunk;
let vm_chunk = compiler.chunk;
// let mut vm = Vm::new(vm_chunk);
// let result = vm.run();
// let output = match result {
// Ok(val) => val.show(),
// Err(panic) => format!("Ludus panicked! {panic}"),
// };
// vm.print_stack();
// println!("{output}");
let mut vm = Vm::new(vm_chunk);
let result = vm.run();
let output = match result {
Ok(val) => val.show(),
Err(panic) => format!("Ludus panicked! {panic}"),
};
vm.print_stack();
println!("{output}");
}
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
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
";