@@ -6,6 +6,7 @@ defpackage stz/dl-ir :
6
6
import stz/type-fargs
7
7
import stz/absolute-info
8
8
import stz/base-dir
9
+ import stz/printing-utils
9
10
10
11
;============================================================
11
12
;======================== PackageIO =========================
@@ -31,16 +32,29 @@ defmethod hash (p : ImportedPackage) :
31
32
defmethod equal? (p1 : ImportedPackage, p2 : ImportedPackage) :
32
33
equal?(package-name(p1), package-name(p2))
33
34
35
+ ;- forwarded-imports: If package A imports B, and B forwards C,
36
+ ; then we say that C is imported into A via forwarding (assuming
37
+ ; that C is not already directly imported into A).
38
+ ; This field stores all packages that are imported via forwarding.
39
+ ;- direct-imports: These are the packages that are explicitly imported
40
+ ; by the user via an import statement. This is a subset of the
41
+ ; 'imported-packages' field in that it does not include the packages
42
+ ; that are implicitly imported due to type signatures.
34
43
public defstruct PackageIO :
35
44
package: Symbol
36
45
imported-packages: Tuple<ImportedPackage> with: (updater => sub-imported-packages)
46
+ forwarded-imports: Tuple<Symbol>
47
+ direct-imports: Tuple<Symbol>
37
48
imports: Tuple<Import> with: (updater => sub-imports)
38
49
exports: Tuple<Export> with: (updater => sub-exports)
39
50
documentation?:False|String with: (updater => sub-documentation)
40
51
52
+ ;Subset of PackageIO which does not include 'Import' field.
41
53
public defstruct PackageExports :
42
54
package: Symbol
43
55
imported-packages: Tuple<ImportedPackage>
56
+ forwarded-imports: Tuple<Symbol>
57
+ direct-imports: Tuple<Symbol>
44
58
exports: Tuple<Export> with: (updater => sub-exports)
45
59
46
60
;============================================================
@@ -442,7 +456,7 @@ public defn match? (x:Rec, y:Rec, types-in-io:HashSet<TypeId>|False) -> True|Fal
442
456
;============================================================
443
457
444
458
public defn to-package-exports (io:PackageIO) :
445
- PackageExports(package(io), imported-packages(io), exports(io))
459
+ PackageExports(package(io), imported-packages(io), forwarded-imports(io), direct-imports(io), exports(io))
446
460
447
461
public defn to-package-exports? (io:PackageIO|False) :
448
462
match(io:PackageIO) :
@@ -567,10 +581,26 @@ defmethod print (o:OutputStream, x:Export) :
567
581
lnprint(o2, "doc: %_" % [documentation?(x)])
568
582
569
583
defmethod print (o:OutputStream, x:PackageIO) :
570
- print(o, "package %~ :" % [package(x)])
571
- val o2 = IndentedStream(o)
572
- lnprint(o2, "imported-packages = (%@)" % [imported-packages(x)])
573
- lnprints(o2, cat(imports(x), exports(x)))
584
+ val items = [
585
+ falseable-field("documentation", documentation?(x))
586
+ named-list-fields("imported-packages", imported-packages(x))
587
+ line-wrapped-field("forwarded-imports", forwarded-imports(x))
588
+ line-wrapped-field("direct-imports", direct-imports(x))
589
+ inline-fields(imports(x))
590
+ inline-fields(exports(x))]
591
+ print(o, "package %~ %_" % [package(x), colon-field-list(items)])
592
+
593
+ defmethod print (o:OutputStream, x:ImportedPackage) :
594
+ val items = [
595
+ simple-field("forward", forward(x))
596
+ falseable-field("only", only(x))
597
+ inline-fields(prefix(x))]
598
+ print(o, "import package %~ %_" % [package-name(x), colon-field-list(items)])
599
+
600
+ defmethod print (o:OutputStream, x:ImportPrefix) :
601
+ match(names(x)) :
602
+ (names:Tuple<Symbol>) : print(o, "prefix(%,) => %~" % [names, prefix(x)])
603
+ (f:False) : print(o, "prefix => %~" % [prefix(x)])
574
604
575
605
defmethod print (o:OutputStream, x:PackageExports) :
576
606
print(o, "package %~ :" % [package(x)])
@@ -603,7 +633,8 @@ defsyntax dl-ir :
603
633
?imports:#import ...
604
634
?exports:#export ...) :
605
635
;[TODO] Add doc string reader macro. Defaulted to false for now.
606
- PackageIO(name, to-tuple(map({ImportedPackage(_)}, ips)), to-tuple(imports), to-tuple(exports), false)
636
+ ;[TODO]: is the empty direct-import list OK?
637
+ PackageIO(name, to-tuple(map({ImportedPackage(_)}, ips)), [], [], to-tuple(imports), to-tuple(exports), false)
607
638
608
639
defproduction dtype : DType
609
640
defrule dtype = (byte) : DByte()
0 commit comments