From: Michael D. Lowis Date: Mon, 10 Feb 2020 03:05:22 +0000 (-0500) Subject: added parsing of referenced modules X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=0d6accdf0323eee84e0b0162ebe8d7b81d27bb23;p=proto%2Fsclpl-rb.git added parsing of referenced modules --- 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()