diff --git a/amalgamate.py b/amalgamate.py index 9775e061..2f8c6e41 100644 --- a/amalgamate.py +++ b/amalgamate.py @@ -74,4 +74,7 @@ if os.path.exists("plugins/unity/PocketPyUnityPlugin"): if os.path.exists("plugins/godot/godot-cpp/pocketpy"): shutil.copy("amalgamated/pocketpy.h", "plugins/godot/godot-cpp/pocketpy/src/pocketpy.h") +if os.path.exists("/mnt/e/PainterEngine/project/pocketpy.h"): + shutil.copy("amalgamated/pocketpy.h", "/mnt/e/PainterEngine/project/pocketpy.h") + print("amalgamated/pocketpy.h") \ No newline at end of file diff --git a/src/obj.h b/src/obj.h index 6e16fe5f..519ccd76 100644 --- a/src/obj.h +++ b/src/obj.h @@ -105,6 +105,10 @@ struct PyObject{ _attr->~NameDict(); pool64.dealloc(_attr); } + + void enable_instance_dict(float lf=kInstAttrLoadFactor) noexcept { + _attr = new(pool64.alloc()) NameDict(lf); + } }; template diff --git a/src/tuplelist.h b/src/tuplelist.h index 80779d7f..0c8e47f7 100644 --- a/src/tuplelist.h +++ b/src/tuplelist.h @@ -38,6 +38,9 @@ public: for(PyObject* p : list) _args[i++] = p; } + // TODO: poor performance + // List is allocated by pool128 while tuple is by pool64 + // ... Tuple(List&& other) noexcept : Tuple(other.size()){ for(int i=0; i<_size; i++) _args[i] = other[i]; other.clear(); diff --git a/src/vm.h b/src/vm.h index 38b3cc5a..d51040a0 100644 --- a/src/vm.h +++ b/src/vm.h @@ -689,7 +689,13 @@ inline PyObject* VM::_py_call(PyObject* callable, ArgsView args, ArgsView kwargs int i = 0; if(args.size() < fn.decl->args.size()){ - vm->TypeError(fmt("expected ", fn.decl->args.size(), " positional arguments, but got ", args.size())); + vm->TypeError(fmt( + "expected ", + fn.decl->args.size(), + " positional arguments, but got ", + args.size(), + " (", fn.decl->code->name, ')' + )); } // prepare args @@ -711,7 +717,7 @@ inline PyObject* VM::_py_call(PyObject* callable, ArgsView args, ArgsView kwargs break; } } - if(i < args.size()) TypeError("too many arguments"); + if(i < args.size()) TypeError(fmt("too many arguments", " (", fn.decl->code->name, ')')); } for(int i=0; iattr().try_get(__new__); PyObject* obj; if(new_f != nullptr){ - obj = call(new_f, std::move(args), kwargs, false); + // should not use std::move here, since we will reuse args in possible __init__ + obj = call(new_f, args, kwargs, false); + if(!isinstance(obj, OBJ_GET(Type, callable))) return obj; }else{ obj = heap.gcnew(OBJ_GET(Type, callable), {}); - PyObject* self; - PyObject* init_f = get_unbound_method(obj, __init__, &self, false); + } + PyObject* self; + PyObject* init_f = get_unbound_method(obj, __init__, &self, false); + if (self != _py_null) { args.extend_self(self); - if (self != _py_null) call(init_f, std::move(args), kwargs, false); + call(init_f, std::move(args), kwargs, false); } return obj; }