rename py_Type

This commit is contained in:
blueloveTH 2024-06-26 01:03:53 +08:00
parent 5bdbec273e
commit 6f99ebed88
7 changed files with 37 additions and 37 deletions

View File

@ -28,8 +28,8 @@ void pk_ManagedHeap__collect_if_needed(pk_ManagedHeap* self);
int pk_ManagedHeap__collect(pk_ManagedHeap* self);
int pk_ManagedHeap__sweep(pk_ManagedHeap* self);
PyObject* pk_ManagedHeap__new(pk_ManagedHeap* self, Type type, int slots, int size);
PyObject* pk_ManagedHeap__gcnew(pk_ManagedHeap* self, Type type, int slots, int size);
PyObject* pk_ManagedHeap__new(pk_ManagedHeap* self, py_Type type, int slots, int size);
PyObject* pk_ManagedHeap__gcnew(pk_ManagedHeap* self, py_Type type, int slots, int size);
// external implementation
void pk_ManagedHeap__mark(pk_ManagedHeap* self);

View File

@ -10,7 +10,7 @@ extern "C" {
typedef struct pk_TypeInfo{
py_Name name;
Type base;
py_Type base;
PyVar self; // the type object itself
PyVar module; // the module where the type is defined
@ -38,7 +38,7 @@ typedef struct pk_TypeInfo{
py_CFunction on_end_subclass; // for enum module
} pk_TypeInfo;
void pk_TypeInfo__ctor(pk_TypeInfo* self, py_Name name, Type base, PyObject* obj, const PyVar* module, bool subclass_enabled);
void pk_TypeInfo__ctor(pk_TypeInfo* self, py_Name name, py_Type base, PyObject* obj, const PyVar* module, bool subclass_enabled);
void pk_TypeInfo__dtor(pk_TypeInfo* self);
typedef struct pk_VM {
@ -91,7 +91,7 @@ typedef enum pk_FrameResult{
pk_FrameResult pk_VM__run_top_frame(pk_VM* self);
Type pk_VM__new_type(pk_VM* self, const char* name, Type base, const PyVar* module, bool subclass_enabled);
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const PyVar* module, bool subclass_enabled);
#ifdef __cplusplus
}

View File

@ -13,10 +13,10 @@
extern "C" {
#endif
typedef int16_t Type;
typedef int16_t py_Type;
typedef struct PyVar{
Type type;
py_Type type;
bool is_ptr;
int extra;
union {
@ -39,23 +39,23 @@ typedef struct PyVar{
static_assert(sizeof(PyVar) == 16, "sizeof(PyVar) != 16");
/* predefined vars */
static const Type tp_object = {1}, tp_type = {2};
static const Type tp_int = {3}, tp_float = {4}, tp_bool = {5}, tp_str = {6};
static const Type tp_list = {7}, tp_tuple = {8};
static const Type tp_slice = {9}, tp_range = {10}, tp_module = {11};
static const Type tp_function = {12}, tp_nativefunc = {13}, tp_bound_method = {14};
static const Type tp_super = {15}, tp_exception = {16}, tp_bytes = {17}, tp_mappingproxy = {18};
static const Type tp_dict = {19}, tp_property = {20}, tp_star_wrapper = {21};
static const Type tp_staticmethod = {22}, tp_classmethod = {23};
static const Type tp_none_type = {24}, tp_not_implemented_type = {25};
static const Type tp_ellipsis = {26};
static const Type tp_op_call = {27}, tp_op_yield = {28};
static const Type tp_syntax_error = {29}, tp_stop_iteration = {30};
static const py_Type tp_object = {1}, tp_type = {2};
static const py_Type tp_int = {3}, tp_float = {4}, tp_bool = {5}, tp_str = {6};
static const py_Type tp_list = {7}, tp_tuple = {8};
static const py_Type tp_slice = {9}, tp_range = {10}, tp_module = {11};
static const py_Type tp_function = {12}, tp_nativefunc = {13}, tp_bound_method = {14};
static const py_Type tp_super = {15}, tp_exception = {16}, tp_bytes = {17}, tp_mappingproxy = {18};
static const py_Type tp_dict = {19}, tp_property = {20}, tp_star_wrapper = {21};
static const py_Type tp_staticmethod = {22}, tp_classmethod = {23};
static const py_Type tp_none_type = {24}, tp_not_implemented_type = {25};
static const py_Type tp_ellipsis = {26};
static const py_Type tp_op_call = {27}, tp_op_yield = {28};
static const py_Type tp_syntax_error = {29}, tp_stop_iteration = {30};
PK_INLINE bool PyVar__is_null(const PyVar* self) { return self->type == 0; }
PK_INLINE int64_t PyVar__hash(const PyVar* self) { return self->extra + self->_i64; }
PK_INLINE void PyVar__ctor(PyVar* self, Type type, PyObject* obj){
PK_INLINE void PyVar__ctor(PyVar* self, py_Type type, PyObject* obj){
self->type = type;
self->is_ptr = true;
self->_obj = obj;

View File

@ -8,7 +8,7 @@ extern "C" {
#endif
typedef struct PyObject{
Type type; // we have a duplicated type here for convenience
py_Type type; // we have a duplicated type here for convenience
bool gc_is_large;
bool gc_marked;
int slots; // number of slots in the object
@ -28,7 +28,7 @@ void* PyObject__value(PyObject* self);
#define PK_OBJ_HEADER_SIZE(slots) ((slots)>=0 ? 8+sizeof(PyVar)*(slots) : 8+sizeof(pk_NameDict))
PyObject* PyObject__new(Type type, int slots, int size);
PyObject* PyObject__new(py_Type type, int slots, int size);
void PyObject__delete(PyObject* self);
PK_INLINE PyVar PyVar__fromobj(PyObject* obj){

View File

@ -8,14 +8,14 @@ typedef struct PyObject PyObject;
typedef struct PyVar PyVar;
typedef struct pk_VM pk_VM;
typedef uint16_t py_Name;
typedef int16_t Type;
typedef int16_t py_Type;
typedef PyVar* py_Ref;
typedef int (*py_CFunction)(const py_Ref, int);
typedef struct py_Str py_Str;
typedef struct py_Error{
Type type;
py_Type type;
} py_Error;
typedef enum BindType {
@ -139,9 +139,9 @@ int py_tofloat(py_Ref, double* out);
int py_tostr(py_Ref, py_Str** out);
int py_tobool(py_Ref, bool* out);
bool py_istype(const py_Ref, Type);
bool py_isinstance(const py_Ref obj, Type type);
bool py_issubclass(Type derived, Type base);
bool py_istype(const py_Ref, py_Type);
bool py_isinstance(const py_Ref obj, py_Type type);
bool py_issubclass(py_Type derived, py_Type base);
#ifdef __cplusplus
}

View File

@ -88,20 +88,20 @@ int pk_ManagedHeap__sweep(pk_ManagedHeap *self){
return freed;
}
PyObject* pk_ManagedHeap__new(pk_ManagedHeap *self, Type type, int slots, int size){
PyObject* pk_ManagedHeap__new(pk_ManagedHeap *self, py_Type type, int slots, int size){
PyObject* obj = PyObject__new(type, slots, size);
c11_vector__push(PyObject*, &self->no_gc, obj);
return obj;
}
PyObject* pk_ManagedHeap__gcnew(pk_ManagedHeap *self, Type type, int slots, int size){
PyObject* pk_ManagedHeap__gcnew(pk_ManagedHeap *self, py_Type type, int slots, int size){
PyObject* obj = PyObject__new(type, slots, size);
c11_vector__push(PyObject*, &self->gen, obj);
self->gc_counter++;
return obj;
}
PyObject* PyObject__new(Type type, int slots, int size){
PyObject* PyObject__new(py_Type type, int slots, int size){
assert(slots >= 0 || slots == -1);
PyObject* self;
size += PK_OBJ_HEADER_SIZE(slots);

View File

@ -17,7 +17,7 @@ static void pk_default_stderr(const char* s){
fflush(stderr);
}
void pk_TypeInfo__ctor(pk_TypeInfo *self, py_Name name, Type base, PyObject* obj, const PyVar* module, bool subclass_enabled){
void pk_TypeInfo__ctor(pk_TypeInfo *self, py_Name name, py_Type base, PyObject* obj, const PyVar* module, bool subclass_enabled){
memset(self, 0, sizeof(pk_TypeInfo));
self->name = name;
@ -172,7 +172,7 @@ void pk_VM__ctor(pk_VM* self){
self->builtins = *py_newmodule("builtins", NULL);
/* Setup Public Builtin Types */
Type public_types[] = {
py_Type public_types[] = {
tp_object, tp_type,
tp_int, tp_float, tp_bool, tp_str,
tp_list, tp_tuple,
@ -182,7 +182,7 @@ void pk_VM__ctor(pk_VM* self){
};
for(int i=0; i<PK_ARRAY_COUNT(public_types); i++){
Type t = public_types[i];
py_Type t = public_types[i];
pk_TypeInfo* ti = c11__at(pk_TypeInfo, &self->types, t);
py_setdict(&self->builtins, ti->name, &ti->self);
}
@ -220,11 +220,11 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self){
return RES_RETURN;
}
Type pk_VM__new_type(pk_VM* self, const char* name, Type base, const PyVar* module, bool subclass_enabled){
Type type = self->types.count;
py_Type pk_VM__new_type(pk_VM* self, const char* name, py_Type base, const PyVar* module, bool subclass_enabled){
py_Type type = self->types.count;
pk_TypeInfo* ti = c11_vector__emplace(&self->types);
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, 0, sizeof(Type));
Type* value = PyObject__value(typeobj);
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, 0, sizeof(py_Type));
py_Type* value = PyObject__value(typeobj);
*value = type;
pk_TypeInfo__ctor(ti, py_name(name), base, typeobj, module, subclass_enabled);
return type;