This commit is contained in:
blueloveTH 2023-06-17 12:59:16 +08:00
parent a0545048bd
commit c889a33d51
3 changed files with 3 additions and 3 deletions

View File

@ -60,7 +60,6 @@ struct CodeObject {
List consts;
std::vector<StrName> varnames; // local variables
NameDictInt varnames_inv;
std::set<Str> global_names;
std::vector<CodeBlock> blocks = { CodeBlock(NO_BLOCK, -1, 0, 0) };
NameDictInt labels;
std::vector<FuncDecl_> func_decls;

View File

@ -422,7 +422,7 @@ class Compiler {
void exprName(){
Str name = prev().str();
NameScope scope = name_scope();
if(ctx()->co->global_names.count(name)){
if(ctx()->global_names.count(name)){
scope = NAME_GLOBAL;
}
ctx()->s_expr.push(make_expr<NameExpr>(name, scope));
@ -803,7 +803,7 @@ __SUBSCR_END:
case TK("global"):
do {
consume(TK("@id"));
ctx()->co->global_names.insert(prev().str());
ctx()->global_names.insert(prev().str());
} while (match(TK(",")));
consume_end_stmt();
break;

View File

@ -38,6 +38,7 @@ struct CodeEmitContext{
CodeObject_ co;
stack<Expr_> s_expr;
int level;
std::set<Str> global_names;
CodeEmitContext(VM* vm, CodeObject_ co, int level): vm(vm), co(co), level(level) {}
int curr_block_i = 0;