Merge branch 'blueloveTH:main' into fileio-seek

This commit is contained in:
Paul m. p. Peny 2023-12-23 17:57:49 +01:00 committed by GitHub
commit dffe4b4c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 31 deletions

View File

@ -9,7 +9,7 @@ namespace pkpy {
#define PY_CLASS(T, mod, name) \
static Type _type(VM* vm) { \
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){ \
if(!vm->isinstance(val, T::_type(vm))){ \

View File

@ -174,8 +174,7 @@ struct Discarded { };
struct Type {
int index;
Type(): index(-1) {}
Type(int index): index(index) {}
constexpr 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; }
operator int() const { return this->index; }

View File

@ -150,12 +150,14 @@ public:
unsigned char* (*_import_handler)(const char*, int, int*);
// for quick access
Type tp_object, tp_type, tp_int, tp_float, tp_bool, tp_str;
Type tp_list, tp_tuple;
Type tp_function, tp_native_func, tp_bound_method;
Type tp_slice, tp_range, tp_module;
Type tp_super, tp_exception, tp_bytes, tp_mappingproxy;
Type tp_dict, tp_property, tp_star_wrapper;
static constexpr Type tp_object=0, tp_type=1;
static constexpr Type tp_int=kTpIntIndex, tp_float=kTpFloatIndex, tp_bool=4, tp_str=5;
static constexpr Type tp_list=6, tp_tuple=7;
static constexpr Type tp_slice=8, tp_range=9, tp_module=10;
static constexpr Type tp_function=11, tp_native_func=12, tp_bound_method=13;
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__;

View File

@ -161,7 +161,7 @@ void add_module_c(VM* vm){
});
PyObject* type;
Type type_t;
Type type_t = -1;
#define BIND_PRIMITIVE(T, CNAME) \
vm->bind_func<1>(mod, CNAME "_", [](VM* vm, ArgsView args){ \

View File

@ -708,29 +708,29 @@ void VM::_log_s_data(const char* title) {
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(1)), 0, nullptr, "type", false});
tp_object = 0; tp_type = 1;
tp_int = _new_type_object("int");
tp_float = _new_type_object("float");
if(tp_int.index != kTpIntIndex || tp_float.index != kTpFloatIndex) FATAL_ERROR();
PK_ASSERT(tp_int == _new_type_object("int"));
PK_ASSERT(tp_float == _new_type_object("float"));
tp_bool = _new_type_object("bool");
tp_str = _new_type_object("str");
tp_list = _new_type_object("list");
tp_tuple = _new_type_object("tuple");
tp_slice = _new_type_object("slice");
tp_range = _new_type_object("range");
tp_module = _new_type_object("module");
tp_function = _new_type_object("function");
tp_native_func = _new_type_object("native_func");
tp_bound_method = _new_type_object("bound_method");
tp_super = _new_type_object("super");
tp_exception = _new_type_object("_Exception");
tp_bytes = _new_type_object("bytes");
tp_mappingproxy = _new_type_object("mappingproxy");
tp_dict = _new_type_object("dict");
tp_property = _new_type_object("property");
tp_star_wrapper = _new_type_object("_star_wrapper");
PK_ASSERT(tp_bool == _new_type_object("bool"));
PK_ASSERT(tp_str == _new_type_object("str"));
PK_ASSERT(tp_list == _new_type_object("list"));
PK_ASSERT(tp_tuple == _new_type_object("tuple"));
PK_ASSERT(tp_slice == _new_type_object("slice"));
PK_ASSERT(tp_range == _new_type_object("range"));
PK_ASSERT(tp_module == _new_type_object("module"));
PK_ASSERT(tp_function == _new_type_object("function"));
PK_ASSERT(tp_native_func == _new_type_object("native_func"));
PK_ASSERT(tp_bound_method == _new_type_object("bound_method"));
PK_ASSERT(tp_super == _new_type_object("super"));
PK_ASSERT(tp_exception == _new_type_object("_Exception"));
PK_ASSERT(tp_bytes == _new_type_object("bytes"));
PK_ASSERT(tp_mappingproxy == _new_type_object("mappingproxy"));
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->NotImplemented = heap._new<Dummy>(_new_type_object("NotImplementedType"));