aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index ad97783..727f177 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -559,9 +559,8 @@ impl Compiler {
// so we know from where to copy them.
});
- let mut prev = function_block.ops.len() - 1;
- loop {
- match function_block.ops[prev] {
+ for op in function_block.ops.iter().rev() {
+ match op {
Op::Pop | Op::PopUpvalue => {}
Op::Return => { break; } ,
_ => {
@@ -570,7 +569,11 @@ impl Compiler {
break;
}
}
- prev -= 1;
+ }
+
+ if function_block.ops.is_empty() {
+ function_block.add(Op::Constant(Value::Nil), self.line());
+ function_block.add(Op::Return, self.line());
}
function_block.ty = Type::Function(args, Box::new(return_type));