refactor LIST_APPEND

This commit is contained in:
blueloveTH 2023-02-20 10:47:41 +08:00
parent 52df3a2f67
commit 24c2563315
2 changed files with 3 additions and 10 deletions

View File

@ -86,10 +86,9 @@ PyVar VM::run_frame(Frame* frame){
} continue; } continue;
case OP_LOAD_EVAL_FN: frame->push(builtins->attr(m_eval)); continue; case OP_LOAD_EVAL_FN: frame->push(builtins->attr(m_eval)); continue;
case OP_LIST_APPEND: { case OP_LIST_APPEND: {
pkpy::Args args(2); PyVar obj = frame->pop_value(this);
args[1] = frame->pop_value(this); // obj pkpy::List& list = PyList_AS_C(frame->top_1());
args[0] = frame->top_value_offset(this, -2); // list list.push_back(std::move(obj));
fast_call(m_append, std::move(args));
} continue; } continue;
case OP_BUILD_CLASS: { case OP_BUILD_CLASS: {
const Str& clsName = frame->co->names[byte.arg].first; const Str& clsName = frame->co->names[byte.arg].first;

View File

@ -89,12 +89,6 @@ struct Frame {
return _data[_data.size()-2]; return _data[_data.size()-2];
} }
inline PyVar top_value_offset(VM* vm, int n){
PyVar value = _data[_data.size() + n];
try_deref(vm, value);
return value;
}
template<typename T> template<typename T>
inline void push(T&& obj){ _data.push_back(std::forward<T>(obj)); } inline void push(T&& obj){ _data.push_back(std::forward<T>(obj)); }