From 914bc87fd0525ce042d279bff6a4c97477bfeb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 20 Jan 2021 22:56:30 +0100 Subject: allow empty functions --- src/compiler.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') 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)); -- cgit v1.2.1