add some more registers

This commit is contained in:
blueloveTH 2026-01-06 14:09:11 +08:00
parent 0bdbf17d46
commit 45f18f8431
7 changed files with 17 additions and 11 deletions

View File

@ -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;

View File

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

View File

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

View File

@ -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;

View File

@ -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;

View File

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

View File

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