]> git.mdlowis.com Git - proto/obnc.git/commitdiff
cleaned up module entries in the symbol file
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 19 Jul 2021 02:07:31 +0000 (22:07 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 19 Jul 2021 02:07:31 +0000 (22:07 -0400)
cerise/src/sym.c

index df1beddbaec213fd3b2437b1e0c28435a6b88220..41b986cf3a1419381de14c87a9458b7df4ddde51 100644 (file)
@@ -169,6 +169,7 @@ static const char SymTypes[5] = {
 
 static size_t typeid(Parser* p, Type* type)
 {
+    if (type == NULL) return -1;
     size_t i;
     for (i = 0; i < p->ntypes; i++)
     {
@@ -179,6 +180,17 @@ static size_t typeid(Parser* p, Type* type)
     return i;
 }
 
+static char* modname(Parser* p, Symbol* sym)
+{
+    char* name = p->name;
+    if (sym->module > 0)
+    {
+        sym = symbol_getbyid(p, sym->module);
+        name = sym->name;
+    }
+    return name;
+}
+
 void symbol_export(Parser* p, char* path)
 {
     (void)path;
@@ -191,9 +203,26 @@ void symbol_export(Parser* p, char* path)
     {
         Symbol* sym = &(p->syms[i]);
         if (!sym->export) continue;
-        printf("%c %s ", SymTypes[sym->class], sym->name);
-        fflush(stdout);
-        printf("%ld\n", typeid(p, sym->type));
+        if (sym->class == SYM_MODULE && sym->module != 0) continue;
+
+        printf("%c %s %s ",
+            SymTypes[sym->class],
+            modname(p, sym),
+            sym->name);
+
+        switch (sym->class)
+        {
+            case SYM_MODULE:
+                printf("<signature>\n");
+                break;
+
+            case SYM_CONST:
+            case SYM_VAR:
+            case SYM_TYPE:
+            case SYM_PROC:
+                printf("%ld\n", typeid(p, sym->type));
+                break;
+        }
     }
 }
 
@@ -202,18 +231,18 @@ void symbol_export(Parser* p, char* path)
 
 void symbol_import(Parser* p, char* name, char* alias)
 {
-    Symbol* mod = symbol_new(p, 0, name, SYM_MODULE, false);
+    Symbol* mod = symbol_new(p, 0, name, SYM_MODULE, true);
     size_t modid = symbol_getid(p, 0, mod->name, SYM_MODULE);
     if (alias)
     {
-        Symbol* modalias = symbol_new(p, 0, alias, SYM_MODULE, false);
+        Symbol* modalias = symbol_new(p, 0, alias, SYM_MODULE, true);
         modalias->module = modid; // Points to the aliased module
     }
 
     /* TODO: read symbols from real symbol file */
     // All of these should set ->module = modid
 
-    Symbol* sym = symbol_new(p, 0, "testint", SYM_CONST, false);
+    Symbol* sym = symbol_new(p, 0, "testint", SYM_CONST, true);
     sym->module = modid;
     sym->value = ast_int(42);
 }