mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix a bug
This commit is contained in:
parent
c01a77d4b4
commit
294877f4e5
@ -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")
|
@ -105,6 +105,10 @@ struct PyObject{
|
||||
_attr->~NameDict();
|
||||
pool64.dealloc(_attr);
|
||||
}
|
||||
|
||||
void enable_instance_dict(float lf=kInstAttrLoadFactor) noexcept {
|
||||
_attr = new(pool64.alloc<NameDict>()) NameDict(lf);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -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();
|
||||
|
22
src/vm.h
22
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; i<kwargs.size(); i+=2){
|
||||
@ -756,13 +762,17 @@ inline PyObject* VM::call(PyObject* callable, Args args, const Args& kwargs, boo
|
||||
PyObject* new_f = callable->attr().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<DummyInstance>(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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user