]> git.mdlowis.com Git - proto/cerise-c.git/commitdiff
fixed code generation of module bound symbols. still need to emit prototypes for...
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 22 Oct 2024 03:39:11 +0000 (23:39 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 22 Oct 2024 03:39:11 +0000 (23:39 -0400)
lib/codegen.rb
lib/sym_table.rb

index 5c205133cab46d89f28698284ca641ff461a0bec..5463556639dca11d582620541218101f1d332a63 100644 (file)
@@ -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
index 7228edb5a3ea795b32f920e1d10c49ad03d13442..0ddcbe7a80be62e6499f0e4bb0411d4febe69e6e 100644 (file)
@@ -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)