From: Michael D. Lowis Date: Fri, 2 Dec 2022 21:08:04 +0000 (-0500) Subject: added symbol copying for imports X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c0fb70352a74637eb2fa2e5df2b9b4f14dc4c294;p=proto%2Fobnc.git added symbol copying for imports --- diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 56870ab..33f7c05 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -714,6 +714,7 @@ static void init_parser(Parser* p, char* path) static void import(Parser* curr, char* modname, char* alias) { + /* parse the module */ Parser p = {0}; char* path = fs_modfind(curr, modname); if (!path) @@ -724,17 +725,18 @@ static void import(Parser* curr, char* modname, char* alias) module(&p); (void)alias; -// Symbol* sym = symbol_new(p, 0, modname, SYM_MODULE, 0); -// size_t modid = sym - &p->syms[0]; -// -// for (size_t i = 0; i < p.nsyms; i++) -// { -// if (p.syms[i].export) -// { -//// printf("sym: %s\n", p.syms[i].name); -//// (void)alias; -// } -// } + /* copy exported symbols to our symbol table */ + Symbol* sym = symbol_new(curr, 0, modname, SYM_MODULE, 0); + size_t modid = sym - &curr->syms[0]; + printf("%lu\n", modid); + for (size_t i = 0; i < p.nsyms; i++) + { + if (p.syms[i].export) + { + Symbol* sym = symbol_new(curr, 0, p.syms[i].name, p.syms[i].class, 0); + sym->module = modid; + } + } } void compile(char* path) diff --git a/cerise/tests/Module.m b/cerise/tests/Module.m index a24ea43..b491d90 100644 --- a/cerise/tests/Module.m +++ b/cerise/tests/Module.m @@ -1,4 +1,5 @@ -import A +import + A const FOO* = 42