Skip to content

Commit

Permalink
import modules with new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 26, 2023
1 parent 2447bdc commit 726f009
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions rivetc/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,30 @@ def import_modules(self):
def import_modules_from_decls(self, sf, decls):
for decl in decls:
if isinstance(decl, ast.ImportDecl):
mod = self.load_module_files(
decl.path, decl.alias, sf.file, decl.pos
)
if mod.found:
if mod_sym_ := self.universe.find(mod.full_name):
mod_sym = mod_sym_ # module already imported
else:
mod_sym = sym.Mod(False, mod.full_name)
self.universe.add(mod_sym)
self.parsed_files += parser.Parser(self).parse_mod(
mod_sym, mod.files
)
decl.alias = mod.alias
decl.mod_sym = mod_sym
self.import_module(sf, decl)
elif isinstance(decl, ast.ComptimeIf):
ct_decls = self.evalue_comptime_if(decl)
self.import_modules_from_decls(sf, ct_decls)

def import_module(self, sf, decl):
if len(decl.subimports) > 0:
for subimport in decl.subimports:
self.import_module(sf, subimport)
return
mod = self.load_module_files(
decl.path, decl.alias, sf.file, decl.pos
)
if mod.found:
if mod_sym_ := self.universe.find(mod.full_name):
mod_sym = mod_sym_ # module already imported
else:
mod_sym = sym.Mod(False, mod.full_name)
self.universe.add(mod_sym)
self.parsed_files += parser.Parser(self).parse_mod(
mod_sym, mod.files
)
decl.alias = mod.alias
decl.mod_sym = mod_sym

def resolve_deps(self):
g = self.import_graph()
Expand Down

0 comments on commit 726f009

Please sign in to comment.