mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
fix: len counting label leading to incorrent jmp
This commit is contained in:
parent
9f7e80dae2
commit
76dd657788
|
@ -56,9 +56,9 @@ impl Compiler {
|
|||
let mut then = self.compile(cdr[1].clone())?;
|
||||
let mut else_ = self.compile(cdr[2].clone())?;
|
||||
|
||||
result.push(Instr::JumpIfFalse { to: then.len() + 1}); // +1 for the jump instr
|
||||
result.push(Instr::JumpIfFalse { to: len(&then) + 1}); // +1 for the jump instr
|
||||
result.append(&mut then);
|
||||
result.push(Instr::Jump { to: else_.len() });
|
||||
result.push(Instr::Jump { to: len(&else_) });
|
||||
result.append(&mut else_);
|
||||
}
|
||||
_ => {
|
||||
|
@ -158,4 +158,16 @@ impl Compiler {
|
|||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
fn len(vec: &Vec<Instr>) -> usize {
|
||||
let mut result = 0;
|
||||
for i in vec {
|
||||
match i {
|
||||
Instr::Comment { .. } => {},
|
||||
Instr::Label { .. } => {},
|
||||
_ => { result += 1; },
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
(fun print_true (print "True"))
|
||||
(fun print_false (print "False"))
|
||||
(fun main
|
||||
(if true
|
||||
(print "True")
|
||||
(print "False")))
|
||||
(if true print_true print_false))
|
Loading…
Reference in a new issue