mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
add global kw
This commit is contained in:
parent
ff4776f756
commit
ca4039a52f
1
.gitignore
vendored
1
.gitignore
vendored
@ -153,7 +153,6 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
src/main
|
src/main
|
||||||
src/test
|
|
||||||
gmon.out
|
gmon.out
|
||||||
gprof.txt
|
gprof.txt
|
||||||
/pocketpy
|
/pocketpy
|
||||||
|
@ -42,7 +42,7 @@ struct CodeObject {
|
|||||||
int addName(const _Str& name, NameScope scope){
|
int addName(const _Str& name, NameScope scope){
|
||||||
auto p = std::make_shared<NamePointer>(name, scope);
|
auto p = std::make_shared<NamePointer>(name, scope);
|
||||||
for(int i=0; i<co_names.size(); i++){
|
for(int i=0; i<co_names.size(); i++){
|
||||||
if(*co_names[i] == *p) return i;
|
if(co_names[i]->name == p->name) return i;
|
||||||
}
|
}
|
||||||
co_names.push_back(p);
|
co_names.push_back(p);
|
||||||
return co_names.size() - 1;
|
return co_names.size() - 1;
|
||||||
|
@ -733,6 +733,10 @@ __LISTCOMP:
|
|||||||
EXPR();
|
EXPR();
|
||||||
emitCode(OP_DELETE_PTR);
|
emitCode(OP_DELETE_PTR);
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
|
} else if(match(TK("global"))){
|
||||||
|
consume(TK("@id"));
|
||||||
|
int index = getCode()->addName(parser->previous.str(), NAME_GLOBAL);
|
||||||
|
consumeEndStatement();
|
||||||
} else if(match(TK("pass"))){
|
} else if(match(TK("pass"))){
|
||||||
consumeEndStatement();
|
consumeEndStatement();
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,7 +12,7 @@ constexpr const char* __TOKENS[] = {
|
|||||||
"+=", "-=", "*=", "/=", "//=",
|
"+=", "-=", "*=", "/=", "//=",
|
||||||
/** KW_BEGIN **/
|
/** KW_BEGIN **/
|
||||||
"class", "import", "as", "def", "lambda", "pass", "del",
|
"class", "import", "as", "def", "lambda", "pass", "del",
|
||||||
"None", "in", "is", "and", "or", "not", "True", "False",
|
"None", "in", "is", "and", "or", "not", "True", "False", "global",
|
||||||
"while", "for", "if", "elif", "else", "break", "continue", "return", "assert", "raise",
|
"while", "for", "if", "elif", "else", "break", "continue", "return", "assert", "raise",
|
||||||
/** KW_END **/
|
/** KW_END **/
|
||||||
"is not", "not in",
|
"is not", "not in",
|
||||||
|
@ -24,10 +24,6 @@ struct NamePointer : BasePointer {
|
|||||||
PyVar get(VM* vm, Frame* frame) const;
|
PyVar get(VM* vm, Frame* frame) const;
|
||||||
void set(VM* vm, Frame* frame, PyVar val) const;
|
void set(VM* vm, Frame* frame, PyVar val) const;
|
||||||
void del(VM* vm, Frame* frame) const;
|
void del(VM* vm, Frame* frame) const;
|
||||||
|
|
||||||
bool operator==(const NamePointer& other) const {
|
|
||||||
return name == other.name && scope == other.scope;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AttrPointer : BasePointer {
|
struct AttrPointer : BasePointer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user