mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
8da205f4f9
commit
d1080aab1f
@ -138,10 +138,13 @@ struct FuncDecl {
|
|||||||
Str docstring; // docstring of this function
|
Str docstring; // docstring of this function
|
||||||
bool is_simple;
|
bool is_simple;
|
||||||
|
|
||||||
int keyword_to_index(StrName key) const{
|
NameDictInt kw_to_index;
|
||||||
for(const KwArg& item: kwargs) if(item.key == key) return item.index;
|
|
||||||
return -1;
|
void add_kwarg(int index, StrName key, PyObject* value){
|
||||||
|
kw_to_index.set(key, index);
|
||||||
|
kwargs.push_back({index, key, value});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _gc_mark() const;
|
void _gc_mark() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1037,7 +1037,7 @@ __EAT_DOTS_END:
|
|||||||
if(value == nullptr){
|
if(value == nullptr){
|
||||||
SyntaxError(Str("default argument must be a literal"));
|
SyntaxError(Str("default argument must be a literal"));
|
||||||
}
|
}
|
||||||
decl->kwargs.push_back(FuncDecl::KwArg{index, name, value});
|
decl->add_kwarg(index, name, value);
|
||||||
} break;
|
} break;
|
||||||
case 3:
|
case 3:
|
||||||
decl->starred_kwarg = index;
|
decl->starred_kwarg = index;
|
||||||
|
@ -844,9 +844,9 @@ void VM::_prepare_py_call(PyObject** buffer, ArgsView args, ArgsView kwargs, con
|
|||||||
|
|
||||||
for(int j=0; j<kwargs.size(); j+=2){
|
for(int j=0; j<kwargs.size(); j+=2){
|
||||||
StrName key(CAST(int, kwargs[j]));
|
StrName key(CAST(int, kwargs[j]));
|
||||||
int index = decl->keyword_to_index(key);
|
int index = decl->kw_to_index.try_get_likely_found(key);
|
||||||
// if key is an explicit key, set as local variable
|
// if key is an explicit key, set as local variable
|
||||||
if(index != -1){
|
if(index >= 0){
|
||||||
buffer[index] = kwargs[j+1];
|
buffer[index] = kwargs[j+1];
|
||||||
}else{
|
}else{
|
||||||
// otherwise, set as **kwargs if possible
|
// otherwise, set as **kwargs if possible
|
||||||
|
Loading…
x
Reference in New Issue
Block a user