blueloveTH 1 anno fa
parent
commit
00bdfe66cf
3 ha cambiato i file con 7 aggiunte e 6 eliminazioni
  1. 1 1
      src/compiler/compiler.c
  2. 1 0
      src/interpreter/ceval.c
  3. 5 5
      src/interpreter/frame.c

+ 1 - 1
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) {

+ 1 - 0
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();
             }

+ 5 - 5
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 <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;
 }