Skip to content

Commit 51d2580

Browse files
committed
Simplify end implementation
1 parent d733ace commit 51d2580

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/fizzy/execute.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,8 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args,
549549
}
550550
case Instr::end:
551551
{
552-
// End execution if it's a final end instruction.
553-
if (pc == &code.instructions[code.instructions.size()])
554-
goto end;
555-
break;
552+
assert(pc == &code.instructions[code.instructions.size()]);
553+
goto end;
556554
}
557555
case Instr::br:
558556
case Instr::br_if:

lib/fizzy/parser_expr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,9 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, FuncIdx f
531531

532532
if (frame.instruction != Instr::loop) // If end of block/if/else instruction.
533533
{
534-
// Jump on the matching end instruction.
534+
// The position of the "end":
535+
// for the outermost implicit function block this is the function's end instruction,
536+
// otherwise this is the next instruction after the block's end.
535537
const auto target_pc = static_cast<uint32_t>(code.instructions.size());
536538

537539
if (frame.instruction == Instr::if_ || frame.instruction == Instr::else_)

0 commit comments

Comments
 (0)