From 0d6accdf0323eee84e0b0162ebe8d7b81d27bb23 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 9 Feb 2020 22:05:22 -0500 Subject: [PATCH] added parsing of referenced modules --- compile.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/compile.rb b/compile.rb index 2380530..3cde1ed 100755 --- a/compile.rb +++ b/compile.rb @@ -54,6 +54,8 @@ BuiltinSyms = { }, } +Modules = {} + class Symtable def initialize @builtins = BuiltinSyms @@ -204,7 +206,7 @@ class Parser @imports end - def definitions() + def definitions(api_only = false) while !matches(:eof) sym = { export: accept("$"), @@ -220,6 +222,9 @@ class Parser else error("invalid symbol definition") end + if api_only && sym[:export] then + sym[:value] = nil + end @symbols[sym[:name]] = sym end @symbols @@ -563,21 +568,26 @@ class Parser end class Package - def initialize(path) + attr_accessor :name, :definitions + + def initialize(path, api_only = false) @name = nil @imports = {} @declares = {} @definitions = {} - add_file(path) + add_file(path, api_only) type_check end - def add_file(path) + def add_file(path, api_only = false) parse = Parser.new(path) @name = parse.module() @imports = parse.imports() -p @imports - @definitions = parse.definitions() + @imports.each do |m| + pkg = Package.new("lib/#{m.downcase}.m", api_only = true) + Modules[pkg.name] = pkg.definitions() + end + @definitions = parse.definitions(api_only) end def dump @@ -593,4 +603,5 @@ p @imports end pkg = Package.new("lib/main.m") +#pp Modules #pkg.dump() -- 2.52.0