From ca4039a52fb07b7d81152bbfa23ee7ca857fdf8f Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 11 Nov 2022 00:47:01 +0800 Subject: [PATCH] add global kw --- .gitignore | 1 - src/codeobject.h | 2 +- src/compiler.h | 4 ++++ src/parser.h | 2 +- src/pointer.h | 4 ---- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 45406b13..1c3dd7a8 100644 --- a/.gitignore +++ b/.gitignore @@ -153,7 +153,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ src/main -src/test gmon.out gprof.txt /pocketpy diff --git a/src/codeobject.h b/src/codeobject.h index d100656d..63fa9aa1 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -42,7 +42,7 @@ struct CodeObject { int addName(const _Str& name, NameScope scope){ auto p = std::make_shared(name, scope); for(int i=0; iname == p->name) return i; } co_names.push_back(p); return co_names.size() - 1; diff --git a/src/compiler.h b/src/compiler.h index 314b48dc..4f359d23 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -733,6 +733,10 @@ __LISTCOMP: EXPR(); emitCode(OP_DELETE_PTR); consumeEndStatement(); + } else if(match(TK("global"))){ + consume(TK("@id")); + int index = getCode()->addName(parser->previous.str(), NAME_GLOBAL); + consumeEndStatement(); } else if(match(TK("pass"))){ consumeEndStatement(); } else { diff --git a/src/parser.h b/src/parser.h index 5c149a81..130d8cb6 100644 --- a/src/parser.h +++ b/src/parser.h @@ -12,7 +12,7 @@ constexpr const char* __TOKENS[] = { "+=", "-=", "*=", "/=", "//=", /** KW_BEGIN **/ "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", /** KW_END **/ "is not", "not in", diff --git a/src/pointer.h b/src/pointer.h index 2d6b27da..8db647ba 100644 --- a/src/pointer.h +++ b/src/pointer.h @@ -24,10 +24,6 @@ struct NamePointer : BasePointer { PyVar get(VM* vm, Frame* frame) const; void set(VM* vm, Frame* frame, PyVar val) const; void del(VM* vm, Frame* frame) const; - - bool operator==(const NamePointer& other) const { - return name == other.name && scope == other.scope; - } }; struct AttrPointer : BasePointer {