diff --git a/3rd/lua_bridge/src/lua_bridge.cpp b/3rd/lua_bridge/src/lua_bridge.cpp index 5af54223..8a562228 100644 --- a/3rd/lua_bridge/src/lua_bridge.cpp +++ b/3rd/lua_bridge/src/lua_bridge.cpp @@ -82,8 +82,7 @@ struct PyLuaTable: PyLuaObject{ vm->bind_func(type, __new__, 1, [](VM* vm, ArgsView args){ lua_newtable(_L); // push an empty table onto the stack - PyVar obj = vm->heap.gcnew(PK_OBJ_GET(Type, args[0])); - return obj; + return vm->new_object(PK_OBJ_GET(Type, args[0])); }); vm->bind__len__(t, [](VM* vm, PyVar obj){ diff --git a/docs/modules/linalg.md b/docs/modules/linalg.md index a9cd0fa5..6056ff10 100644 --- a/docs/modules/linalg.md +++ b/docs/modules/linalg.md @@ -36,10 +36,6 @@ class vec2(_StructLike['vec2']): def normalize(self) -> vec2: ... def rotate(self, radians: float) -> vec2: ... - def copy_(self, other: vec2) -> None: ... - def normalize_(self) -> None: ... - def rotate_(self, radians: float) -> None: ... - @staticmethod def angle(__from: vec2, __to: vec2) -> float: """Returns the angle in radians between vectors `from` and `to`. @@ -77,9 +73,6 @@ class vec3(_StructLike['vec3']): def length_squared(self) -> float: ... def normalize(self) -> vec3: ... - def copy_(self, other: vec3) -> None: ... - def normalize_(self) -> None: ... - class vec4(_StructLike['vec4']): x: float y: float diff --git a/include/pocketpy/bindings.h b/include/pocketpy/bindings.h index 08ee9939..b50aaf92 100644 --- a/include/pocketpy/bindings.h +++ b/include/pocketpy/bindings.h @@ -97,7 +97,7 @@ PyVar VM::bind_field(PyVar obj, const char* name, F T::*field){ F T::*field = lambda_get_userdata(args.begin()); return VAR(self.*field); }; - PyVar _0 = heap.gcnew(tp_native_func, fget, 1, field); + PyVar _0 = new_object(tp_native_func, fget, 1, field); PyVar _1 = vm->None; if constexpr (!ReadOnly){ auto fset = [](VM* vm, ArgsView args){ @@ -106,7 +106,7 @@ PyVar VM::bind_field(PyVar obj, const char* name, F T::*field){ self.*field = py_cast(vm, args[1]); return vm->None; }; - _1 = heap.gcnew(tp_native_func, fset, 2, field); + _1 = new_object(tp_native_func, fset, 2, field); } PyVar prop = VAR(Property(_0, _1)); obj->attr().set(StrName(name_sv), prop); diff --git a/include/pocketpy/cffi.h b/include/pocketpy/cffi.h index cf7aa952..cca04c41 100644 --- a/include/pocketpy/cffi.h +++ b/include/pocketpy/cffi.h @@ -38,8 +38,8 @@ struct VoidP{ #define POINTER_VAR(Tp, NAME) \ inline PyVar py_var(VM* vm, Tp val){ \ const static std::pair P("c", NAME); \ - PyVar type = vm->_modules[P.first]->attr(P.second); \ - return vm->heap.gcnew(PK_OBJ_GET(Type, type), val); \ + PyVar type = vm->_modules[P.first]->attr(P.second); \ + return vm->new_object(PK_OBJ_GET(Type, type), val); \ } POINTER_VAR(char*, "char_p") diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h index bf91362d..e065cf63 100644 --- a/include/pocketpy/common.h +++ b/include/pocketpy/common.h @@ -185,6 +185,7 @@ struct PyVar final{ // SSO initialized (is_sso = true) template PyVar(Type type, T value): type(type), is_sso(true), flags(0) { + static_assert(sizeof(T) <= sizeof(_bytes), "SSO size exceeded"); as() = value; } @@ -222,6 +223,12 @@ struct PyVar final{ static_assert(sizeof(PyVar) == 16 && is_pod_v); +// by default, only `int` and `float` enable SSO +// users can specialize this template to enable SSO for other types +// SSO types cannot have instance dict +template +inline constexpr bool is_sso_v = is_integral_v || is_floating_point_v; + } // namespace pkpy diff --git a/include/pocketpy/config.h b/include/pocketpy/config.h index 24e30f7a..a1733f32 100644 --- a/include/pocketpy/config.h +++ b/include/pocketpy/config.h @@ -33,7 +33,7 @@ /*************** debug settings ***************/ // Enable this may help you find bugs -#define PK_DEBUG_EXTRA_CHECK 0 +#define PK_DEBUG_EXTRA_CHECK 1 // Do not edit the following settings unless you know what you are doing #define PK_DEBUG_CEVAL_STEP 0 diff --git a/include/pocketpy/gc.h b/include/pocketpy/gc.h index 99f6309f..13ac14ce 100644 --- a/include/pocketpy/gc.h +++ b/include/pocketpy/gc.h @@ -41,6 +41,7 @@ struct ManagedHeap{ template PyVar gcnew(Type type, Args&&... args){ using __T = Py_>; + static_assert(!is_sso_v<__T>, "gcnew cannot be used with SSO types"); // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476 PyObject* p = new(pool128_alloc<__T>()) Py_>(std::forward(args)...); PyVar obj(type, p); @@ -52,7 +53,7 @@ struct ManagedHeap{ template PyVar _new(Type type, Args&&... args){ using __T = Py_>; - // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476 + static_assert(!is_sso_v<__T>); PyObject* p = new(pool128_alloc<__T>()) Py_>(std::forward(args)...); PyVar obj(type, p); obj->gc_enabled = false; diff --git a/include/pocketpy/linalg.h b/include/pocketpy/linalg.h index fd4f250e..ed7d2b59 100644 --- a/include/pocketpy/linalg.h +++ b/include/pocketpy/linalg.h @@ -27,8 +27,6 @@ struct Vec2{ float length_squared() const { return x * x + y * y; } Vec2 normalize() const { float l = length(); return Vec2(x / l, y / l); } Vec2 rotate(float radian) const { float cr = cosf(radian), sr = sinf(radian); return Vec2(x * cr - y * sr, x * sr + y * cr); } - NoReturn normalize_() { float l = length(); x /= l; y /= l; return {}; } - NoReturn copy_(const Vec2& v) { x = v.x; y = v.y; return {}; } }; struct Vec3{ @@ -51,8 +49,6 @@ struct Vec3{ float length() const { return sqrtf(x * x + y * y + z * z); } float length_squared() const { return x * x + y * y + z * z; } Vec3 normalize() const { float l = length(); return Vec3(x / l, y / l, z / l); } - NoReturn normalize_() { float l = length(); x /= l; y /= l; z /= l; return {}; } - NoReturn copy_(const Vec3& v) { x = v.x; y = v.y; z = v.z; return {}; } }; struct Vec4{ @@ -129,4 +125,9 @@ static_assert(is_pod_v); static_assert(is_pod_v); static_assert(is_pod_v); +template<> +inline constexpr bool is_sso_v = true; +template<> +inline constexpr bool is_sso_v = true; + } // namespace pkpy \ No newline at end of file diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index 4ac6cfb1..4071a9e5 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -388,7 +388,13 @@ public: template PyVar new_user_object(Args&&... args){ - return heap.gcnew(_tp_user(), std::forward(args)...); + return new_object(_tp_user(), std::forward(args)...); + } + + template + PyVar new_object(Type type, Args&&... args){ + if constexpr(is_sso_v) return PyVar(type, T(std::forward(args)...)); + else return heap.gcnew(type, std::forward(args)...); } #endif @@ -489,11 +495,13 @@ PyVar py_var(VM* vm, __T&& value){ }else{ constexpr Type const_type = _find_type_in_const_cxx_typeid_map(); if constexpr(const_type){ - return vm->heap.gcnew(const_type, std::forward<__T>(value)); + if constexpr(is_sso_v) return PyVar(const_type, value); + else return vm->heap.gcnew(const_type, std::forward<__T>(value)); } } Type type = vm->_find_type_in_cxx_typeid_map(); - return vm->heap.gcnew(type, std::forward<__T>(value)); + if constexpr(is_sso_v) return PyVar(type, value); + else return vm->heap.gcnew(type, std::forward<__T>(value)); } template diff --git a/include/typings/linalg.pyi b/include/typings/linalg.pyi index d529e870..3927adf0 100644 --- a/include/typings/linalg.pyi +++ b/include/typings/linalg.pyi @@ -27,10 +27,6 @@ class vec2(_StructLike['vec2']): def normalize(self) -> vec2: ... def rotate(self, radians: float) -> vec2: ... - def copy_(self, other: vec2) -> None: ... - def normalize_(self) -> None: ... - def rotate_(self, radians: float) -> None: ... - @staticmethod def angle(__from: vec2, __to: vec2) -> float: """Returns the angle in radians between vectors `from` and `to`. @@ -71,9 +67,6 @@ class vec3(_StructLike['vec3']): def length_squared(self) -> float: ... def normalize(self) -> vec3: ... - def copy_(self, other: vec3) -> None: ... - def normalize_(self) -> None: ... - class vec4(_StructLike['vec4']): x: float y: float diff --git a/src/array2d.cpp b/src/array2d.cpp index 816fd2ce..2334b6dd 100644 --- a/src/array2d.cpp +++ b/src/array2d.cpp @@ -39,7 +39,7 @@ struct Array2d{ static void _register(VM* vm, PyVar mod, PyVar type){ vm->bind(type, "__new__(cls, *args, **kwargs)", [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); - return vm->heap.gcnew(cls); + return vm->new_object(cls); }); vm->bind(type, "__init__(self, n_cols: int, n_rows: int, default=None)", [](VM* vm, ArgsView args){ diff --git a/src/cffi.cpp b/src/cffi.cpp index 17f2bae7..8760eed9 100644 --- a/src/cffi.cpp +++ b/src/cffi.cpp @@ -6,7 +6,7 @@ namespace pkpy{ vm->bind_func(type, __new__, 2, [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); i64 addr = CAST(i64, args[1]); - return vm->heap.gcnew(cls, reinterpret_cast(addr)); + return vm->new_object(cls, reinterpret_cast(addr)); }); vm->bind__hash__(PK_OBJ_GET(Type, type), [](VM* vm, PyVar obj){ @@ -41,7 +41,7 @@ namespace pkpy{ vm->bind_func(type, __new__, 2, [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); int size = CAST(int, args[1]); - return vm->heap.gcnew(cls, size); + return vm->new_object(cls, size); }); vm->bind_func(type, "hex", 1, [](VM* vm, ArgsView args){ @@ -91,7 +91,7 @@ namespace pkpy{ vm->bind_func(type, "copy", 1, [](VM* vm, ArgsView args){ const Struct& self = _CAST(Struct&, args[0]); - return vm->heap.gcnew(vm->_tp(args[0]), self); + return vm->new_object(vm->_tp(args[0]), self); }); vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyVar lhs, PyVar rhs){ @@ -173,7 +173,7 @@ void add_module_c(VM* vm){ if(!vm->issubclass(cls, vm->_tp_user())){ vm->ValueError("expected a subclass of void_p"); } - return vm->heap.gcnew(cls, ptr.ptr); + return vm->new_object(cls, ptr.ptr); }); vm->bind(mod, "p_value(ptr: 'void_p') -> int", [](VM* vm, ArgsView args){ @@ -184,7 +184,7 @@ void add_module_c(VM* vm){ vm->bind(mod, "pp_deref(ptr: Tp) -> Tp", [](VM* vm, ArgsView args){ VoidP& ptr = CAST(VoidP&, args[0]); void* value = *reinterpret_cast(ptr.ptr); - return vm->heap.gcnew(args[0].type, value); + return vm->new_object(args[0].type, value); }); PyVar type; @@ -226,13 +226,13 @@ void add_module_c(VM* vm){ VoidP& voidp = PK_OBJ_GET(VoidP, lhs); \ i64 offset = CAST(i64, rhs); \ T* target = (T*)voidp.ptr; \ - return vm->heap.gcnew(lhs.type, target + offset); \ + return vm->new_object(lhs.type, target + offset); \ }); \ vm->bind__sub__(type_t, [](VM* vm, PyVar lhs, PyVar rhs){ \ VoidP& voidp = PK_OBJ_GET(VoidP, lhs); \ i64 offset = CAST(i64, rhs); \ T* target = (T*)voidp.ptr; \ - return vm->heap.gcnew(lhs.type, target - offset); \ + return vm->new_object(lhs.type, target - offset); \ }); \ vm->bind__repr__(type_t, [](VM* vm, PyVar obj) -> Str{ \ VoidP& self = _CAST(VoidP&, obj); \ diff --git a/src/collections.cpp b/src/collections.cpp index 0a6a10f8..d861b434 100644 --- a/src/collections.cpp +++ b/src/collections.cpp @@ -63,7 +63,7 @@ namespace pkpy Type cls_t = PK_OBJ_GET(Type, args[0]); PyVar iterable = args[1]; PyVar maxlen = args[2]; - return vm->heap.gcnew(cls_t, vm, iterable, maxlen); + return vm->new_object(cls_t, vm, iterable, maxlen); }); // gets the item at the given index, if index is negative, it will be treated as index + len(deque) // if the index is out of range, IndexError will be thrown --> required for [] operator diff --git a/src/gc.cpp b/src/gc.cpp index eade7843..f2cb4466 100644 --- a/src/gc.cpp +++ b/src/gc.cpp @@ -5,6 +5,7 @@ namespace pkpy{ int ManagedHeap::sweep(){ std::vector alive; for(PyVar obj: gen){ + PK_DEBUG_ASSERT(!obj.is_sso) if(obj->gc_marked){ obj->gc_marked = false; alive.push_back(obj); diff --git a/src/io.cpp b/src/io.cpp index 775e0a42..5d90a5e2 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -56,7 +56,7 @@ unsigned char* _default_import_handler(const char* name, int* out_size){ void FileIO::_register(VM* vm, PyVar mod, PyVar type){ vm->bind_func(type, __new__, 3, [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); - return vm->heap.gcnew(cls, vm, + return vm->new_object(cls, vm, py_cast(vm, args[1]), py_cast(vm, args[2])); }); @@ -154,7 +154,7 @@ void add_module_io(VM* vm){ void add_module_os(VM* vm){ PyVar mod = vm->new_module("os"); - PyVar path_obj = vm->heap.gcnew(vm->tp_object); + PyVar path_obj = vm->new_object(vm->tp_object); mod->attr().set("path", path_obj); // Working directory is shared by all VMs!! diff --git a/src/linalg.cpp b/src/linalg.cpp index 19d3683a..e007e172 100644 --- a/src/linalg.cpp +++ b/src/linalg.cpp @@ -123,7 +123,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s vm->bind_func(type, __new__, 3, [](VM* vm, ArgsView args){ float x = CAST_F(args[1]); float y = CAST_F(args[2]); - return vm->heap.gcnew(PK_OBJ_GET(Type, args[0]), x, y); + return vm->new_object(PK_OBJ_GET(Type, args[0]), x, y); }); // @staticmethod @@ -163,13 +163,6 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s return vm->new_user_object(self.rotate(radian)); }); - vm->bind_func(type, "rotate_", 2, [](VM* vm, ArgsView args){ - Vec2& self = _CAST(Vec2&, args[0]); - float radian = CAST(f64, args[1]); - self = self.rotate(radian); - return vm->None; - }); - PY_FIELD(Vec2, "x", x) PY_FIELD(Vec2, "y", y) @@ -179,11 +172,9 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s BIND_VEC_FLOAT_OP(2, __truediv__, /) BIND_VEC_FUNCTION_1(2, dot) BIND_VEC_FUNCTION_1(2, cross) - BIND_VEC_FUNCTION_1(2, copy_) BIND_VEC_FUNCTION_0(2, length) BIND_VEC_FUNCTION_0(2, length_squared) BIND_VEC_FUNCTION_0(2, normalize) - BIND_VEC_FUNCTION_0(2, normalize_) BIND_VEC_GETITEM(2) } @@ -197,7 +188,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s float x = CAST_F(args[1]); float y = CAST_F(args[2]); float z = CAST_F(args[3]); - return vm->heap.gcnew(PK_OBJ_GET(Type, args[0]), x, y, z); + return vm->new_object(PK_OBJ_GET(Type, args[0]), x, y, z); }); vm->bind__repr__(PK_OBJ_GET(Type, type), [](VM* vm, PyVar obj) -> Str{ @@ -217,11 +208,9 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s BIND_VEC_MUL_OP(3) BIND_VEC_FUNCTION_1(3, dot) BIND_VEC_FUNCTION_1(3, cross) - BIND_VEC_FUNCTION_1(3, copy_) BIND_VEC_FUNCTION_0(3, length) BIND_VEC_FUNCTION_0(3, length_squared) BIND_VEC_FUNCTION_0(3, normalize) - BIND_VEC_FUNCTION_0(3, normalize_) BIND_VEC_GETITEM(3) } @@ -236,7 +225,7 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s float y = CAST_F(args[2]); float z = CAST_F(args[3]); float w = CAST_F(args[4]); - return vm->heap.gcnew(PK_OBJ_GET(Type, args[0]), x, y, z, w); + return vm->new_object(PK_OBJ_GET(Type, args[0]), x, y, z, w); }); vm->bind__repr__(PK_OBJ_GET(Type, type), [](VM* vm, PyVar obj) -> Str{ @@ -274,18 +263,18 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s PY_STRUCT_LIKE(Mat3x3) vm->bind_func(type, __new__, -1, [](VM* vm, ArgsView args){ - if(args.size() == 1+0) return vm->heap.gcnew(PK_OBJ_GET(Type, args[0]), Mat3x3::zeros()); + if(args.size() == 1+0) return vm->new_object(PK_OBJ_GET(Type, args[0]), Mat3x3::zeros()); if(args.size() == 1+1){ const List& list = CAST(List&, args[1]); if(list.size() != 9) vm->TypeError("Mat3x3.__new__ takes a list of 9 floats"); Mat3x3 mat; for(int i=0; i<9; i++) mat.v[i] = CAST_F(list[i]); - return vm->heap.gcnew(PK_OBJ_GET(Type, args[0]), mat); + return vm->new_object(PK_OBJ_GET(Type, args[0]), mat); } if(args.size() == 1+9){ Mat3x3 mat; for(int i=0; i<9; i++) mat.v[i] = CAST_F(args[1+i]); - return vm->heap.gcnew(PK_OBJ_GET(Type, args[0]), mat); + return vm->new_object(PK_OBJ_GET(Type, args[0]), mat); } vm->TypeError(_S("Mat3x3.__new__ takes 0 or 1 or 9 arguments, got ", args.size()-1)); return vm->None; diff --git a/src/modules.cpp b/src/modules.cpp index 77040ba4..352d3eeb 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -71,8 +71,8 @@ void add_module_sys(VM* vm){ vm->setattr(mod, "version", VAR(PK_VERSION)); vm->setattr(mod, "platform", VAR(kPlatformStrings[PK_SYS_PLATFORM])); - PyVar stdout_ = vm->heap.gcnew(vm->tp_object); - PyVar stderr_ = vm->heap.gcnew(vm->tp_object); + PyVar stdout_ = vm->new_object(vm->tp_object); + PyVar stderr_ = vm->new_object(vm->tp_object); vm->setattr(mod, "stdout", stdout_); vm->setattr(mod, "stderr", stderr_); @@ -287,7 +287,7 @@ struct LineProfilerW{ static void _register(VM* vm, PyVar mod, PyVar type){ vm->bind_func(type, __new__, 1, [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); - return vm->heap.gcnew(cls); + return vm->new_object(cls); }); vm->bind(type, "add_function(self, func)", [](VM* vm, ArgsView args){ diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 83cb013d..e590c29d 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -104,19 +104,19 @@ void __init_builtins(VM* _vm) { StrName _1 = _type_name(vm, type); vm->TypeError("super(): " + _0.escape() + " is not an instance of " + _1.escape()); } - return vm->heap.gcnew(vm->tp_super, self_arg, vm->_all_types[type].base); + return vm->new_object(vm->tp_super, self_arg, vm->_all_types[type].base); }); _vm->bind_func(_vm->builtins, "staticmethod", 1, [](VM* vm, ArgsView args) { PyVar func = args[0]; vm->check_type(func, vm->tp_function); - return vm->heap.gcnew(vm->tp_staticmethod, args[0]); + return vm->new_object(vm->tp_staticmethod, args[0]); }); _vm->bind_func(_vm->builtins, "classmethod", 1, [](VM* vm, ArgsView args) { PyVar func = args[0]; vm->check_type(func, vm->tp_function); - return vm->heap.gcnew(vm->tp_classmethod, args[0]); + return vm->new_object(vm->tp_classmethod, args[0]); }); _vm->bind_func(_vm->builtins, "isinstance", 2, [](VM* vm, ArgsView args) { @@ -343,7 +343,7 @@ void __init_builtins(VM* _vm) { _vm->__cached_object_new = _vm->bind_func(VM::tp_object, __new__, 1, [](VM* vm, ArgsView args) { vm->check_type(args[0], vm->tp_type); Type t = PK_OBJ_GET(Type, args[0]); - return vm->heap.gcnew(t); + return vm->new_object(t); }); // tp_type @@ -1264,7 +1264,7 @@ void __init_builtins(VM* _vm) { // tp_dict _vm->bind_func(VM::tp_dict, __new__, -1, [](VM* vm, ArgsView args){ Type cls_t = PK_OBJ_GET(Type, args[0]); - return vm->heap.gcnew(cls_t, vm); + return vm->new_object(cls_t, vm); }); _vm->bind_func(VM::tp_dict, __init__, -1, [](VM* vm, ArgsView args){ @@ -1464,7 +1464,7 @@ void __init_builtins(VM* _vm) { _vm->bind_func(VM::tp_exception, __new__, -1, [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); StrName cls_name = _type_name(vm, cls); - PyVar e_obj = vm->heap.gcnew(cls, cls_name); + PyVar e_obj = vm->new_object(cls, cls_name); e_obj->_enable_instance_dict(); PK_OBJ_GET(Exception, e_obj)._self = e_obj; return e_obj; diff --git a/src/random.cpp b/src/random.cpp index aae385f1..6ce0ab80 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -136,7 +136,7 @@ struct Random{ static void _register(VM* vm, PyVar mod, PyVar type){ vm->bind_func(type, __new__, 1, [](VM* vm, ArgsView args){ Type cls = PK_OBJ_GET(Type, args[0]); - return vm->heap.gcnew(cls); + return vm->new_object(cls); }); vm->bind_func(type, "seed", 2, [](VM* vm, ArgsView args) { diff --git a/src/vm.cpp b/src/vm.cpp index e5cdf076..76ec6e6a 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -541,7 +541,7 @@ PyVar VM::__py_exec_internal(const CodeObject_& code, PyVar globals, PyVar local }else{ check_compatible_type(globals, VM::tp_dict); // make a temporary object and copy globals into it - globals_obj = heap.gcnew(VM::tp_object); + globals_obj = new_object(VM::tp_object); globals_obj->_enable_instance_dict(); globals_dict = &PK_OBJ_GET(Dict, globals); globals_dict->apply([&](PyVar k, PyVar v){ @@ -1095,7 +1095,7 @@ PyVar VM::vectorcall(int ARGC, int KWARGC, bool op_call){ PK_DEBUG_ASSERT(new_f != nullptr && !method_call); if(new_f == __cached_object_new) { // fast path for object.__new__ - obj = vm->heap.gcnew(PK_OBJ_GET(Type, callable)); + obj = vm->new_object(PK_OBJ_GET(Type, callable)); }else{ PUSH(new_f); PUSH(PY_NULL); @@ -1361,9 +1361,9 @@ PyVar VM::bind_property(PyVar obj, const char* name, NativeFuncC fget, NativeFun PK_ASSERT(is_type(obj, tp_type)); std::string_view name_sv(name); int pos = name_sv.find(':'); if(pos > 0) name_sv = name_sv.substr(0, pos); - PyVar _0 = heap.gcnew(tp_native_func, fget, 1); + PyVar _0 = new_object(tp_native_func, fget, 1); PyVar _1 = vm->None; - if(fset != nullptr) _1 = heap.gcnew(tp_native_func, fset, 2); + if(fset != nullptr) _1 = new_object(tp_native_func, fset, 2); PyVar prop = VAR(Property(_0, _1)); obj->attr().set(StrName(name_sv), prop); return prop; diff --git a/tests/80_linalg.py b/tests/80_linalg.py index f914e018..495fec29 100644 --- a/tests/80_linalg.py +++ b/tests/80_linalg.py @@ -39,8 +39,6 @@ test_vec2_copy = test_vec2.copy() radians = random.uniform(-10*math.pi, 10*math.pi) test_vec2_copy = rotated_vec2(test_vec2_copy, radians) assert test_vec2.rotate(radians) == test_vec2_copy -test_vec2.rotate_(radians) -assert test_vec2 == test_vec2_copy # test smooth_damp vel = vec2(0, 0)