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; List consts;
std::vector<StrName> varnames; // local variables std::vector<StrName> varnames; // local variables
NameDictInt varnames_inv; NameDictInt varnames_inv;
std::set<Str> global_names;
std::vector<CodeBlock> blocks = { CodeBlock(NO_BLOCK, -1, 0, 0) }; std::vector<CodeBlock> blocks = { CodeBlock(NO_BLOCK, -1, 0, 0) };
NameDictInt labels; NameDictInt labels;
std::vector<FuncDecl_> func_decls; std::vector<FuncDecl_> func_decls;

View File

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

View File

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