mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
9cc0c4a504
commit
63b0a592bd
@ -130,33 +130,15 @@ struct FuncDecl {
|
|||||||
CodeObject_ code; // code object of this function
|
CodeObject_ code; // code object of this function
|
||||||
std::vector<int> args; // indices in co->varnames
|
std::vector<int> args; // indices in co->varnames
|
||||||
std::vector<KwArg> kwargs; // indices in co->varnames
|
std::vector<KwArg> kwargs; // indices in co->varnames
|
||||||
int starred_arg; // index in co->varnames, -1 if no *arg
|
int starred_arg = -1; // index in co->varnames, -1 if no *arg
|
||||||
int starred_kwarg; // index in co->varnames, -1 if no **kwarg
|
int starred_kwarg = -1; // index in co->varnames, -1 if no **kwarg
|
||||||
bool nested; // whether this function is nested
|
bool nested = false; // whether this function is nested
|
||||||
|
|
||||||
static const int MAX_K2I_CACHE = 16;
|
|
||||||
|
|
||||||
int _keyword_to_index[MAX_K2I_CACHE]; // map from `kwargs[i].key` to `kwargs[i].index`
|
|
||||||
|
|
||||||
Str signature; // signature of this function
|
Str signature; // signature of this function
|
||||||
Str docstring; // docstring of this function
|
Str docstring; // docstring of this function
|
||||||
bool is_simple;
|
bool is_simple;
|
||||||
|
|
||||||
FuncDecl(){
|
|
||||||
starred_arg = -1;
|
|
||||||
starred_kwarg = -1;
|
|
||||||
nested = false;
|
|
||||||
for(int i=0; i<MAX_K2I_CACHE; i++) _keyword_to_index[i] = -1;
|
|
||||||
is_simple = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_kwarg_item(int index, StrName key, PyObject* value){
|
|
||||||
kwargs.push_back(KwArg{index, key, value});
|
|
||||||
if(key.index < MAX_K2I_CACHE) _keyword_to_index[key.index] = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
int keyword_to_index(StrName key) const{
|
int keyword_to_index(StrName key) const{
|
||||||
if(key.index < MAX_K2I_CACHE) return _keyword_to_index[key.index];
|
|
||||||
for(const KwArg& item: kwargs) if(item.key == key) return item.index;
|
for(const KwArg& item: kwargs) if(item.key == key) return item.index;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -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->add_kwarg_item(index, name, value);
|
decl->kwargs.push_back(FuncDecl::KwArg{index, name, value});
|
||||||
} break;
|
} break;
|
||||||
case 3:
|
case 3:
|
||||||
decl->starred_kwarg = index;
|
decl->starred_kwarg = index;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user