diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index ad6e352f..39c6e761 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -1108,7 +1108,7 @@ static void Ctx__dtor(Ctx* self) { static bool is_small_int(int64_t value) { return value >= INT16_MIN && value <= INT16_MAX; } static bool is_context_block(CodeBlock* block) { - return block->type >= CodeBlockType_WITH && block->type <= CodeBlockType_FINALLY; + return block->type >= CodeBlockType_FOR_LOOP && block->type <= CodeBlockType_FINALLY; } static int Ctx__get_loop(Ctx* self, bool* has_context) { diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index 9ef738c3..5bfeaced 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -1010,6 +1010,7 @@ FrameResult VM__run_top_frame(VM* self) { DISPATCH(); } case OP_END_EXC_HANDLING: { + assert(self->curr_exception.type); py_clearexc(NULL); DISPATCH(); } diff --git a/src/interpreter/frame.c b/src/interpreter/frame.c index 0ff1366e..f339f528 100644 --- a/src/interpreter/frame.c +++ b/src/interpreter/frame.c @@ -1,7 +1,7 @@ #include "pocketpy/interpreter/frame.h" #include "pocketpy/interpreter/vm.h" +#include "pocketpy/objects/base.h" #include "pocketpy/objects/codeobject.h" -#include "pocketpy/objects/object.h" #include "pocketpy/pocketpy.h" #include @@ -99,10 +99,10 @@ void Frame__prepare_jump_break(Frame* self, ValueStack* _s, int target) { int Frame__exit_block(Frame* self, ValueStack* _s, int iblock) { CodeBlock* block = c11__at(CodeBlock, &self->co->blocks, iblock); - if(block->type == CodeBlockType_FOR_LOOP) { - _s->sp--; // pop iterator - } else if(block->type == CodeBlockType_WITH) { - _s->sp--; // pop context variable + if(block->type == CodeBlockType_FOR_LOOP || block->type == CodeBlockType_WITH) { + _s->sp--; // pop iterator or context variable + } else if(block->type == CodeBlockType_EXCEPT || block->type == CodeBlockType_FINALLY) { + py_clearexc(NULL); } return block->parent; }