فهرست منبع

some optimize

blueloveTH 8 ماه پیش
والد
کامیت
4bb0ae3035
5فایلهای تغییر یافته به همراه8 افزوده شده و 8 حذف شده
  1. 1 1
      include/pocketpy/interpreter/typeinfo.h
  2. 2 2
      src/interpreter/vm.c
  3. 2 2
      src/modules/pickle.c
  4. 1 1
      src/public/internal.c
  5. 2 2
      src/public/py_object.c

+ 1 - 1
include/pocketpy/interpreter/typeinfo.h

@@ -12,7 +12,7 @@ typedef struct py_TypeInfo {
     struct py_TypeInfo* base_ti;
 
     py_TValue self;
-    py_TValue module;  // the module where the type is defined
+    py_GlobalRef module;
 
     bool is_python;  // is it a python class? (not derived from c object)
     bool is_sealed;  // can it be subclassed?

+ 2 - 2
src/interpreter/vm.c

@@ -44,7 +44,7 @@ static void py_TypeInfo__ctor(py_TypeInfo* self,
                               py_Type index,
                               py_Type base,
                               py_TypeInfo* base_ti,
-                              py_TValue module) {
+                              py_GlobalRef module) {
     memset(self, 0, sizeof(py_TypeInfo));
 
     self->name = name;
@@ -403,7 +403,7 @@ py_Type pk_newtype(const char* name,
     if(base_ti && base_ti->is_sealed) {
         c11__abort("type '%s' is not an acceptable base type", py_name2str(base_ti->name));
     }
-    py_TypeInfo__ctor(ti, py_name(name), index, base, base_ti, module ? *module : *py_NIL());
+    py_TypeInfo__ctor(ti, py_name(name), index, base, base_ti, module ? module : py_NIL());
     if(!dtor && base) dtor = base_ti->dtor;
     ti->dtor = dtor;
     ti->is_python = is_python;

+ 2 - 2
src/modules/pickle.c

@@ -62,11 +62,11 @@ static void PickleObject__write_bytes(PickleObject* buf, const void* data, int s
 
 static void c11_sbuf__write_type_path(c11_sbuf* path_buf, py_Type type) {
     py_TypeInfo* ti = pk__type_info(type);
-    if(py_isnil(&ti->module)) {
+    if(py_isnil(ti->module)) {
         c11_sbuf__write_cstr(path_buf, py_name2str(ti->name));
         return;
     }
-    const char* mod_path = py_tostr(py_getdict(&ti->module, __path__));
+    const char* mod_path = py_tostr(py_getdict(ti->module, __path__));
     c11_sbuf__write_cstr(path_buf, mod_path);
     c11_sbuf__write_char(path_buf, '.');
     c11_sbuf__write_cstr(path_buf, py_name2str(ti->name));

+ 1 - 1
src/public/internal.c

@@ -265,7 +265,7 @@ py_Ref py_tpfindname(py_Type t, py_Name name) {
 py_Type py_tpbase(py_Type t) {
     assert(t);
     py_TypeInfo* ti = pk__type_info(t);
-    return py_totype(&ti->base_ti->self);
+    return ti->base;
 }
 
 PK_DEPRECATED py_Ref py_tpgetmagic(py_Type type, py_Name name) {

+ 2 - 2
src/public/py_object.c

@@ -101,10 +101,10 @@ static bool type__or__(int argc, py_Ref argv) {
 static bool type__module__(int argc, py_Ref argv) {
     PY_CHECK_ARGC(1);
     py_TypeInfo* ti = pk__type_info(py_totype(argv));
-    if(py_isnil(&ti->module)) {
+    if(py_isnil(ti->module)) {
         py_newnone(py_retval());
     } else {
-        py_Ref path = py_getdict(&ti->module, __path__);
+        py_Ref path = py_getdict(ti->module, __path__);
         py_assign(py_retval(), path);
     }
     return true;