Bladeren bron

add some more registers

blueloveTH 1 maand geleden
bovenliggende
commit
45f18f8431

+ 2 - 2
include/pocketpy/interpreter/vm.h

@@ -58,8 +58,8 @@ typedef struct VM {
     int recursion_depth;
     int max_recursion_depth;
 
-    py_TValue reg[8];  // users' registers
-    void* ctx;         // user-defined context
+    py_TValue reg[14];  // users' registers
+    void* ctx;          // user-defined context
 
     CachedNames cached_names;
 

+ 7 - 0
include/pocketpy/pocketpy.h

@@ -441,6 +441,13 @@ PK_API py_GlobalRef py_retval();
 #define py_r6() py_getreg(6)
 #define py_r7() py_getreg(7)
 
+#define py_tmpr0() py_getreg(8)
+#define py_tmpr1() py_getreg(9)
+#define py_tmpr2() py_getreg(10)
+#define py_tmpr3() py_getreg(11)
+#define py_sysr0() py_getreg(12)    // for debugger
+#define py_sysr1() py_getreg(13)    // for pybind11
+
 /// Get an item from the object's `__dict__`.
 /// Return `NULL` if not found.
 PK_API py_ItemRef py_getdict(py_Ref self, py_Name name);

+ 1 - 2
include/pybind11/internal/kernel.h

@@ -44,8 +44,7 @@ struct object_pool {
     };
 
     static void initialize(int size) noexcept {
-        // use 8th register.
-        pool = py_getreg(7);
+        pool = py_sysr1();
         py_newtuple(pool, size);
         indices_ = new std::vector<int>(size, 0);
     }

+ 1 - 1
src/debugger/core.c

@@ -46,7 +46,7 @@ static struct c11_debugger {
     c11_vector py_frames;
     c11_smallmap_d2index scopes_query_cache;
 
-#define python_vars py_r7()
+#define python_vars py_sysr0()
 
 } debugger;
 

+ 2 - 0
src/interpreter/vm.c

@@ -99,6 +99,8 @@ void VM__ctor(VM* self) {
     self->recursion_depth = 0;
     self->max_recursion_depth = 1000;
 
+    memset(self->reg, 0, sizeof(self->reg));
+
     self->ctx = NULL;
     self->curr_class = NULL;
     self->curr_decl_based_function = NULL;

+ 2 - 4
src/interpreter/vmx.c

@@ -114,10 +114,8 @@ py_Ref py_name2ref(py_Name name) {
     py_Ref res = CachedNames__try_get(d, name);
     if(res != NULL) return res;
     // not found, create a new one
-    py_StackRef tmp = py_pushtmp();
-    py_newstrv(tmp, py_name2sv(name));
-    CachedNames__set(d, name, tmp);
-    py_pop();
+    py_newstrv(py_tmpr0(), py_name2sv(name));
+    CachedNames__set(d, name, py_tmpr0());
     return CachedNames__try_get(d, name);
 }
 

+ 2 - 2
src/public/DictSlots.c

@@ -1,8 +1,8 @@
 #include "pocketpy/interpreter/vm.h"
 
-py_Ref py_getreg(int i) { return pk_current_vm->reg + i; }
+PK_INLINE py_Ref py_getreg(int i) { return pk_current_vm->reg + i; }
 
-void py_setreg(int i, py_Ref val) { pk_current_vm->reg[i] = *val; }
+PK_INLINE void py_setreg(int i, py_Ref val) { pk_current_vm->reg[i] = *val; }
 
 PK_INLINE py_Ref py_retval() { return &pk_current_vm->last_retval; }