Fixed an extra return opcode in empty functions

This commit is contained in:
2026-05-27 09:52:21 +10:00
parent 92e4a41662
commit f2b714baaa
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -1464,7 +1464,7 @@ static void writeBytecodeBody(Toy_Bytecode* mb, Toy_Ast* ast) {
writeBytecodeFromAst(&mb, ast); writeBytecodeFromAst(&mb, ast);
//append an extra return if needed //append an extra return if needed
if (mb->codeCount <= 4 || mb->code[mb->codeCount - 4] != TOY_OPCODE_RETURN) { //if empty or no return statement if (mb->codeCount < 4 || mb->code[mb->codeCount - 4] != TOY_OPCODE_RETURN) { //if empty or no return statement
EMIT_BYTE(&mb, code, TOY_OPCODE_RETURN); //end terminator EMIT_BYTE(&mb, code, TOY_OPCODE_RETURN); //end terminator
EMIT_BYTE(&mb, code, 0); //4-byte alignment EMIT_BYTE(&mb, code, 0); //4-byte alignment
EMIT_BYTE(&mb, code, 0); EMIT_BYTE(&mb, code, 0);
+6 -2
View File
@@ -1,8 +1,12 @@
fn empty() { //BUG: there's an extra return in the bytecode fn empty() {
//
}
fn almostEmpty() {
return; return;
} }
fn full() { fn notEmpty() {
return 42; return 42;
} }