fix extra pop regression
This commit is contained in:
parent
5ae4742840
commit
23b8beb291
|
@ -316,10 +316,14 @@ pub struct Compiler<'a> {
|
|||
loop_info: Vec<LoopInfo>,
|
||||
}
|
||||
|
||||
fn is_let(expr: &Spanned<Ast>) -> bool {
|
||||
fn is_binding(expr: &Spanned<Ast>) -> 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);
|
||||
|
|
26
src/main.rs
26
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 ()
|
||||
|
||||
|
||||
";
|
||||
|
|
Loading…
Reference in New Issue
Block a user