]> git.mdlowis.com Git - proto/obnc.git/commitdiff
new symbol table functioning
authormike lowis <mike@mdlowis.com>
Sat, 5 Jun 2021 02:42:45 +0000 (22:42 -0400)
committermike lowis <mike@mdlowis.com>
Sat, 5 Jun 2021 02:42:45 +0000 (22:42 -0400)
cerise/src/grammar.c
cerise/src/sym.c
cerise/tests/Module.m

index 4c3357aabb511700494acb0e22a816461030e1b7..50f5fecdf6b94cfd4e176b9e50c4950ef4126801 100644 (file)
         static void name(Parser* p, Item* item)
 #endif
 
-/* Default Symbol List
- *****************************************************************************/
-static Symbol BoolSym = {
-    .class = SYM_TYPE,
-    .name  = "Bool",
-    .type  = &BoolType
-};
-
-static Symbol IntSym = {
-    .next  = &BoolSym,
-    .class = SYM_TYPE,
-    .name  = "Int",
-    .type  = &IntType
-};
-
-static Symbol RealSym = {
-    .next  = &IntSym,
-    .class = SYM_TYPE,
-    .name  = "Real",
-    .type  = &RealType
-};
-
 /* Item Handling
  *****************************************************************************/
 static void init_item(Item* item, Symbol* sym)
@@ -473,7 +451,7 @@ 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);
+//            sym->global = (p->level <= 1 ? 1 : 0);
             nsyms++;
         }
         while (accept(p, ','));
@@ -712,7 +690,7 @@ void compile(char* fname)
     char* fcontents = file_load(fname);
     Parser* p = &(Parser){
         .name  = NULL,
-        .scope = &RealSym,
+//        .scope = &RealSym,
         .file  = &(LexFile){
             .path  = fname,
             .fbeg  = fcontents,
@@ -720,6 +698,12 @@ void compile(char* fname)
         },
         .curr_reg = 0
     };
+
+    symbol_new(p, 0, "Bool",   SYM_TYPE, 0)->type = &BoolType;
+    symbol_new(p, 0, "Int",    SYM_TYPE, 0)->type = &IntType;
+    symbol_new(p, 0, "Real",   SYM_TYPE, 0)->type = &RealType;
+    symbol_new(p, 0, "String", SYM_TYPE, 0)->type = &StringType;
+
     codegen_startmod(p);
     module(p, &(Item){0});
     codegen_main(p);
@@ -733,16 +717,13 @@ void compile(char* fname)
 
 Parser Ctx = {0};
 
-static Symbol InitialScope = {
-    .next  = &RealSym,
-    .class = SYM_SCOPE,
-};
-
 static void parse_init(char* fname, char* string)
 {
     memset(&Ctx, 0, sizeof(Ctx));
-    Ctx.scope = &InitialScope;
-    InitialScope.desc = NULL;
+    symbol_new(&Ctx, 0, "Bool",   SYM_TYPE, 0)->type = &BoolType;
+    symbol_new(&Ctx, 0, "Int",    SYM_TYPE, 0)->type = &IntType;
+    symbol_new(&Ctx, 0, "Real",   SYM_TYPE, 0)->type = &RealType;
+    symbol_new(&Ctx, 0, "String", SYM_TYPE, 0)->type = &StringType;
     LexFile* file = calloc(sizeof(LexFile), 1u);
     file->path = strdup(fname);
     file->fbeg = file->fpos = strdup(string);
index 2f83d71437014186b5d4433da2c984c9d60c2434..05c66f380dbf16074cb24d6b1b003da4f2ad2259 100644 (file)
@@ -4,6 +4,7 @@
 
 static int sym_matches(Parser* p, int class, char* name, Symbol* sym)
 {
+//    printf("%s == %s\n", name, sym->name);
     if (name && sym->name && !strcmp(sym->name, name))
     {
         if (class >= 0 && (int)sym->class != class)
@@ -82,7 +83,7 @@ Symbol* symbol_get(Parser* p, char* name, int class)
     Symbol* sym = NULL;
     size_t index = lookup(p, 0, name, class);
 
-    if (NIL_SYMBOL != index)
+    if (NIL_SYMBOL == index)
     {
         error(p, "unknown symbol '%s'", name);
     }
index e23d994a0386b5af72f2c0aaebaa5ac701ea3b29..162b7ebafdeb17310702e7031e0fe0f4d47c6e4f 100644 (file)
@@ -19,6 +19,11 @@ type
       w,h : Int
     end
   end
+  TypeE = record
+    i : Int
+    a : array 5 of Int
+  end
+  TypeF = array 5 of TypeE
 
 var
   a : Bool
@@ -28,6 +33,7 @@ var
   e : array 5 of array 10 of Int
   f : TypeD
   g : array 5 of Int
+  h : TypeF
 
 procedure Foo*(e : Int, z : Int, q1 : TypeD, q2 : array 5 of Int) : Int
   const FOO = 2
@@ -43,6 +49,9 @@ begin
 end
 
 begin
+
+    h[1].i = 42;
+
 #  a = true;
 #  a = A;
 #  b = 24;
@@ -117,7 +126,10 @@ begin
 #  f.dim.h = 0;
 #  f.label[0] = 42;
 
-    c = 4;
-    g[c] = 42;
+#    c = 4;
+#    g[c] = 42;
 #    e[0][9] = 42;
+
+
+
 end