blueloveTH 2 lat temu
rodzic
commit
37453a8502
3 zmienionych plików z 12 dodań i 11 usunięć
  1. 5 6
      include/pocketpy/frame.h
  2. 1 1
      src/ceval.cpp
  3. 6 4
      src/compiler.cpp

+ 5 - 6
include/pocketpy/frame.h

@@ -77,8 +77,8 @@ struct ValueStackImpl {
 using ValueStack = ValueStackImpl<PK_VM_STACK_SIZE>;
 
 struct Frame {
-    int _ip = -1;
-    int _next_ip = 0;
+    int _ip;
+    int _next_ip;
     ValueStack* _s;
     // This is for unwinding only, use `actual_sp_base()` for value stack access
     PyObject** _sp_base;
@@ -89,17 +89,16 @@ struct Frame {
     FastLocals _locals;
 
     NameDict& f_globals() noexcept { return _module->attr(); }
-    
     PyObject* f_closure_try_get(StrName name);
 
     Frame(ValueStack* _s, PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable)
-            : _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, p0) { }
+            : _ip(-1), _next_ip(0), _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, p0) { }
 
     Frame(ValueStack* _s, PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable, FastLocals _locals)
-            : _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { }
+            : _ip(-1), _next_ip(0), _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { }
 
     Frame(ValueStack* _s, PyObject** p0, const CodeObject_& co, PyObject* _module)
-            : _s(_s), _sp_base(p0), co(co.get()), _module(_module), _callable(nullptr), _locals(co.get(), p0) {}
+            : _ip(-1), _next_ip(0), _s(_s), _sp_base(p0), co(co.get()), _module(_module), _callable(nullptr), _locals(co.get(), p0) {}
 
     Bytecode next_bytecode() {
         _ip = _next_ip++;

+ 1 - 1
src/ceval.cpp

@@ -512,7 +512,7 @@ __NEXT_STEP:;
         frame->jump_abs(byte.arg);
         DISPATCH();
     TARGET(JUMP_ABSOLUTE_TOP)
-        frame->jump_abs(_CAST(uint16_t, POPX()));
+        frame->jump_abs(_CAST(int, POPX()));
         DISPATCH();
     TARGET(POP_JUMP_IF_FALSE){
         if(!py_bool(TOP())) frame->jump_abs(byte.arg);

+ 6 - 4
src/compiler.cpp

@@ -43,10 +43,10 @@ namespace pkpy{
         if(ctx()->co->varnames.size() > PK_MAX_CO_VARNAMES){
             SyntaxError("maximum number of local variables exceeded");
         }
-        if(ctx()->co->consts.size() > 65535){
+        if(ctx()->co->consts.size() > 65530){
             SyntaxError("maximum number of constants exceeded");
         }
-        if(codes.size() > 65535 && ctx()->co->src->mode != JSON_MODE){
+        if(codes.size() > 65530 && ctx()->co->src->mode != JSON_MODE){
             // json mode does not contain jump instructions, so it is safe to ignore this check
             SyntaxError("maximum number of opcodes exceeded");
         }
@@ -718,7 +718,8 @@ __EAT_DOTS_END:
         }
         // no match, re-raise
         if(finally_entry != -1){
-            ctx()->emit_(OP_LOAD_INTEGER, (uint16_t)ctx()->co->codes.size()+2, BC_KEEPLINE);
+            i64 target = ctx()->co->codes.size()+2;
+            ctx()->emit_(OP_LOAD_CONST, ctx()->add_const(VAR(target)), BC_KEEPLINE);
             ctx()->emit_(OP_JUMP_ABSOLUTE, finally_entry, BC_KEEPLINE);
         }
         ctx()->emit_(OP_RE_RAISE, BC_NOARG, BC_KEEPLINE);
@@ -726,7 +727,8 @@ __EAT_DOTS_END:
         // no exception or no match, jump to the end
         for (int patch : patches) ctx()->patch_jump(patch);
         if(finally_entry != -1){
-            ctx()->emit_(OP_LOAD_INTEGER, (uint16_t)ctx()->co->codes.size()+2, BC_KEEPLINE);
+            i64 target = ctx()->co->codes.size()+2;
+            ctx()->emit_(OP_LOAD_CONST, ctx()->add_const(VAR(target)), BC_KEEPLINE);
             ctx()->emit_(OP_JUMP_ABSOLUTE, finally_entry, BC_KEEPLINE);
         }
     }