mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-10 13:40:16 +00:00
Merge branch 'blueloveTH:main' into fileio-seek
This commit is contained in:
commit
dffe4b4c60
@ -9,7 +9,7 @@ namespace pkpy {
|
|||||||
#define PY_CLASS(T, mod, name) \
|
#define PY_CLASS(T, mod, name) \
|
||||||
static Type _type(VM* vm) { \
|
static Type _type(VM* vm) { \
|
||||||
PK_LOCAL_STATIC const std::pair<StrName, StrName> _path(#mod, #name); \
|
PK_LOCAL_STATIC const std::pair<StrName, StrName> _path(#mod, #name); \
|
||||||
return PK_OBJ_GET(Type, vm->_modules[_path.first]->attr()[_path.second]); \
|
return PK_OBJ_GET(Type, vm->_modules[_path.first]->attr(_path.second)); \
|
||||||
} \
|
} \
|
||||||
static void _check_type(VM* vm, PyObject* val){ \
|
static void _check_type(VM* vm, PyObject* val){ \
|
||||||
if(!vm->isinstance(val, T::_type(vm))){ \
|
if(!vm->isinstance(val, T::_type(vm))){ \
|
||||||
|
|||||||
@ -174,8 +174,7 @@ struct Discarded { };
|
|||||||
|
|
||||||
struct Type {
|
struct Type {
|
||||||
int index;
|
int index;
|
||||||
Type(): index(-1) {}
|
constexpr Type(int index): index(index) {}
|
||||||
Type(int index): index(index) {}
|
|
||||||
bool operator==(Type other) const { return this->index == other.index; }
|
bool operator==(Type other) const { return this->index == other.index; }
|
||||||
bool operator!=(Type other) const { return this->index != other.index; }
|
bool operator!=(Type other) const { return this->index != other.index; }
|
||||||
operator int() const { return this->index; }
|
operator int() const { return this->index; }
|
||||||
|
|||||||
@ -150,12 +150,14 @@ public:
|
|||||||
unsigned char* (*_import_handler)(const char*, int, int*);
|
unsigned char* (*_import_handler)(const char*, int, int*);
|
||||||
|
|
||||||
// for quick access
|
// for quick access
|
||||||
Type tp_object, tp_type, tp_int, tp_float, tp_bool, tp_str;
|
static constexpr Type tp_object=0, tp_type=1;
|
||||||
Type tp_list, tp_tuple;
|
static constexpr Type tp_int=kTpIntIndex, tp_float=kTpFloatIndex, tp_bool=4, tp_str=5;
|
||||||
Type tp_function, tp_native_func, tp_bound_method;
|
static constexpr Type tp_list=6, tp_tuple=7;
|
||||||
Type tp_slice, tp_range, tp_module;
|
static constexpr Type tp_slice=8, tp_range=9, tp_module=10;
|
||||||
Type tp_super, tp_exception, tp_bytes, tp_mappingproxy;
|
static constexpr Type tp_function=11, tp_native_func=12, tp_bound_method=13;
|
||||||
Type tp_dict, tp_property, tp_star_wrapper;
|
|
||||||
|
static constexpr Type tp_super=14, tp_exception=15, tp_bytes=16, tp_mappingproxy=17;
|
||||||
|
static constexpr Type tp_dict=18, tp_property=19, tp_star_wrapper=20;
|
||||||
|
|
||||||
PyObject* cached_object__new__;
|
PyObject* cached_object__new__;
|
||||||
|
|
||||||
|
|||||||
@ -161,7 +161,7 @@ void add_module_c(VM* vm){
|
|||||||
});
|
});
|
||||||
|
|
||||||
PyObject* type;
|
PyObject* type;
|
||||||
Type type_t;
|
Type type_t = -1;
|
||||||
|
|
||||||
#define BIND_PRIMITIVE(T, CNAME) \
|
#define BIND_PRIMITIVE(T, CNAME) \
|
||||||
vm->bind_func<1>(mod, CNAME "_", [](VM* vm, ArgsView args){ \
|
vm->bind_func<1>(mod, CNAME "_", [](VM* vm, ArgsView args){ \
|
||||||
|
|||||||
42
src/vm.cpp
42
src/vm.cpp
@ -708,29 +708,29 @@ void VM::_log_s_data(const char* title) {
|
|||||||
void VM::init_builtin_types(){
|
void VM::init_builtin_types(){
|
||||||
_all_types.push_back({heap._new<Type>(Type(1), Type(0)), -1, nullptr, "object", true});
|
_all_types.push_back({heap._new<Type>(Type(1), Type(0)), -1, nullptr, "object", true});
|
||||||
_all_types.push_back({heap._new<Type>(Type(1), Type(1)), 0, nullptr, "type", false});
|
_all_types.push_back({heap._new<Type>(Type(1), Type(1)), 0, nullptr, "type", false});
|
||||||
tp_object = 0; tp_type = 1;
|
|
||||||
|
|
||||||
tp_int = _new_type_object("int");
|
PK_ASSERT(tp_int == _new_type_object("int"));
|
||||||
tp_float = _new_type_object("float");
|
PK_ASSERT(tp_float == _new_type_object("float"));
|
||||||
if(tp_int.index != kTpIntIndex || tp_float.index != kTpFloatIndex) FATAL_ERROR();
|
|
||||||
|
|
||||||
tp_bool = _new_type_object("bool");
|
PK_ASSERT(tp_bool == _new_type_object("bool"));
|
||||||
tp_str = _new_type_object("str");
|
PK_ASSERT(tp_str == _new_type_object("str"));
|
||||||
tp_list = _new_type_object("list");
|
PK_ASSERT(tp_list == _new_type_object("list"));
|
||||||
tp_tuple = _new_type_object("tuple");
|
PK_ASSERT(tp_tuple == _new_type_object("tuple"));
|
||||||
tp_slice = _new_type_object("slice");
|
|
||||||
tp_range = _new_type_object("range");
|
PK_ASSERT(tp_slice == _new_type_object("slice"));
|
||||||
tp_module = _new_type_object("module");
|
PK_ASSERT(tp_range == _new_type_object("range"));
|
||||||
tp_function = _new_type_object("function");
|
PK_ASSERT(tp_module == _new_type_object("module"));
|
||||||
tp_native_func = _new_type_object("native_func");
|
PK_ASSERT(tp_function == _new_type_object("function"));
|
||||||
tp_bound_method = _new_type_object("bound_method");
|
PK_ASSERT(tp_native_func == _new_type_object("native_func"));
|
||||||
tp_super = _new_type_object("super");
|
PK_ASSERT(tp_bound_method == _new_type_object("bound_method"));
|
||||||
tp_exception = _new_type_object("_Exception");
|
|
||||||
tp_bytes = _new_type_object("bytes");
|
PK_ASSERT(tp_super == _new_type_object("super"));
|
||||||
tp_mappingproxy = _new_type_object("mappingproxy");
|
PK_ASSERT(tp_exception == _new_type_object("_Exception"));
|
||||||
tp_dict = _new_type_object("dict");
|
PK_ASSERT(tp_bytes == _new_type_object("bytes"));
|
||||||
tp_property = _new_type_object("property");
|
PK_ASSERT(tp_mappingproxy == _new_type_object("mappingproxy"));
|
||||||
tp_star_wrapper = _new_type_object("_star_wrapper");
|
PK_ASSERT(tp_dict == _new_type_object("dict"));
|
||||||
|
PK_ASSERT(tp_property == _new_type_object("property"));
|
||||||
|
PK_ASSERT(tp_star_wrapper == _new_type_object("_star_wrapper"));
|
||||||
|
|
||||||
this->None = heap._new<Dummy>(_new_type_object("NoneType"));
|
this->None = heap._new<Dummy>(_new_type_object("NoneType"));
|
||||||
this->NotImplemented = heap._new<Dummy>(_new_type_object("NotImplementedType"));
|
this->NotImplemented = heap._new<Dummy>(_new_type_object("NotImplementedType"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user