mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
a484879b14
commit
d0453ab15f
37
src/ceval.h
37
src/ceval.h
@ -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();
|
||||||
|
28
src/expr.h
28
src/expr.h
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user