From 24f4680b1b982b177a28f61a9d8f1a55962c4df8 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 21 Oct 2024 23:39:11 -0400 Subject: [PATCH] fixed code generation of module bound symbols. still need to emit prototypes for imported symbols --- lib/codegen.rb | 11 +++++++++-- lib/sym_table.rb | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/codegen.rb b/lib/codegen.rb index 5c20513..5463556 100644 --- a/lib/codegen.rb +++ b/lib/codegen.rb @@ -239,7 +239,14 @@ class Codegen def lookup_func(func) if func.is_a? IR::Var then - value = @syms[func.name] + if func.module then + mod = @syms[func.module] + modsym = mod.type.exports[func.name] + value = SymTable::Symbol.new(func.module, func.name, nil, modsym[:kind], modsym[:type], nil) + else + value = @syms[func.name] + end + error func, "no such function: #{func.name}" if value.nil? else value = func @@ -276,7 +283,7 @@ class Codegen if @syms.builtin? sym.name "#{sym.name}" else - "#{@parser.module}_#{sym.name}" + "#{sym.module || @parser.module}_#{sym.name}" end end end diff --git a/lib/sym_table.rb b/lib/sym_table.rb index 7228edb..0ddcbe7 100644 --- a/lib/sym_table.rb +++ b/lib/sym_table.rb @@ -2,7 +2,7 @@ # Symbol Table Definition ## class SymTable - Symbol = Struct.new(:name, :loc, :kind, :type, :value) + Symbol = Struct.new(:module, :name, :loc, :kind, :type, :value) def initialize() @scopes = [{}, {}] @@ -49,12 +49,12 @@ class SymTable def add_builtin(name, kind, type, value) @scopes[0][name] = - Symbol.new(name, 0, kind, type, value) + Symbol.new(nil, name, 0, kind, type, value) end def add_sym(name, loc, kind, type, value) @scopes.last[name] = - Symbol.new(name, loc, kind, type, value) + Symbol.new(nil, name, loc, kind, type, value) end def each(&block) -- 2.54.0