]> git.mdlowis.com Git - proto/obnc.git/commitdiff
fixed up code generation with new symbol table approach.
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 7 Jun 2021 16:05:14 +0000 (12:05 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 7 Jun 2021 16:05:14 +0000 (12:05 -0400)
cerise/inc/cerise.h
cerise/src/grammar.c
cerise/src/sym.c

index 4e49ea83f1313d66f4c54802f6173459f8131efc..4dc00c1d6a2b498b4c726164130b749e4b96d869 100644 (file)
@@ -146,6 +146,7 @@ typedef struct {
     size_t msyms;
     size_t nsyms;
     Symbol* syms;
+    size_t scope;
 } Parser;
 
 // src/stdlib.c
index 181fe6540cea500099e19f87f0780f56d2440a6a..f0625969ad78e9fac88d8751ad5200433820d637 100644 (file)
@@ -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, ','));
index 4b4d87ee6605a6c20909bb032162653f6e019da3..1a18752c296dc6c6c01d0aea55ee1e271ad22330 100644 (file)
@@ -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;
 }