mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-10 13:40:16 +00:00
some optimize
This commit is contained in:
parent
f813d815eb
commit
4c14460961
@ -364,9 +364,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Type _tp(PyObject* obj){
|
Type _tp(PyObject* obj){
|
||||||
|
if(!is_tagged(obj)) return obj->type;
|
||||||
if(is_int(obj)) return tp_int;
|
if(is_int(obj)) return tp_int;
|
||||||
if(is_float(obj)) return tp_float;
|
return tp_float;
|
||||||
return obj->type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* _t(PyObject* obj){
|
PyObject* _t(PyObject* obj){
|
||||||
|
|||||||
38
src/vm.cpp
38
src/vm.cpp
@ -882,25 +882,6 @@ PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
|
|||||||
PyObject** _base = args.begin();
|
PyObject** _base = args.begin();
|
||||||
PyObject* buffer[PK_MAX_CO_VARNAMES];
|
PyObject* buffer[PK_MAX_CO_VARNAMES];
|
||||||
|
|
||||||
if(callable_t == tp_native_func){
|
|
||||||
const auto& f = PK_OBJ_GET(NativeFunc, callable);
|
|
||||||
PyObject* ret;
|
|
||||||
if(f.decl != nullptr){
|
|
||||||
int co_nlocals = f.decl->code->varnames.size();
|
|
||||||
_prepare_py_call(buffer, args, kwargs, f.decl);
|
|
||||||
// copy buffer back to stack
|
|
||||||
s_data.reset(_base + co_nlocals);
|
|
||||||
for(int j=0; j<co_nlocals; j++) _base[j] = buffer[j];
|
|
||||||
ret = f.call(vm, ArgsView(s_data._sp - co_nlocals, s_data._sp));
|
|
||||||
}else{
|
|
||||||
if(KWARGC != 0) TypeError("old-style native_func does not accept keyword arguments");
|
|
||||||
f.check_size(this, args);
|
|
||||||
ret = f.call(this, args);
|
|
||||||
}
|
|
||||||
s_data.reset(p0);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(callable_t == tp_function){
|
if(callable_t == tp_function){
|
||||||
/*****************_py_call*****************/
|
/*****************_py_call*****************/
|
||||||
// callable must be a `function` object
|
// callable must be a `function` object
|
||||||
@ -949,6 +930,25 @@ __FAST_CALL:
|
|||||||
/*****************_py_call*****************/
|
/*****************_py_call*****************/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(callable_t == tp_native_func){
|
||||||
|
const auto& f = PK_OBJ_GET(NativeFunc, callable);
|
||||||
|
PyObject* ret;
|
||||||
|
if(f.decl != nullptr){
|
||||||
|
int co_nlocals = f.decl->code->varnames.size();
|
||||||
|
_prepare_py_call(buffer, args, kwargs, f.decl);
|
||||||
|
// copy buffer back to stack
|
||||||
|
s_data.reset(_base + co_nlocals);
|
||||||
|
for(int j=0; j<co_nlocals; j++) _base[j] = buffer[j];
|
||||||
|
ret = f.call(vm, ArgsView(s_data._sp - co_nlocals, s_data._sp));
|
||||||
|
}else{
|
||||||
|
if(KWARGC != 0) TypeError("old-style native_func does not accept keyword arguments");
|
||||||
|
f.check_size(this, args);
|
||||||
|
ret = f.call(this, args);
|
||||||
|
}
|
||||||
|
s_data.reset(p0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if(callable_t == tp_type){
|
if(callable_t == tp_type){
|
||||||
// [type, NULL, args..., kwargs...]
|
// [type, NULL, args..., kwargs...]
|
||||||
PyObject* new_f = find_name_in_mro(PK_OBJ_GET(Type, callable), __new__);
|
PyObject* new_f = find_name_in_mro(PK_OBJ_GET(Type, callable), __new__);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user