From cacc5a6e98178d224016c7ad297067f84d11ecf2 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 7 Jun 2021 12:05:14 -0400 Subject: [PATCH] fixed up code generation with new symbol table approach. --- cerise/inc/cerise.h | 1 + cerise/src/grammar.c | 1 - cerise/src/sym.c | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index 4e49ea8..4dc00c1 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -146,6 +146,7 @@ typedef struct { size_t msyms; size_t nsyms; Symbol* syms; + size_t scope; } Parser; // src/stdlib.c diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 181fe65..f062596 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -451,7 +451,6 @@ RULE(var_decl) export = accept(p, '*'); sym = symbol_new(p, 0, name, SYM_VAR, export); first = (nsyms == 0 ? sym : first); -// sym->global = (p->level <= 1 ? 1 : 0); nsyms++; } while (accept(p, ',')); diff --git a/cerise/src/sym.c b/cerise/src/sym.c index 4b4d87e..1a18752 100644 --- a/cerise/src/sym.c +++ b/cerise/src/sym.c @@ -74,6 +74,7 @@ Symbol* symbol_new(Parser* p, size_t scope, char* name, int class, bool export) p->syms[p->nsyms].name = name; p->syms[p->nsyms].class = class; p->syms[p->nsyms].export = export; + p->syms[p->nsyms].global = (p->scope == 1); p->nsyms++; return &(p->syms[p->nsyms-1]); @@ -98,11 +99,13 @@ Symbol* symbol_get(Parser* p, char* name, int class) size_t symbol_openscope(Parser* p) { + p->scope++; return p->nsyms; } void symbol_closescope(Parser* p, size_t scope) { + p->scope--; p->nsyms = scope; } -- 2.49.0