diff --git a/src/compiler.rs b/src/compiler.rs index f277a7b..20f2ec1 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -316,10 +316,14 @@ pub struct Compiler<'a> { loop_info: Vec, } -fn is_let(expr: &Spanned) -> bool { +fn is_binding(expr: &Spanned) -> bool { let (ast, _) = expr; use Ast::*; - matches!(ast, Let(..)) + match ast { + Let(..) | LBox(..) => true, + Fn(name, ..) => !name.is_empty(), + _ => false, + } } impl<'a> Compiler<'a> { @@ -463,6 +467,7 @@ impl<'a> Compiler<'a> { } fn pop(&mut self) { + println!("Popping from: {}", self.ast); self.emit_op(Op::Pop); self.stack_depth -= 1; } @@ -515,7 +520,7 @@ impl<'a> Compiler<'a> { self.scope_depth += 1; let stack_depth = self.stack_depth; for expr in lines.iter().take(lines.len() - 1) { - if is_let(expr) { + if is_binding(expr) { self.visit(expr); } else { self.visit(expr); diff --git a/src/main.rs b/src/main.rs index b880a65..dfcc9bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,20 +57,20 @@ 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() { @@ -78,7 +78,7 @@ pub fn main() { let src = " fn foo () -> :foo -foo +foo () ";