mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
rename py_Type
This commit is contained in:
parent
5bdbec273e
commit
6f99ebed88
@ -28,8 +28,8 @@ void pk_ManagedHeap__collect_if_needed(pk_ManagedHeap* self);
|
|||||||
int pk_ManagedHeap__collect(pk_ManagedHeap* self);
|
int pk_ManagedHeap__collect(pk_ManagedHeap* self);
|
||||||
int pk_ManagedHeap__sweep(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__new(pk_ManagedHeap* self, py_Type type, int slots, int size);
|
||||||
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);
|
||||||
|
|
||||||
// external implementation
|
// external implementation
|
||||||
void pk_ManagedHeap__mark(pk_ManagedHeap* self);
|
void pk_ManagedHeap__mark(pk_ManagedHeap* self);
|
||||||
|
@ -10,7 +10,7 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct pk_TypeInfo{
|
typedef struct pk_TypeInfo{
|
||||||
py_Name name;
|
py_Name name;
|
||||||
Type base;
|
py_Type base;
|
||||||
|
|
||||||
PyVar self; // the type object itself
|
PyVar self; // the type object itself
|
||||||
PyVar module; // the module where the type is defined
|
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
|
py_CFunction on_end_subclass; // for enum module
|
||||||
} pk_TypeInfo;
|
} 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);
|
void pk_TypeInfo__dtor(pk_TypeInfo* self);
|
||||||
|
|
||||||
typedef struct pk_VM {
|
typedef struct pk_VM {
|
||||||
@ -91,7 +91,7 @@ typedef enum pk_FrameResult{
|
|||||||
|
|
||||||
pk_FrameResult pk_VM__run_top_frame(pk_VM* self);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef int16_t Type;
|
typedef int16_t py_Type;
|
||||||
|
|
||||||
typedef struct PyVar{
|
typedef struct PyVar{
|
||||||
Type type;
|
py_Type type;
|
||||||
bool is_ptr;
|
bool is_ptr;
|
||||||
int extra;
|
int extra;
|
||||||
union {
|
union {
|
||||||
@ -39,23 +39,23 @@ typedef struct PyVar{
|
|||||||
static_assert(sizeof(PyVar) == 16, "sizeof(PyVar) != 16");
|
static_assert(sizeof(PyVar) == 16, "sizeof(PyVar) != 16");
|
||||||
|
|
||||||
/* predefined vars */
|
/* predefined vars */
|
||||||
static const Type tp_object = {1}, tp_type = {2};
|
static const py_Type tp_object = {1}, tp_type = {2};
|
||||||
static const Type tp_int = {3}, tp_float = {4}, tp_bool = {5}, tp_str = {6};
|
static const py_Type tp_int = {3}, tp_float = {4}, tp_bool = {5}, tp_str = {6};
|
||||||
static const Type tp_list = {7}, tp_tuple = {8};
|
static const py_Type tp_list = {7}, tp_tuple = {8};
|
||||||
static const Type tp_slice = {9}, tp_range = {10}, tp_module = {11};
|
static const py_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 py_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 py_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 py_Type tp_dict = {19}, tp_property = {20}, tp_star_wrapper = {21};
|
||||||
static const Type tp_staticmethod = {22}, tp_classmethod = {23};
|
static const py_Type tp_staticmethod = {22}, tp_classmethod = {23};
|
||||||
static const Type tp_none_type = {24}, tp_not_implemented_type = {25};
|
static const py_Type tp_none_type = {24}, tp_not_implemented_type = {25};
|
||||||
static const Type tp_ellipsis = {26};
|
static const py_Type tp_ellipsis = {26};
|
||||||
static const Type tp_op_call = {27}, tp_op_yield = {28};
|
static const py_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_syntax_error = {29}, tp_stop_iteration = {30};
|
||||||
|
|
||||||
PK_INLINE bool PyVar__is_null(const PyVar* self) { return self->type == 0; }
|
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 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->type = type;
|
||||||
self->is_ptr = true;
|
self->is_ptr = true;
|
||||||
self->_obj = obj;
|
self->_obj = obj;
|
||||||
|
@ -8,7 +8,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct PyObject{
|
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_is_large;
|
||||||
bool gc_marked;
|
bool gc_marked;
|
||||||
int slots; // number of slots in the object
|
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))
|
#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);
|
void PyObject__delete(PyObject* self);
|
||||||
|
|
||||||
PK_INLINE PyVar PyVar__fromobj(PyObject* obj){
|
PK_INLINE PyVar PyVar__fromobj(PyObject* obj){
|
||||||
|
@ -8,14 +8,14 @@ typedef struct PyObject PyObject;
|
|||||||
typedef struct PyVar PyVar;
|
typedef struct PyVar PyVar;
|
||||||
typedef struct pk_VM pk_VM;
|
typedef struct pk_VM pk_VM;
|
||||||
typedef uint16_t py_Name;
|
typedef uint16_t py_Name;
|
||||||
typedef int16_t Type;
|
typedef int16_t py_Type;
|
||||||
typedef PyVar* py_Ref;
|
typedef PyVar* py_Ref;
|
||||||
typedef int (*py_CFunction)(const py_Ref, int);
|
typedef int (*py_CFunction)(const py_Ref, int);
|
||||||
|
|
||||||
typedef struct py_Str py_Str;
|
typedef struct py_Str py_Str;
|
||||||
|
|
||||||
typedef struct py_Error{
|
typedef struct py_Error{
|
||||||
Type type;
|
py_Type type;
|
||||||
} py_Error;
|
} py_Error;
|
||||||
|
|
||||||
typedef enum BindType {
|
typedef enum BindType {
|
||||||
@ -139,9 +139,9 @@ int py_tofloat(py_Ref, double* out);
|
|||||||
int py_tostr(py_Ref, py_Str** out);
|
int py_tostr(py_Ref, py_Str** out);
|
||||||
int py_tobool(py_Ref, bool* out);
|
int py_tobool(py_Ref, bool* out);
|
||||||
|
|
||||||
bool py_istype(const py_Ref, Type);
|
bool py_istype(const py_Ref, py_Type);
|
||||||
bool py_isinstance(const py_Ref obj, Type type);
|
bool py_isinstance(const py_Ref obj, py_Type type);
|
||||||
bool py_issubclass(Type derived, Type base);
|
bool py_issubclass(py_Type derived, py_Type base);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -88,20 +88,20 @@ int pk_ManagedHeap__sweep(pk_ManagedHeap *self){
|
|||||||
return freed;
|
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);
|
PyObject* obj = PyObject__new(type, slots, size);
|
||||||
c11_vector__push(PyObject*, &self->no_gc, obj);
|
c11_vector__push(PyObject*, &self->no_gc, obj);
|
||||||
return 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);
|
PyObject* obj = PyObject__new(type, slots, size);
|
||||||
c11_vector__push(PyObject*, &self->gen, obj);
|
c11_vector__push(PyObject*, &self->gen, obj);
|
||||||
self->gc_counter++;
|
self->gc_counter++;
|
||||||
return obj;
|
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);
|
assert(slots >= 0 || slots == -1);
|
||||||
PyObject* self;
|
PyObject* self;
|
||||||
size += PK_OBJ_HEADER_SIZE(slots);
|
size += PK_OBJ_HEADER_SIZE(slots);
|
||||||
|
@ -17,7 +17,7 @@ static void pk_default_stderr(const char* s){
|
|||||||
fflush(stderr);
|
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));
|
memset(self, 0, sizeof(pk_TypeInfo));
|
||||||
|
|
||||||
self->name = name;
|
self->name = name;
|
||||||
@ -172,7 +172,7 @@ void pk_VM__ctor(pk_VM* self){
|
|||||||
self->builtins = *py_newmodule("builtins", NULL);
|
self->builtins = *py_newmodule("builtins", NULL);
|
||||||
|
|
||||||
/* Setup Public Builtin Types */
|
/* Setup Public Builtin Types */
|
||||||
Type public_types[] = {
|
py_Type public_types[] = {
|
||||||
tp_object, tp_type,
|
tp_object, tp_type,
|
||||||
tp_int, tp_float, tp_bool, tp_str,
|
tp_int, tp_float, tp_bool, tp_str,
|
||||||
tp_list, tp_tuple,
|
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++){
|
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);
|
pk_TypeInfo* ti = c11__at(pk_TypeInfo, &self->types, t);
|
||||||
py_setdict(&self->builtins, ti->name, &ti->self);
|
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;
|
return RES_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
||||||
Type type = self->types.count;
|
py_Type type = self->types.count;
|
||||||
pk_TypeInfo* ti = c11_vector__emplace(&self->types);
|
pk_TypeInfo* ti = c11_vector__emplace(&self->types);
|
||||||
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, 0, sizeof(Type));
|
PyObject* typeobj = pk_ManagedHeap__gcnew(&self->heap, tp_type, 0, sizeof(py_Type));
|
||||||
Type* value = PyObject__value(typeobj);
|
py_Type* value = PyObject__value(typeobj);
|
||||||
*value = type;
|
*value = type;
|
||||||
pk_TypeInfo__ctor(ti, py_name(name), base, typeobj, module, subclass_enabled);
|
pk_TypeInfo__ctor(ti, py_name(name), base, typeobj, module, subclass_enabled);
|
||||||
return type;
|
return type;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user