From: Michael D. Lowis Date: Thu, 15 Jul 2021 20:36:35 +0000 (-0400) Subject: started writing rudimentary symbol export logic X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=fc14877a5a777424dbfcb6506a0d54e25513d991;p=proto%2Fobnc.git started writing rudimentary symbol export logic --- diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index 1ec2c56..0b65656 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -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); diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 305318b..071fee5 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -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(); } diff --git a/cerise/src/sym.c b/cerise/src/sym.c index daa55f2..d3b110e 100644 --- a/cerise/src/sym.c +++ b/cerise/src/sym.c @@ -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 diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index c12e223..dd92fb4 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -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;