This commit is contained in:
blueloveTH 2023-06-10 12:33:12 +08:00
parent a484879b14
commit d0453ab15f
2 changed files with 40 additions and 25 deletions

View File

@ -470,19 +470,30 @@ __NEXT_STEP:;
PUSH(_0); PUSH(_0);
DISPATCH(); DISPATCH();
TARGET(CALL_TP) TARGET(CALL_TP)
// [callable, <self>, args: tuple, kwargs: dict] // [callable, <self>, args: tuple, kwargs: dict | NULL]
_2 = POPX(); if(byte.arg){
_1 = POPX(); _2 = POPX();
for(PyObject* obj: _CAST(Tuple&, _1)) PUSH(obj); _1 = POPX();
_CAST(Dict&, _2).apply([this](PyObject* k, PyObject* v){ for(PyObject* obj: _CAST(Tuple&, _1)) PUSH(obj);
PUSH(VAR(StrName(CAST(Str&, k)).index)); _CAST(Dict&, _2).apply([this](PyObject* k, PyObject* v){
PUSH(v); PUSH(VAR(StrName(CAST(Str&, k)).index));
}); PUSH(v);
_0 = vectorcall( });
_CAST(Tuple&, _1).size(), // ARGC _0 = vectorcall(
_CAST(Dict&, _2).size(), // KWARGC _CAST(Tuple&, _1).size(), // ARGC
true _CAST(Dict&, _2).size(), // KWARGC
); true
);
}else{
// no **kwargs
_1 = POPX();
for(PyObject* obj: _CAST(Tuple&, _1)) PUSH(obj);
_0 = vectorcall(
_CAST(Tuple&, _1).size(), // ARGC
0, // KWARGC
true
);
}
if(_0 == PY_OP_CALL) DISPATCH_OP_CALL(); if(_0 == PY_OP_CALL) DISPATCH_OP_CALL();
PUSH(_0); PUSH(_0);
DISPATCH(); DISPATCH();

View File

@ -686,20 +686,24 @@ struct CallExpr: Expr{
for(auto& item: args) item->emit(ctx); for(auto& item: args) item->emit(ctx);
ctx->emit(OP_BUILD_TUPLE_UNPACK, (int)args.size(), line); ctx->emit(OP_BUILD_TUPLE_UNPACK, (int)args.size(), line);
for(auto& item: kwargs){ if(!kwargs.empty()){
if(item.second->is_starred()){ for(auto& item: kwargs){
if(item.second->star_level() != 2) FATAL_ERROR(); if(item.second->is_starred()){
item.second->emit(ctx); if(item.second->star_level() != 2) FATAL_ERROR();
}else{ item.second->emit(ctx);
// k=v }else{
int index = ctx->add_const(py_var(ctx->vm, item.first)); // k=v
ctx->emit(OP_LOAD_CONST, index, line); int index = ctx->add_const(py_var(ctx->vm, item.first));
item.second->emit(ctx); ctx->emit(OP_LOAD_CONST, index, line);
ctx->emit(OP_BUILD_TUPLE, 2, line); item.second->emit(ctx);
ctx->emit(OP_BUILD_TUPLE, 2, line);
}
} }
ctx->emit(OP_BUILD_DICT_UNPACK, (int)kwargs.size(), line);
ctx->emit(OP_CALL_TP, 1, line);
}else{
ctx->emit(OP_CALL_TP, 0, line);
} }
ctx->emit(OP_BUILD_DICT_UNPACK, (int)kwargs.size(), line);
ctx->emit(OP_CALL_TP, BC_NOARG, line);
}else{ }else{
// vectorcall protocal // vectorcall protocal
for(auto& item: args) item->emit(ctx); for(auto& item: args) item->emit(ctx);