some optimize

This commit is contained in:
blueloveTH 2024-03-16 17:22:00 +08:00
parent 93b7904353
commit 21c906ab33
4 changed files with 9 additions and 6 deletions

View File

@ -90,8 +90,8 @@ struct Frame {
NameDict& f_globals() noexcept { return _module->attr(); }
PyObject* f_closure_try_get(StrName name);
Frame(PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable)
: _ip(-1), _next_ip(0), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, p0) { }
Frame(PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable, PyObject** _locals_base)
: _ip(-1), _next_ip(0), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, _locals_base) { }
Frame(PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable, FastLocals _locals)
: _ip(-1), _next_ip(0), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { }
@ -150,6 +150,9 @@ struct CallStack{
}
void pop(){
#if PK_DEBUG_EXTRA_CHECK
if(empty()) PK_FATAL_ERROR();
#endif
LinkedFrame* p = _tail;
_tail = p->f_back;
pool64_dealloc(p);

View File

@ -67,7 +67,7 @@ PyObject* VM::_run_top_frame(){
__NEXT_FRAME:
// cache
const CodeObject* co = frame->co;
const auto& co_consts = co->consts;
PyObject** co_consts = const_cast<PyObject**>(co->consts.data());
const Bytecode* co_codes = co->codes.data();
Bytecode byte = co_codes[frame->next_bytecode()];

View File

@ -55,7 +55,7 @@ void LineProfiler::_step_end(LinkedFrame* linked_frame, int line){
}else if(linked_frame->f_back == top_frame_record.frame){
id_delta = 1;
}else{
id_delta = -1;
id_delta = -1; // unsafe
}
// current line is about to change

View File

@ -930,7 +930,7 @@ PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
if(co->is_generator){
s_data.reset(p0);
return _py_generator(
Frame(nullptr, co, fn._module, callable),
Frame(nullptr, co, fn._module, callable, nullptr),
ArgsView(buffer, buffer + co_nlocals)
);
}
@ -940,7 +940,7 @@ PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
for(int j=0; j<co_nlocals; j++) _base[j] = buffer[j];
__FAST_CALL:
callstack.emplace(p0, co, fn._module, callable, FastLocals(co, args.begin()));
callstack.emplace(p0, co, fn._module, callable, args.begin());
if(op_call) return PY_OP_CALL;
return _run_top_frame();
/*****************_py_call*****************/