This commit is contained in:
blueloveTH 2024-10-26 16:14:27 +08:00
parent 791d9f39d3
commit 00bdfe66cf
3 changed files with 7 additions and 6 deletions

View File

@ -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) {

View File

@ -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();
}

View File

@ -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 <stdbool.h>
@ -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;
}