mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
deprecate *non_tagged*
This commit is contained in:
parent
b3c898672e
commit
f53a46941a
@ -100,7 +100,7 @@ void add_module_cjson(VM* vm){
|
|||||||
|
|
||||||
vm->bind_func<1>(mod, "loads", [](VM* vm, ArgsView args){
|
vm->bind_func<1>(mod, "loads", [](VM* vm, ArgsView args){
|
||||||
std::string_view sv;
|
std::string_view sv;
|
||||||
if(is_non_tagged_type(args[0], vm->tp_bytes)){
|
if(is_type(args[0], vm->tp_bytes)){
|
||||||
sv = PK_OBJ_GET(Bytes, args[0]).sv();
|
sv = PK_OBJ_GET(Bytes, args[0]).sv();
|
||||||
}else{
|
}else{
|
||||||
sv = CAST(Str&, args[0]).sv();
|
sv = CAST(Str&, args[0]).sv();
|
||||||
|
@ -274,13 +274,13 @@ void lua_push_from_python(VM* vm, PyObject* val){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_non_tagged_type(val, PyLuaTable::_type(vm))){
|
if(is_type(val, PyLuaTable::_type(vm))){
|
||||||
const PyLuaTable& table = _CAST(PyLuaTable&, val);
|
const PyLuaTable& table = _CAST(PyLuaTable&, val);
|
||||||
lua_rawgeti(_L, LUA_REGISTRYINDEX, table.r);
|
lua_rawgeti(_L, LUA_REGISTRYINDEX, table.r);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_non_tagged_type(val, PyLuaFunction::_type(vm))){
|
if(is_type(val, PyLuaFunction::_type(vm))){
|
||||||
const PyLuaFunction& func = _CAST(PyLuaFunction&, val);
|
const PyLuaFunction& func = _CAST(PyLuaFunction&, val);
|
||||||
lua_rawgeti(_L, LUA_REGISTRYINDEX, func.r);
|
lua_rawgeti(_L, LUA_REGISTRYINDEX, func.r);
|
||||||
return;
|
return;
|
||||||
|
@ -95,7 +95,6 @@ you can use the following functions:
|
|||||||
+ `bool is_int(PyObject* obj)`
|
+ `bool is_int(PyObject* obj)`
|
||||||
+ `bool is_float(PyObject* obj)`
|
+ `bool is_float(PyObject* obj)`
|
||||||
+ `bool is_tagged(PyObject* obj)`
|
+ `bool is_tagged(PyObject* obj)`
|
||||||
+ `bool is_non_tagged_type(PyObject* obj, Type type)`
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
PyObject* obj = py_var(vm, 1);
|
PyObject* obj = py_var(vm, 1);
|
||||||
@ -115,4 +114,4 @@ You can also use `check_` prefix functions assert the type of a `PyObject*`,
|
|||||||
which will throw `TypeError` on failure.
|
which will throw `TypeError` on failure.
|
||||||
|
|
||||||
+ `void check_type(PyObject* obj, Type type)`
|
+ `void check_type(PyObject* obj, Type type)`
|
||||||
+ `void check_non_tagged_type(PyObject* obj, Type type)`
|
|
||||||
|
@ -149,17 +149,13 @@ inline bool is_type(PyObject* obj, Type type) {
|
|||||||
#if PK_DEBUG_EXTRA_CHECK
|
#if PK_DEBUG_EXTRA_CHECK
|
||||||
if(obj == nullptr) throw std::runtime_error("is_type() called with nullptr");
|
if(obj == nullptr) throw std::runtime_error("is_type() called with nullptr");
|
||||||
#endif
|
#endif
|
||||||
switch(type.index){
|
if(type.index == kTpIntIndex) return is_int(obj);
|
||||||
case kTpIntIndex: return is_int(obj);
|
return !is_tagged(obj) && obj->type == type;
|
||||||
default: return !is_tagged(obj) && obj->type == type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[deprecated("use is_type() instead")]]
|
||||||
inline bool is_non_tagged_type(PyObject* obj, Type type) {
|
inline bool is_non_tagged_type(PyObject* obj, Type type) {
|
||||||
#if PK_DEBUG_EXTRA_CHECK
|
return is_type(obj, type);
|
||||||
if(obj == nullptr) throw std::runtime_error("is_non_tagged_type() called with nullptr");
|
|
||||||
#endif
|
|
||||||
return !is_tagged(obj) && obj->type == type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename, typename=void> struct has_gc_marker : std::false_type {};
|
template <typename, typename=void> struct has_gc_marker : std::false_type {};
|
||||||
|
@ -351,9 +351,9 @@ public:
|
|||||||
TypeError("expected " + _type_name(vm, type).escape() + ", got " + _type_name(vm, _tp(obj)).escape());
|
TypeError("expected " + _type_name(vm, type).escape() + ", got " + _type_name(vm, _tp(obj)).escape());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[deprecated("use check_type() instead")]]
|
||||||
void check_non_tagged_type(PyObject* obj, Type type){
|
void check_non_tagged_type(PyObject* obj, Type type){
|
||||||
if(is_non_tagged_type(obj, type)) return;
|
return check_type(obj, type);
|
||||||
TypeError("expected " + _type_name(vm, type).escape() + ", got " + _type_name(vm, _tp(obj)).escape());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_compatible_type(PyObject* obj, Type type){
|
void check_compatible_type(PyObject* obj, Type type){
|
||||||
@ -527,7 +527,7 @@ __T _py_cast__internal(VM* vm, PyObject* obj) {
|
|||||||
static_assert(!std::is_reference_v<__T>);
|
static_assert(!std::is_reference_v<__T>);
|
||||||
// str (shortcuts)
|
// str (shortcuts)
|
||||||
if(obj == vm->None) return nullptr;
|
if(obj == vm->None) return nullptr;
|
||||||
if constexpr(with_check) vm->check_non_tagged_type(obj, vm->tp_str);
|
if constexpr(with_check) vm->check_type(obj, vm->tp_str);
|
||||||
return PK_OBJ_GET(Str, obj).c_str();
|
return PK_OBJ_GET(Str, obj).c_str();
|
||||||
}else if constexpr(std::is_same_v<T, bool>){
|
}else if constexpr(std::is_same_v<T, bool>){
|
||||||
static_assert(!std::is_reference_v<__T>);
|
static_assert(!std::is_reference_v<__T>);
|
||||||
@ -571,7 +571,7 @@ __T _py_cast__internal(VM* vm, PyObject* obj) {
|
|||||||
// Exception is `subclass_enabled`
|
// Exception is `subclass_enabled`
|
||||||
vm->check_compatible_type(obj, const_type);
|
vm->check_compatible_type(obj, const_type);
|
||||||
}else{
|
}else{
|
||||||
vm->check_non_tagged_type(obj, const_type);
|
vm->check_type(obj, const_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PK_OBJ_GET(T, obj);
|
return PK_OBJ_GET(T, obj);
|
||||||
@ -597,7 +597,7 @@ PyObject* VM::bind_method(Type type, Str name, NativeFuncC fn) {
|
|||||||
|
|
||||||
template<int ARGC>
|
template<int ARGC>
|
||||||
PyObject* VM::bind_method(PyObject* obj, Str name, NativeFuncC fn) {
|
PyObject* VM::bind_method(PyObject* obj, Str name, NativeFuncC fn) {
|
||||||
check_non_tagged_type(obj, tp_type);
|
check_type(obj, tp_type);
|
||||||
return bind_method<ARGC>(PK_OBJ_GET(Type, obj), name, fn);
|
return bind_method<ARGC>(PK_OBJ_GET(Type, obj), name, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ struct Array2d{
|
|||||||
return self._get(col, row);
|
return self._get(col, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_non_tagged_type(xy[0], VM::tp_slice) && is_non_tagged_type(xy[1], VM::tp_slice)){
|
if(is_type(xy[0], VM::tp_slice) && is_type(xy[1], VM::tp_slice)){
|
||||||
HANDLE_SLICE();
|
HANDLE_SLICE();
|
||||||
PyObject* new_array_obj = vm->heap.gcnew<Array2d>(Array2d::_type(vm));
|
PyObject* new_array_obj = vm->heap.gcnew<Array2d>(Array2d::_type(vm));
|
||||||
Array2d& new_array = PK_OBJ_GET(Array2d, new_array_obj);
|
Array2d& new_array = PK_OBJ_GET(Array2d, new_array_obj);
|
||||||
@ -131,7 +131,7 @@ struct Array2d{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_non_tagged_type(xy[0], VM::tp_slice) && is_non_tagged_type(xy[1], VM::tp_slice)){
|
if(is_type(xy[0], VM::tp_slice) && is_type(xy[1], VM::tp_slice)){
|
||||||
HANDLE_SLICE();
|
HANDLE_SLICE();
|
||||||
|
|
||||||
bool is_basic_type = false;
|
bool is_basic_type = false;
|
||||||
@ -150,7 +150,7 @@ struct Array2d{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_non_tagged_type(_2, Array2d::_type(vm))){
|
if(!is_type(_2, Array2d::_type(vm))){
|
||||||
vm->TypeError(_S("expected int/float/str/bool/None or an array2d instance"));
|
vm->TypeError(_S("expected int/float/str/bool/None or an array2d instance"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ struct Array2d{
|
|||||||
|
|
||||||
vm->bind(type, "copy_(self, other)", [](VM* vm, ArgsView args){
|
vm->bind(type, "copy_(self, other)", [](VM* vm, ArgsView args){
|
||||||
Array2d& self = PK_OBJ_GET(Array2d, args[0]);
|
Array2d& self = PK_OBJ_GET(Array2d, args[0]);
|
||||||
if(is_non_tagged_type(args[1], VM::tp_list)){
|
if(is_type(args[1], VM::tp_list)){
|
||||||
const List& list = PK_OBJ_GET(List, args[1]);
|
const List& list = PK_OBJ_GET(List, args[1]);
|
||||||
if(list.size() != self.numel){
|
if(list.size() != self.numel){
|
||||||
vm->ValueError("list size must be equal to the number of elements in the array2d");
|
vm->ValueError("list size must be equal to the number of elements in the array2d");
|
||||||
@ -255,7 +255,7 @@ struct Array2d{
|
|||||||
|
|
||||||
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){
|
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){
|
||||||
Array2d& self = PK_OBJ_GET(Array2d, _0);
|
Array2d& self = PK_OBJ_GET(Array2d, _0);
|
||||||
if(!is_non_tagged_type(_1, Array2d::_type(vm))) return vm->NotImplemented;
|
if(!is_type(_1, Array2d::_type(vm))) return vm->NotImplemented;
|
||||||
Array2d& other = PK_OBJ_GET(Array2d, _1);
|
Array2d& other = PK_OBJ_GET(Array2d, _1);
|
||||||
if(self.n_cols != other.n_cols || self.n_rows != other.n_rows) return vm->False;
|
if(self.n_cols != other.n_cols || self.n_rows != other.n_rows) return vm->False;
|
||||||
for(int i = 0; i < self.numel; i++){
|
for(int i = 0; i < self.numel; i++){
|
||||||
|
@ -807,7 +807,7 @@ __NEXT_STEP:;
|
|||||||
StrName _name(byte.arg);
|
StrName _name(byte.arg);
|
||||||
PyObject* _0 = POPX(); // super
|
PyObject* _0 = POPX(); // super
|
||||||
if(_0 == None) _0 = _t(tp_object);
|
if(_0 == None) _0 = _t(tp_object);
|
||||||
check_non_tagged_type(_0, tp_type);
|
check_type(_0, tp_type);
|
||||||
_curr_class = new_type_object(frame->_module, _name, PK_OBJ_GET(Type, _0));
|
_curr_class = new_type_object(frame->_module, _name, PK_OBJ_GET(Type, _0));
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(END_CLASS) {
|
TARGET(END_CLASS) {
|
||||||
@ -826,7 +826,7 @@ __NEXT_STEP:;
|
|||||||
PK_ASSERT(_curr_class != nullptr);
|
PK_ASSERT(_curr_class != nullptr);
|
||||||
StrName _name(byte.arg);
|
StrName _name(byte.arg);
|
||||||
PyObject* _0 = POPX();
|
PyObject* _0 = POPX();
|
||||||
if(is_non_tagged_type(_0, tp_function)){
|
if(is_type(_0, tp_function)){
|
||||||
PK_OBJ_GET(Function, _0)._class = _curr_class;
|
PK_OBJ_GET(Function, _0)._class = _curr_class;
|
||||||
}
|
}
|
||||||
_curr_class->attr().set(_name, _0);
|
_curr_class->attr().set(_name, _0);
|
||||||
@ -854,13 +854,13 @@ __NEXT_STEP:;
|
|||||||
/*****************************************/
|
/*****************************************/
|
||||||
TARGET(EXCEPTION_MATCH) {
|
TARGET(EXCEPTION_MATCH) {
|
||||||
PyObject* assumed_type = POPX();
|
PyObject* assumed_type = POPX();
|
||||||
check_non_tagged_type(assumed_type, tp_type);
|
check_type(assumed_type, tp_type);
|
||||||
PyObject* e_obj = TOP();
|
PyObject* e_obj = TOP();
|
||||||
bool ok = isinstance(e_obj, PK_OBJ_GET(Type, assumed_type));
|
bool ok = isinstance(e_obj, PK_OBJ_GET(Type, assumed_type));
|
||||||
PUSH(VAR(ok));
|
PUSH(VAR(ok));
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(RAISE) {
|
TARGET(RAISE) {
|
||||||
if(is_non_tagged_type(TOP(), tp_type)){
|
if(is_type(TOP(), tp_type)){
|
||||||
TOP() = call(TOP());
|
TOP() = call(TOP());
|
||||||
}
|
}
|
||||||
if(!isinstance(TOP(), tp_exception)){
|
if(!isinstance(TOP(), tp_exception)){
|
||||||
|
@ -96,7 +96,7 @@ namespace pkpy{
|
|||||||
|
|
||||||
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* lhs, PyObject* rhs){
|
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* lhs, PyObject* rhs){
|
||||||
C99Struct& self = _CAST(C99Struct&, lhs);
|
C99Struct& self = _CAST(C99Struct&, lhs);
|
||||||
if(!is_non_tagged_type(rhs, C99Struct::_type(vm))) return vm->NotImplemented;
|
if(!is_type(rhs, C99Struct::_type(vm))) return vm->NotImplemented;
|
||||||
C99Struct& other = _CAST(C99Struct&, rhs);
|
C99Struct& other = _CAST(C99Struct&, rhs);
|
||||||
bool ok = self.size == other.size && memcmp(self.p, other.p, self.size) == 0;
|
bool ok = self.size == other.size && memcmp(self.p, other.p, self.size) == 0;
|
||||||
return VAR(ok);
|
return VAR(ok);
|
||||||
@ -167,7 +167,7 @@ void add_module_c(VM* vm){
|
|||||||
|
|
||||||
vm->bind(mod, "p_cast(ptr: 'void_p', cls: type[T]) -> T", [](VM* vm, ArgsView args){
|
vm->bind(mod, "p_cast(ptr: 'void_p', cls: type[T]) -> T", [](VM* vm, ArgsView args){
|
||||||
VoidP& ptr = CAST(VoidP&, args[0]);
|
VoidP& ptr = CAST(VoidP&, args[0]);
|
||||||
vm->check_non_tagged_type(args[1], vm->tp_type);
|
vm->check_type(args[1], vm->tp_type);
|
||||||
Type cls = PK_OBJ_GET(Type, args[1]);
|
Type cls = PK_OBJ_GET(Type, args[1]);
|
||||||
if(!vm->issubclass(cls, VoidP::_type(vm))){
|
if(!vm->issubclass(cls, VoidP::_type(vm))){
|
||||||
vm->ValueError("expected a subclass of void_p");
|
vm->ValueError("expected a subclass of void_p");
|
||||||
|
@ -134,7 +134,7 @@ namespace pkpy
|
|||||||
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM *vm, PyObject* _0, PyObject* _1)
|
vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM *vm, PyObject* _0, PyObject* _1)
|
||||||
{
|
{
|
||||||
const PyDeque &self = _CAST(PyDeque&, _0);
|
const PyDeque &self = _CAST(PyDeque&, _0);
|
||||||
if(!is_non_tagged_type(_0, PyDeque::_type(vm))) return vm->NotImplemented;
|
if(!is_type(_0, PyDeque::_type(vm))) return vm->NotImplemented;
|
||||||
const PyDeque &other = _CAST(PyDeque&, _1);
|
const PyDeque &other = _CAST(PyDeque&, _1);
|
||||||
if (self.dequeItems.size() != other.dequeItems.size()) return vm->False;
|
if (self.dequeItems.size() != other.dequeItems.size()) return vm->False;
|
||||||
for (int i = 0; i < self.dequeItems.size(); i++){
|
for (int i = 0; i < self.dequeItems.size(); i++){
|
||||||
|
@ -81,7 +81,7 @@ void add_module_dataclasses(VM* vm){
|
|||||||
PyObject* mod = vm->new_module("dataclasses");
|
PyObject* mod = vm->new_module("dataclasses");
|
||||||
|
|
||||||
vm->bind_func<1>(mod, "dataclass", [](VM* vm, ArgsView args){
|
vm->bind_func<1>(mod, "dataclass", [](VM* vm, ArgsView args){
|
||||||
vm->check_non_tagged_type(args[0], VM::tp_type);
|
vm->check_type(args[0], VM::tp_type);
|
||||||
Type cls = PK_OBJ_GET(Type, args[0]);
|
Type cls = PK_OBJ_GET(Type, args[0]);
|
||||||
NameDict& cls_d = args[0]->attr();
|
NameDict& cls_d = args[0]->attr();
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ namespace pkpy{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CodeEmitContext::add_const(PyObject* v){
|
int CodeEmitContext::add_const(PyObject* v){
|
||||||
if(is_non_tagged_type(v, vm->tp_str)){
|
if(is_type(v, vm->tp_str)){
|
||||||
// warning: should use add_const_string() instead
|
// warning: should use add_const_string() instead
|
||||||
return add_const_string(PK_OBJ_GET(Str, v).sv());
|
return add_const_string(PK_OBJ_GET(Str, v).sv());
|
||||||
}else{
|
}else{
|
||||||
|
@ -32,7 +32,7 @@ namespace pkpy{
|
|||||||
#define BIND_VEC_MUL_OP(D) \
|
#define BIND_VEC_MUL_OP(D) \
|
||||||
vm->bind__mul__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){ \
|
vm->bind__mul__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){ \
|
||||||
Vec##D& self = _CAST(Vec##D&, _0); \
|
Vec##D& self = _CAST(Vec##D&, _0); \
|
||||||
if(is_non_tagged_type(_1, Vec##D::_type(vm))){ \
|
if(is_type(_1, Vec##D::_type(vm))){ \
|
||||||
Vec##D& other = _CAST(Vec##D&, _1); \
|
Vec##D& other = _CAST(Vec##D&, _1); \
|
||||||
return VAR(self * other); \
|
return VAR(self * other); \
|
||||||
} \
|
} \
|
||||||
@ -356,11 +356,11 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s
|
|||||||
|
|
||||||
vm->bind__matmul__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){
|
vm->bind__matmul__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){
|
||||||
Mat3x3& self = _CAST(Mat3x3&, _0);
|
Mat3x3& self = _CAST(Mat3x3&, _0);
|
||||||
if(is_non_tagged_type(_1, Mat3x3::_type(vm))){
|
if(is_type(_1, Mat3x3::_type(vm))){
|
||||||
const Mat3x3& other = _CAST(Mat3x3&, _1);
|
const Mat3x3& other = _CAST(Mat3x3&, _1);
|
||||||
return VAR_T(Mat3x3, self.matmul(other));
|
return VAR_T(Mat3x3, self.matmul(other));
|
||||||
}
|
}
|
||||||
if(is_non_tagged_type(_1, Vec3::_type(vm))){
|
if(is_type(_1, Vec3::_type(vm))){
|
||||||
const Vec3& other = _CAST(Vec3&, _1);
|
const Vec3& other = _CAST(Vec3&, _1);
|
||||||
return VAR_T(Vec3, self.matmul(other));
|
return VAR_T(Vec3, self.matmul(other));
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ void add_module_json(VM* vm){
|
|||||||
PyObject* mod = vm->new_module("json");
|
PyObject* mod = vm->new_module("json");
|
||||||
vm->bind_func<1>(mod, "loads", [](VM* vm, ArgsView args) {
|
vm->bind_func<1>(mod, "loads", [](VM* vm, ArgsView args) {
|
||||||
std::string_view sv;
|
std::string_view sv;
|
||||||
if(is_non_tagged_type(args[0], vm->tp_bytes)){
|
if(is_type(args[0], vm->tp_bytes)){
|
||||||
sv = PK_OBJ_GET(Bytes, args[0]).sv();
|
sv = PK_OBJ_GET(Bytes, args[0]).sv();
|
||||||
}else{
|
}else{
|
||||||
sv = CAST(Str&, args[0]).sv();
|
sv = CAST(Str&, args[0]).sv();
|
||||||
@ -270,7 +270,7 @@ struct LineProfilerW{
|
|||||||
|
|
||||||
vm->bind(type, "add_function(self, func)", [](VM* vm, ArgsView args){
|
vm->bind(type, "add_function(self, func)", [](VM* vm, ArgsView args){
|
||||||
LineProfilerW& self = PK_OBJ_GET(LineProfilerW, args[0]);
|
LineProfilerW& self = PK_OBJ_GET(LineProfilerW, args[0]);
|
||||||
vm->check_non_tagged_type(args[1], VM::tp_function);
|
vm->check_type(args[1], VM::tp_function);
|
||||||
auto decl = PK_OBJ_GET(Function, args[1]).decl.get();
|
auto decl = PK_OBJ_GET(Function, args[1]).decl.get();
|
||||||
self.profiler.functions.insert(decl);
|
self.profiler.functions.insert(decl);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
|
@ -15,7 +15,7 @@ PyObject* PyArrayGetItem(VM* vm, PyObject* _0, PyObject* _1){
|
|||||||
index = vm->normalized_index(index, self.size());
|
index = vm->normalized_index(index, self.size());
|
||||||
return self[index];
|
return self[index];
|
||||||
}
|
}
|
||||||
if(is_non_tagged_type(_1, vm->tp_slice)){
|
if(is_type(_1, vm->tp_slice)){
|
||||||
const Slice& s = _CAST(Slice&, _1);
|
const Slice& s = _CAST(Slice&, _1);
|
||||||
int start, stop, step;
|
int start, stop, step;
|
||||||
vm->parse_int_slice(s, self.size(), start, stop, step);
|
vm->parse_int_slice(s, self.size(), start, stop, step);
|
||||||
@ -90,7 +90,7 @@ void init_builtins(VM* _vm) {
|
|||||||
}else{
|
}else{
|
||||||
vm->TypeError("super() takes 0 or 2 arguments");
|
vm->TypeError("super() takes 0 or 2 arguments");
|
||||||
}
|
}
|
||||||
vm->check_non_tagged_type(class_arg, vm->tp_type);
|
vm->check_type(class_arg, vm->tp_type);
|
||||||
Type type = PK_OBJ_GET(Type, class_arg);
|
Type type = PK_OBJ_GET(Type, class_arg);
|
||||||
if(!vm->isinstance(self_arg, type)){
|
if(!vm->isinstance(self_arg, type)){
|
||||||
StrName _0 = _type_name(vm, vm->_tp(self_arg));
|
StrName _0 = _type_name(vm, vm->_tp(self_arg));
|
||||||
@ -102,33 +102,33 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind_func<1>(_vm->builtins, "staticmethod", [](VM* vm, ArgsView args) {
|
_vm->bind_func<1>(_vm->builtins, "staticmethod", [](VM* vm, ArgsView args) {
|
||||||
PyObject* func = args[0];
|
PyObject* func = args[0];
|
||||||
vm->check_non_tagged_type(func, vm->tp_function);
|
vm->check_type(func, vm->tp_function);
|
||||||
return vm->heap.gcnew<StaticMethod>(vm->tp_staticmethod, args[0]);
|
return vm->heap.gcnew<StaticMethod>(vm->tp_staticmethod, args[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_func<1>(_vm->builtins, "classmethod", [](VM* vm, ArgsView args) {
|
_vm->bind_func<1>(_vm->builtins, "classmethod", [](VM* vm, ArgsView args) {
|
||||||
PyObject* func = args[0];
|
PyObject* func = args[0];
|
||||||
vm->check_non_tagged_type(func, vm->tp_function);
|
vm->check_type(func, vm->tp_function);
|
||||||
return vm->heap.gcnew<ClassMethod>(vm->tp_classmethod, args[0]);
|
return vm->heap.gcnew<ClassMethod>(vm->tp_classmethod, args[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_func<2>(_vm->builtins, "isinstance", [](VM* vm, ArgsView args) {
|
_vm->bind_func<2>(_vm->builtins, "isinstance", [](VM* vm, ArgsView args) {
|
||||||
if(is_non_tagged_type(args[1], vm->tp_tuple)){
|
if(is_type(args[1], vm->tp_tuple)){
|
||||||
Tuple& types = _CAST(Tuple&, args[1]);
|
Tuple& types = _CAST(Tuple&, args[1]);
|
||||||
for(PyObject* type : types){
|
for(PyObject* type : types){
|
||||||
vm->check_non_tagged_type(type, vm->tp_type);
|
vm->check_type(type, vm->tp_type);
|
||||||
if(vm->isinstance(args[0], PK_OBJ_GET(Type, type))) return vm->True;
|
if(vm->isinstance(args[0], PK_OBJ_GET(Type, type))) return vm->True;
|
||||||
}
|
}
|
||||||
return vm->False;
|
return vm->False;
|
||||||
}
|
}
|
||||||
vm->check_non_tagged_type(args[1], vm->tp_type);
|
vm->check_type(args[1], vm->tp_type);
|
||||||
Type type = PK_OBJ_GET(Type, args[1]);
|
Type type = PK_OBJ_GET(Type, args[1]);
|
||||||
return VAR(vm->isinstance(args[0], type));
|
return VAR(vm->isinstance(args[0], type));
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_func<2>(_vm->builtins, "issubclass", [](VM* vm, ArgsView args) {
|
_vm->bind_func<2>(_vm->builtins, "issubclass", [](VM* vm, ArgsView args) {
|
||||||
vm->check_non_tagged_type(args[0], vm->tp_type);
|
vm->check_type(args[0], vm->tp_type);
|
||||||
vm->check_non_tagged_type(args[1], vm->tp_type);
|
vm->check_type(args[1], vm->tp_type);
|
||||||
return VAR(vm->issubclass(PK_OBJ_GET(Type, args[0]), PK_OBJ_GET(Type, args[1])));
|
return VAR(vm->issubclass(PK_OBJ_GET(Type, args[0]), PK_OBJ_GET(Type, args[1])));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ void init_builtins(VM* _vm) {
|
|||||||
Frame* frame = vm->top_frame();
|
Frame* frame = vm->top_frame();
|
||||||
return vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
|
return vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
|
||||||
}
|
}
|
||||||
vm->check_non_tagged_type(globals, vm->tp_mappingproxy);
|
vm->check_type(globals, vm->tp_mappingproxy);
|
||||||
PyObject* obj = PK_OBJ_GET(MappingProxy, globals).obj;
|
PyObject* obj = PK_OBJ_GET(MappingProxy, globals).obj;
|
||||||
return vm->_exec(code, obj);
|
return vm->_exec(code, obj);
|
||||||
});
|
});
|
||||||
@ -202,7 +202,7 @@ void init_builtins(VM* _vm) {
|
|||||||
vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
|
vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
}
|
}
|
||||||
vm->check_non_tagged_type(globals, vm->tp_mappingproxy);
|
vm->check_type(globals, vm->tp_mappingproxy);
|
||||||
PyObject* obj = PK_OBJ_GET(MappingProxy, globals).obj;
|
PyObject* obj = PK_OBJ_GET(MappingProxy, globals).obj;
|
||||||
vm->_exec(code, obj);
|
vm->_exec(code, obj);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
@ -324,7 +324,7 @@ void init_builtins(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_vm->cached_object__new__ = _vm->bind_constructor<1>(_vm->_t(VM::tp_object), [](VM* vm, ArgsView args) {
|
_vm->cached_object__new__ = _vm->bind_constructor<1>(_vm->_t(VM::tp_object), [](VM* vm, ArgsView args) {
|
||||||
vm->check_non_tagged_type(args[0], vm->tp_type);
|
vm->check_type(args[0], vm->tp_type);
|
||||||
Type t = PK_OBJ_GET(Type, args[0]);
|
Type t = PK_OBJ_GET(Type, args[0]);
|
||||||
return vm->heap.gcnew<DummyInstance>(t);
|
return vm->heap.gcnew<DummyInstance>(t);
|
||||||
});
|
});
|
||||||
@ -562,7 +562,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
#define BIND_CMP_STR(name, op) \
|
#define BIND_CMP_STR(name, op) \
|
||||||
_vm->bind##name(VM::tp_str, [](VM* vm, PyObject* lhs, PyObject* rhs) { \
|
_vm->bind##name(VM::tp_str, [](VM* vm, PyObject* lhs, PyObject* rhs) { \
|
||||||
if(!is_non_tagged_type(rhs, vm->tp_str)) return vm->NotImplemented; \
|
if(!is_type(rhs, vm->tp_str)) return vm->NotImplemented; \
|
||||||
return VAR(_CAST(Str&, lhs) op _CAST(Str&, rhs)); \
|
return VAR(_CAST(Str&, lhs) op _CAST(Str&, rhs)); \
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -575,7 +575,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind__getitem__(VM::tp_str, [](VM* vm, PyObject* _0, PyObject* _1) {
|
_vm->bind__getitem__(VM::tp_str, [](VM* vm, PyObject* _0, PyObject* _1) {
|
||||||
const Str& self = PK_OBJ_GET(Str, _0);
|
const Str& self = PK_OBJ_GET(Str, _0);
|
||||||
if(is_non_tagged_type(_1, vm->tp_slice)){
|
if(is_type(_1, vm->tp_slice)){
|
||||||
const Slice& s = _CAST(Slice&, _1);
|
const Slice& s = _CAST(Slice&, _1);
|
||||||
int start, stop, step;
|
int start, stop, step;
|
||||||
vm->parse_int_slice(s, self.u8_length(), start, stop, step);
|
vm->parse_int_slice(s, self.u8_length(), start, stop, step);
|
||||||
@ -831,7 +831,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind__eq__(VM::tp_list, [](VM* vm, PyObject* _0, PyObject* _1) {
|
_vm->bind__eq__(VM::tp_list, [](VM* vm, PyObject* _0, PyObject* _1) {
|
||||||
List& a = _CAST(List&, _0);
|
List& a = _CAST(List&, _0);
|
||||||
if(!is_non_tagged_type(_1, vm->tp_list)) return vm->NotImplemented;
|
if(!is_type(_1, vm->tp_list)) return vm->NotImplemented;
|
||||||
List& b = _CAST(List&, _1);
|
List& b = _CAST(List&, _1);
|
||||||
if(a.size() != b.size()) return vm->False;
|
if(a.size() != b.size()) return vm->False;
|
||||||
for(int i=0; i<a.size(); i++){
|
for(int i=0; i<a.size(); i++){
|
||||||
@ -943,7 +943,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
#define BIND_RICH_CMP(name, op, _t, _T) \
|
#define BIND_RICH_CMP(name, op, _t, _T) \
|
||||||
_vm->bind__##name##__(_vm->_t, [](VM* vm, PyObject* lhs, PyObject* rhs){ \
|
_vm->bind__##name##__(_vm->_t, [](VM* vm, PyObject* lhs, PyObject* rhs){ \
|
||||||
if(!is_non_tagged_type(rhs, vm->_t)) return vm->NotImplemented; \
|
if(!is_type(rhs, vm->_t)) return vm->NotImplemented; \
|
||||||
auto& a = _CAST(_T&, lhs); \
|
auto& a = _CAST(_T&, lhs); \
|
||||||
auto& b = _CAST(_T&, rhs); \
|
auto& b = _CAST(_T&, rhs); \
|
||||||
for(int i=0; i<a.size() && i<b.size(); i++){ \
|
for(int i=0; i<a.size() && i<b.size(); i++){ \
|
||||||
@ -1019,7 +1019,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind__eq__(VM::tp_tuple, [](VM* vm, PyObject* _0, PyObject* _1) {
|
_vm->bind__eq__(VM::tp_tuple, [](VM* vm, PyObject* _0, PyObject* _1) {
|
||||||
const Tuple& self = _CAST(Tuple&, _0);
|
const Tuple& self = _CAST(Tuple&, _0);
|
||||||
if(!is_non_tagged_type(_1, vm->tp_tuple)) return vm->NotImplemented;
|
if(!is_type(_1, vm->tp_tuple)) return vm->NotImplemented;
|
||||||
const Tuple& other = _CAST(Tuple&, _1);
|
const Tuple& other = _CAST(Tuple&, _1);
|
||||||
if(self.size() != other.size()) return vm->False;
|
if(self.size() != other.size()) return vm->False;
|
||||||
for(int i = 0; i < self.size(); i++) {
|
for(int i = 0; i < self.size(); i++) {
|
||||||
@ -1067,7 +1067,7 @@ void init_builtins(VM* _vm) {
|
|||||||
return VAR(_CAST(bool, _0) != CAST(bool, _1));
|
return VAR(_CAST(bool, _0) != CAST(bool, _1));
|
||||||
});
|
});
|
||||||
_vm->bind__eq__(VM::tp_bool, [](VM* vm, PyObject* _0, PyObject* _1) {
|
_vm->bind__eq__(VM::tp_bool, [](VM* vm, PyObject* _0, PyObject* _1) {
|
||||||
if(is_non_tagged_type(_1, vm->tp_bool)) return VAR(_0 == _1);
|
if(is_type(_1, vm->tp_bool)) return VAR(_0 == _1);
|
||||||
if(is_int(_1)) return VAR(_CAST(bool, _0) == (bool)CAST(i64, _1));
|
if(is_int(_1)) return VAR(_CAST(bool, _0) == (bool)CAST(i64, _1));
|
||||||
return vm->NotImplemented;
|
return vm->NotImplemented;
|
||||||
});
|
});
|
||||||
@ -1094,7 +1094,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind__getitem__(VM::tp_bytes, [](VM* vm, PyObject* _0, PyObject* _1) {
|
_vm->bind__getitem__(VM::tp_bytes, [](VM* vm, PyObject* _0, PyObject* _1) {
|
||||||
const Bytes& self = PK_OBJ_GET(Bytes, _0);
|
const Bytes& self = PK_OBJ_GET(Bytes, _0);
|
||||||
if(is_non_tagged_type(_1, vm->tp_slice)){
|
if(is_type(_1, vm->tp_slice)){
|
||||||
const Slice& s = _CAST(Slice&, _1);
|
const Slice& s = _CAST(Slice&, _1);
|
||||||
int start, stop, step;
|
int start, stop, step;
|
||||||
vm->parse_int_slice(s, self.size(), start, stop, step);
|
vm->parse_int_slice(s, self.size(), start, stop, step);
|
||||||
@ -1147,7 +1147,7 @@ void init_builtins(VM* _vm) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind__eq__(VM::tp_bytes, [](VM* vm, PyObject* _0, PyObject* _1) {
|
_vm->bind__eq__(VM::tp_bytes, [](VM* vm, PyObject* _0, PyObject* _1) {
|
||||||
if(!is_non_tagged_type(_1, vm->tp_bytes)) return vm->NotImplemented;
|
if(!is_type(_1, vm->tp_bytes)) return vm->NotImplemented;
|
||||||
return VAR(_CAST(Bytes&, _0) == _CAST(Bytes&, _1));
|
return VAR(_CAST(Bytes&, _0) == _CAST(Bytes&, _1));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1158,7 +1158,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind__eq__(VM::tp_slice, [](VM* vm, PyObject* _0, PyObject* _1){
|
_vm->bind__eq__(VM::tp_slice, [](VM* vm, PyObject* _0, PyObject* _1){
|
||||||
const Slice& self = _CAST(Slice&, _0);
|
const Slice& self = _CAST(Slice&, _0);
|
||||||
if(!is_non_tagged_type(_1, vm->tp_slice)) return vm->NotImplemented;
|
if(!is_type(_1, vm->tp_slice)) return vm->NotImplemented;
|
||||||
const Slice& other = _CAST(Slice&, _1);
|
const Slice& other = _CAST(Slice&, _1);
|
||||||
if(vm->py_ne(self.start, other.start)) return vm->False;
|
if(vm->py_ne(self.start, other.start)) return vm->False;
|
||||||
if(vm->py_ne(self.stop, other.stop)) return vm->False;
|
if(vm->py_ne(self.stop, other.stop)) return vm->False;
|
||||||
@ -1207,7 +1207,7 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind__eq__(VM::tp_mappingproxy, [](VM* vm, PyObject* _0, PyObject* _1){
|
_vm->bind__eq__(VM::tp_mappingproxy, [](VM* vm, PyObject* _0, PyObject* _1){
|
||||||
const MappingProxy& a = _CAST(MappingProxy&, _0);
|
const MappingProxy& a = _CAST(MappingProxy&, _0);
|
||||||
if(!is_non_tagged_type(_1, vm->tp_mappingproxy)) return vm->NotImplemented;
|
if(!is_type(_1, vm->tp_mappingproxy)) return vm->NotImplemented;
|
||||||
const MappingProxy& b = _CAST(MappingProxy&, _1);
|
const MappingProxy& b = _CAST(MappingProxy&, _1);
|
||||||
return VAR(a.obj == b.obj);
|
return VAR(a.obj == b.obj);
|
||||||
});
|
});
|
||||||
@ -1262,12 +1262,12 @@ void init_builtins(VM* _vm) {
|
|||||||
if(args.size() == 1+1){
|
if(args.size() == 1+1){
|
||||||
auto _lock = vm->heap.gc_scope_lock();
|
auto _lock = vm->heap.gc_scope_lock();
|
||||||
Dict& self = PK_OBJ_GET(Dict, args[0]);
|
Dict& self = PK_OBJ_GET(Dict, args[0]);
|
||||||
if(is_non_tagged_type(args[1], vm->tp_dict)){
|
if(is_type(args[1], vm->tp_dict)){
|
||||||
Dict& other = CAST(Dict&, args[1]);
|
Dict& other = CAST(Dict&, args[1]);
|
||||||
self.update(other);
|
self.update(other);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
}
|
}
|
||||||
if(is_non_tagged_type(args[1], vm->tp_list)){
|
if(is_type(args[1], vm->tp_list)){
|
||||||
List& list = PK_OBJ_GET(List, args[1]);
|
List& list = PK_OBJ_GET(List, args[1]);
|
||||||
for(PyObject* item : list){
|
for(PyObject* item : list){
|
||||||
Tuple& t = CAST(Tuple&, item);
|
Tuple& t = CAST(Tuple&, item);
|
||||||
@ -1563,7 +1563,7 @@ void VM::post_init(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
bind__eq__(tp_bound_method, [](VM* vm, PyObject* lhs, PyObject* rhs){
|
bind__eq__(tp_bound_method, [](VM* vm, PyObject* lhs, PyObject* rhs){
|
||||||
if(!is_non_tagged_type(rhs, vm->tp_bound_method)) return vm->NotImplemented;
|
if(!is_type(rhs, vm->tp_bound_method)) return vm->NotImplemented;
|
||||||
const BoundMethod& _0 = PK_OBJ_GET(BoundMethod, lhs);
|
const BoundMethod& _0 = PK_OBJ_GET(BoundMethod, lhs);
|
||||||
const BoundMethod& _1 = PK_OBJ_GET(BoundMethod, rhs);
|
const BoundMethod& _1 = PK_OBJ_GET(BoundMethod, rhs);
|
||||||
return VAR(_0.self == _1.self && _0.func == _1.func);
|
return VAR(_0.self == _1.self && _0.func == _1.func);
|
||||||
|
@ -215,7 +215,7 @@ bool pkpy_is_bool(pkpy_vm* vm_handle, int i){
|
|||||||
PK_ASSERT_NO_ERROR()
|
PK_ASSERT_NO_ERROR()
|
||||||
PK_PROTECTED(
|
PK_PROTECTED(
|
||||||
PyObject* item = stack_item(vm, i);
|
PyObject* item = stack_item(vm, i);
|
||||||
return is_non_tagged_type(item, vm->tp_bool);
|
return is_type(item, vm->tp_bool);
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ bool pkpy_is_string(pkpy_vm* vm_handle, int i){
|
|||||||
PK_ASSERT_NO_ERROR()
|
PK_ASSERT_NO_ERROR()
|
||||||
PK_PROTECTED(
|
PK_PROTECTED(
|
||||||
PyObject* item = stack_item(vm, i);
|
PyObject* item = stack_item(vm, i);
|
||||||
return is_non_tagged_type(item, vm->tp_str);
|
return is_type(item, vm->tp_str);
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ bool pkpy_is_voidp(pkpy_vm* vm_handle, int i){
|
|||||||
PK_ASSERT_NO_ERROR()
|
PK_ASSERT_NO_ERROR()
|
||||||
PK_PROTECTED(
|
PK_PROTECTED(
|
||||||
PyObject* item = stack_item(vm, i);
|
PyObject* item = stack_item(vm, i);
|
||||||
return is_non_tagged_type(item, VoidP::_type(vm));
|
return is_type(item, VoidP::_type(vm));
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
src/vm.cpp
22
src/vm.cpp
@ -25,7 +25,7 @@ namespace pkpy{
|
|||||||
dict.apply([&](PyObject* k, PyObject* v){
|
dict.apply([&](PyObject* k, PyObject* v){
|
||||||
if(!first) ss << ", ";
|
if(!first) ss << ", ";
|
||||||
first = false;
|
first = false;
|
||||||
if(!is_non_tagged_type(k, vm->tp_str)){
|
if(!is_type(k, VM::tp_str)){
|
||||||
vm->TypeError(_S("json keys must be string, got ", _type_name(vm, vm->_tp(k))));
|
vm->TypeError(_S("json keys must be string, got ", _type_name(vm, vm->_tp(k))));
|
||||||
}
|
}
|
||||||
ss << _CAST(Str&, k).escape(false) << ": ";
|
ss << _CAST(Str&, k).escape(false) << ": ";
|
||||||
@ -108,10 +108,10 @@ namespace pkpy{
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<PyObject**, int> VM::_cast_array(PyObject* obj){
|
std::pair<PyObject**, int> VM::_cast_array(PyObject* obj){
|
||||||
if(is_non_tagged_type(obj, VM::tp_list)){
|
if(is_type(obj, VM::tp_list)){
|
||||||
List& list = PK_OBJ_GET(List, obj);
|
List& list = PK_OBJ_GET(List, obj);
|
||||||
return {list.data(), list.size()};
|
return {list.data(), list.size()};
|
||||||
}else if(is_non_tagged_type(obj, VM::tp_tuple)){
|
}else if(is_type(obj, VM::tp_tuple)){
|
||||||
Tuple& tuple = PK_OBJ_GET(Tuple, obj);
|
Tuple& tuple = PK_OBJ_GET(Tuple, obj);
|
||||||
return {tuple.data(), tuple.size()};
|
return {tuple.data(), tuple.size()};
|
||||||
}
|
}
|
||||||
@ -760,7 +760,7 @@ void VM::init_builtin_types(){
|
|||||||
// `heap.gc_scope_lock();` needed before calling this function
|
// `heap.gc_scope_lock();` needed before calling this function
|
||||||
void VM::_unpack_as_list(ArgsView args, List& list){
|
void VM::_unpack_as_list(ArgsView args, List& list){
|
||||||
for(PyObject* obj: args){
|
for(PyObject* obj: args){
|
||||||
if(is_non_tagged_type(obj, tp_star_wrapper)){
|
if(is_type(obj, tp_star_wrapper)){
|
||||||
const StarWrapper& w = _CAST(StarWrapper&, obj);
|
const StarWrapper& w = _CAST(StarWrapper&, obj);
|
||||||
// maybe this check should be done in the compile time
|
// maybe this check should be done in the compile time
|
||||||
if(w.level != 1) TypeError("expected level 1 star wrapper");
|
if(w.level != 1) TypeError("expected level 1 star wrapper");
|
||||||
@ -779,7 +779,7 @@ void VM::_unpack_as_list(ArgsView args, List& list){
|
|||||||
// `heap.gc_scope_lock();` needed before calling this function
|
// `heap.gc_scope_lock();` needed before calling this function
|
||||||
void VM::_unpack_as_dict(ArgsView args, Dict& dict){
|
void VM::_unpack_as_dict(ArgsView args, Dict& dict){
|
||||||
for(PyObject* obj: args){
|
for(PyObject* obj: args){
|
||||||
if(is_non_tagged_type(obj, tp_star_wrapper)){
|
if(is_type(obj, tp_star_wrapper)){
|
||||||
const StarWrapper& w = _CAST(StarWrapper&, obj);
|
const StarWrapper& w = _CAST(StarWrapper&, obj);
|
||||||
// maybe this check should be done in the compile time
|
// maybe this check should be done in the compile time
|
||||||
if(w.level != 2) TypeError("expected level 2 star wrapper");
|
if(w.level != 2) TypeError("expected level 2 star wrapper");
|
||||||
@ -1010,7 +1010,7 @@ void VM::delattr(PyObject *_0, StrName _name){
|
|||||||
PyObject* VM::getattr(PyObject* obj, StrName name, bool throw_err){
|
PyObject* VM::getattr(PyObject* obj, StrName name, bool throw_err){
|
||||||
Type objtype(0);
|
Type objtype(0);
|
||||||
// handle super() proxy
|
// handle super() proxy
|
||||||
if(is_non_tagged_type(obj, tp_super)){
|
if(is_type(obj, tp_super)){
|
||||||
const Super& super = PK_OBJ_GET(Super, obj);
|
const Super& super = PK_OBJ_GET(Super, obj);
|
||||||
obj = super.first;
|
obj = super.first;
|
||||||
objtype = super.second;
|
objtype = super.second;
|
||||||
@ -1020,7 +1020,7 @@ PyObject* VM::getattr(PyObject* obj, StrName name, bool throw_err){
|
|||||||
PyObject* cls_var = find_name_in_mro(objtype, name);
|
PyObject* cls_var = find_name_in_mro(objtype, name);
|
||||||
if(cls_var != nullptr){
|
if(cls_var != nullptr){
|
||||||
// handle descriptor
|
// handle descriptor
|
||||||
if(is_non_tagged_type(cls_var, tp_property)){
|
if(is_type(cls_var, tp_property)){
|
||||||
const Property& prop = PK_OBJ_GET(Property, cls_var);
|
const Property& prop = PK_OBJ_GET(Property, cls_var);
|
||||||
return call(prop.getter, obj);
|
return call(prop.getter, obj);
|
||||||
}
|
}
|
||||||
@ -1074,7 +1074,7 @@ PyObject* VM::get_unbound_method(PyObject* obj, StrName name, PyObject** self, b
|
|||||||
*self = PY_NULL;
|
*self = PY_NULL;
|
||||||
Type objtype(0);
|
Type objtype(0);
|
||||||
// handle super() proxy
|
// handle super() proxy
|
||||||
if(is_non_tagged_type(obj, tp_super)){
|
if(is_type(obj, tp_super)){
|
||||||
const Super& super = PK_OBJ_GET(Super, obj);
|
const Super& super = PK_OBJ_GET(Super, obj);
|
||||||
obj = super.first;
|
obj = super.first;
|
||||||
objtype = super.second;
|
objtype = super.second;
|
||||||
@ -1086,7 +1086,7 @@ PyObject* VM::get_unbound_method(PyObject* obj, StrName name, PyObject** self, b
|
|||||||
if(fallback){
|
if(fallback){
|
||||||
if(cls_var != nullptr){
|
if(cls_var != nullptr){
|
||||||
// handle descriptor
|
// handle descriptor
|
||||||
if(is_non_tagged_type(cls_var, tp_property)){
|
if(is_type(cls_var, tp_property)){
|
||||||
const Property& prop = PK_OBJ_GET(Property, cls_var);
|
const Property& prop = PK_OBJ_GET(Property, cls_var);
|
||||||
return call(prop.getter, obj);
|
return call(prop.getter, obj);
|
||||||
}
|
}
|
||||||
@ -1142,7 +1142,7 @@ PyObject* VM::get_unbound_method(PyObject* obj, StrName name, PyObject** self, b
|
|||||||
void VM::setattr(PyObject* obj, StrName name, PyObject* value){
|
void VM::setattr(PyObject* obj, StrName name, PyObject* value){
|
||||||
Type objtype(0);
|
Type objtype(0);
|
||||||
// handle super() proxy
|
// handle super() proxy
|
||||||
if(is_non_tagged_type(obj, tp_super)){
|
if(is_type(obj, tp_super)){
|
||||||
Super& super = PK_OBJ_GET(Super, obj);
|
Super& super = PK_OBJ_GET(Super, obj);
|
||||||
obj = super.first;
|
obj = super.first;
|
||||||
objtype = super.second;
|
objtype = super.second;
|
||||||
@ -1152,7 +1152,7 @@ void VM::setattr(PyObject* obj, StrName name, PyObject* value){
|
|||||||
PyObject* cls_var = find_name_in_mro(objtype, name);
|
PyObject* cls_var = find_name_in_mro(objtype, name);
|
||||||
if(cls_var != nullptr){
|
if(cls_var != nullptr){
|
||||||
// handle descriptor
|
// handle descriptor
|
||||||
if(is_non_tagged_type(cls_var, tp_property)){
|
if(is_type(cls_var, tp_property)){
|
||||||
const Property& prop = _CAST(Property&, cls_var);
|
const Property& prop = _CAST(Property&, cls_var);
|
||||||
if(prop.setter != vm->None){
|
if(prop.setter != vm->None){
|
||||||
call(prop.setter, obj, value);
|
call(prop.setter, obj, value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user