]> git.mdlowis.com Git - proto/obnc.git/commitdiff
started writing rudimentary symbol export logic
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 15 Jul 2021 20:36:35 +0000 (16:36 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 15 Jul 2021 20:36:35 +0000 (16:36 -0400)
cerise/inc/cerise.h
cerise/src/grammar.c
cerise/src/sym.c
cerise/tests/Module.m

index 1ec2c56f53aba43aa57b444bc521dd510daa87bd..0b656567ae5c56ab7f8d258577df9e981f952140 100644 (file)
@@ -165,6 +165,7 @@ Symbol* symbol_getbyid(Parser* p, size_t id);
 size_t symbol_openscope(Parser* p);
 void symbol_closescope(Parser* p, size_t scope);
 void symbol_import(Parser* p, char* name, char* alias);
+void symbol_export(Parser* p, char* path);
 
 // src/type_checks.c
 void check_int(Parser* p, AstNode* a);
index 305318b3fa7e7b7e24c13aa14b4a6ab21f14a55d..071fee523daf93060f905bd2547a6f9a0b7ce817 100644 (file)
@@ -626,6 +626,7 @@ static void module(Parser* p)
         error(p, "expected end of file");
     }
 
+    symbol_export(p, NULL);
     symbol_closescope(p, scope);
     EXIT_RULE();
 }
index daa55f2d83a489246afb778af1fadb17aca1413a..d3b110e340b77a270986611e81cc4b8b7e0c5190 100644 (file)
@@ -144,6 +144,32 @@ void symbol_import(Parser* p, char* name, char* alias)
     sym->value = ast_int(42);
 }
 
+/* Symbol File Generation
+ *****************************************************************************/
+
+static const char SymTypes[5] = {
+    [SYM_MODULE] = 'M',
+    [SYM_CONST]  = 'C',
+    [SYM_VAR]    = 'V',
+    [SYM_TYPE]   = 'T',
+    [SYM_PROC]   = 'P',
+};
+
+void symbol_export(Parser* p, char* path)
+{
+    (void)path;
+    for (size_t i = 0; i < p->nsyms; i++)
+    {
+        Symbol* sym = &(p->syms[i]);
+        if (!sym->export) continue;
+        printf("%c %s\n", SymTypes[sym->class], sym->name);
+    }
+}
+
+/* Symbol File Parsing
+ *****************************************************************************/
+/* TODO: write logic to parse symbol file */
+
 /* Symbol Table Unit Tests
  *****************************************************************************/
 #ifdef CERISE_TESTS
index c12e223bd9cbf29ab712cc9b1a373894ab7c45a6..dd92fb44f1273ba20fb6853cc7415f5ffe06d8c6 100644 (file)
@@ -5,9 +5,9 @@ import
   Bar3 = Bar2
 
 const
-  A = true
-  B = 42
-  C = 42.0
+  A* = true
+  B* = 42
+  C* = 42.0
   D = -B
   E = -C
   F = not A
@@ -15,25 +15,25 @@ const
   H = false or A
 
 type
-  TypeA = Int
-  TypeB = array 5*B of Int
-  TypeC = array 5 of array 10 of Int
-  TypeD = record
+  TypeA* = Int
+  TypeB* = array 5*B of Int
+  TypeC* = array 5 of array 10 of Int
+  TypeD* = record
     x,y : Int
     label : array 10 of Int
     dim : record
       w,h : Int
     end
   end
-  TypeE = record
+  TypeE* = record
     i : Int
     a : array 5 of Int
   end
-  TypeF = array 5 of TypeE
+  TypeF* = array 5 of TypeE
 
 var
-  a : Bool
-  b : Int
+  a* : Bool
+  b* : Int
   c : Int
   d : Real
   e : array 5 of array 10 of Int
@@ -54,12 +54,12 @@ var
 #  return z1;
 #end
 
-procedure Bar(a : Int) : Int
+procedure Bar*(a : Int) : Int
 begin
     return a;
 end
 
-procedure Baz(a : Int)
+procedure Baz*(a : Int)
 begin
     if (1 > 2) then
         42;