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>,
|
loop_info: Vec<LoopInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_let(expr: &Spanned<Ast>) -> bool {
|
fn is_binding(expr: &Spanned<Ast>) -> bool {
|
||||||
let (ast, _) = expr;
|
let (ast, _) = expr;
|
||||||
use Ast::*;
|
use Ast::*;
|
||||||
matches!(ast, Let(..))
|
match ast {
|
||||||
|
Let(..) | LBox(..) => true,
|
||||||
|
Fn(name, ..) => !name.is_empty(),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Compiler<'a> {
|
impl<'a> Compiler<'a> {
|
||||||
|
@ -463,6 +467,7 @@ impl<'a> Compiler<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop(&mut self) {
|
fn pop(&mut self) {
|
||||||
|
println!("Popping from: {}", self.ast);
|
||||||
self.emit_op(Op::Pop);
|
self.emit_op(Op::Pop);
|
||||||
self.stack_depth -= 1;
|
self.stack_depth -= 1;
|
||||||
}
|
}
|
||||||
|
@ -515,7 +520,7 @@ impl<'a> Compiler<'a> {
|
||||||
self.scope_depth += 1;
|
self.scope_depth += 1;
|
||||||
let stack_depth = self.stack_depth;
|
let stack_depth = self.stack_depth;
|
||||||
for expr in lines.iter().take(lines.len() - 1) {
|
for expr in lines.iter().take(lines.len() - 1) {
|
||||||
if is_let(expr) {
|
if is_binding(expr) {
|
||||||
self.visit(expr);
|
self.visit(expr);
|
||||||
} else {
|
} else {
|
||||||
self.visit(expr);
|
self.visit(expr);
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -57,20 +57,20 @@ 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() {
|
||||||
|
@ -78,7 +78,7 @@ pub fn main() {
|
||||||
let src = "
|
let src = "
|
||||||
fn foo () -> :foo
|
fn foo () -> :foo
|
||||||
|
|
||||||
foo
|
foo ()
|
||||||
|
|
||||||
|
|
||||||
";
|
";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user