Skip to content

Commit ed1b1c1

Browse files
authored
Merge branch 'master' into al/more-gc-stats
2 parents a8c4182 + f530e6d commit ed1b1c1

27 files changed

+968
-679
lines changed

ci/bootstrap-stanza.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ ${STANZA} compile-macros \
5454
compiler/reader-lang.stanza \
5555
-o bootstrap.macros
5656

57-
${STANZA} core/stanza.proj compiler/stanza.proj stz/driver -o stanzatemp -macros bootstrap.macros -flags BOOTSTRAP
57+
${STANZA} core/stanza.proj compiler/stanza.proj stz/driver -o stanzatemp -macros bootstrap.macros -flags BOOTSTRAP -build-from-source

ci/build-stanza-version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# like 1.23.45
88
#
99
# Use version 0.17.56 to compile 0.18.0
10-
0.18.45
10+
0.18.62

compiler/config.stanza

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ defn verify-installation () :
264264
catch (e:Exception) :
265265
;Could not retrieve version of the executable.
266266
val msg = "Stanza install directory is set to %_, \
267-
but the version of the Stanza executable could not verified. %_"
267+
but the version of the Stanza executable could not be verified. %_"
268268
throw $ Exception(msg % [STANZA-INSTALL-DIR, e])
269269

270270
;Check that the version string is well-formatted.

compiler/core-macros.stanza

+18-15
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ defsyntax core :
10611061
public defproduction id$
10621062
public defproduction ids!
10631063
defrule id! = (?x:#id)
1064+
fail-if id! = (?x:#symbol) : CSE(closest-info(), "Cannot use reserved keyword '%_' as an identifier." % [x])
10641065
fail-if id! = () : CSE(closest-info(), "Identifier expected here.")
10651066
defrule id$ = (?x:#id! (! _))
10661067
fail-if id$ = () : CSE(closest-info(), "Expected an identifier here.")
@@ -1297,12 +1298,17 @@ defsyntax core :
12971298

12981299
;Represents the entire defn header.
12991300
defproduction defnheader:DefnHeader
1300-
defrule defnheader = ((?args:#fnargbinding! ...) ?a2:#return-type?) :
1301+
defrule defnheader = ((#do? ?args:#fnargbinding! ...) ?a2:#return-type?) :
13011302
DefnHeader(closest-info(), to-tuple(args), a2)
13021303

1304+
;Represents an optional @do so that users can optionally
1305+
;omit the space.
1306+
defproduction do?: False
1307+
defrule do? = (@do) : false
1308+
defrule do? = () : false
1309+
13031310
;Error production
13041311
defproduction defnheader!:DefnHeader
1305-
fail-if defnheader! = ((@do _ ...)) : CSE(closest-info(), BAD-ARGLIST-MSG)
13061312
defrule defnheader! = (?x:#defnheader)
13071313
fail-if defnheader! = () : CSE(closest-info(), "Invalid syntax for function arguments.")
13081314

@@ -1332,12 +1338,11 @@ defsyntax core :
13321338

13331339
;Represents the entire defn header.
13341340
defproduction lsdefnheader:DefnHeader
1335-
defrule lsdefnheader = ((?args:#lsfnargbinding! ...) #->! ?a2:#ls-type!) :
1341+
defrule lsdefnheader = ((#do? ?args:#lsfnargbinding! ...) #->! ?a2:#ls-type!) :
13361342
DefnHeader(closest-info(), to-tuple(args), One(a2))
13371343

13381344
;Error production
13391345
defproduction lsdefnheader!:DefnHeader
1340-
fail-if lsdefnheader! = ((@do _ ...)) : CSE(closest-info(), BAD-ARGLIST-MSG)
13411346
defrule lsdefnheader! = (?x:#lsdefnheader)
13421347
fail-if lsdefnheader! = () : CSE(closest-info(), "Invalid syntax for function arguments.")
13431348

@@ -1363,13 +1368,11 @@ defsyntax core :
13631368
defrule arglist = ((?xs:#argbinding ...)) : [map(key, xs), map(value, xs)]
13641369

13651370
defproduction fnheader! : [List List ?]
1366-
fail-if fnheader! = ((@do _ ...)) :
1367-
CSE(closest-info(), BAD-ARGLIST-MSG)
1368-
defrule fnheader! = (?args:#arglist -> ?a2:#type!) :
1369-
val [xs, a1] = args
1371+
defrule fnheader! = ((#do? ?args:#argbinding ...) -> ?a2:#type!) :
1372+
val [xs, a1] = [map(key, args), map(value, args)]
13701373
[xs, a1, a2]
1371-
defrule fnheader! = (?args:#arglist) :
1372-
val [xs, a1] = args
1374+
defrule fnheader! = ((#do? ?args:#argbinding ...)) :
1375+
val [xs, a1] = [map(key, args), map(value, args)]
13731376
[xs, a1, `($none)]
13741377
fail-if fnheader! = () :
13751378
CSE(closest-info(), "Expected argument list here.")
@@ -1759,10 +1762,12 @@ defsyntax core :
17591762
defproduction in-bindings! : List<KeyValue>
17601763
defrule in-bindings! = ((?b0:#in-binding ?bn:#in-binding! ...)) : cons(b0, bn)
17611764
defrule in-bindings! = (?b:#in-binding!) : List(b)
1765+
1766+
defproduction operator-exp!
1767+
defrule operator-exp! = (:) : `core/do
1768+
defrule operator-exp! = (?f:#exp! #:!) : f
17621769

1763-
fail-if exp4 = (for #in-binding :) :
1764-
CSE(closest-info(), BAD-FOR-MSG)
1765-
defrule exp4 = (for ?bs:#in-bindings! ?f:#exp! #:! ?body:#exp!) :
1770+
defrule exp4 = (for ?bs:#in-bindings! ?f:#operator-exp! ?body:#exp!) :
17661771
val template = `(f(fn xs : body, ys))
17671772
parse-syntax[core / #exp](
17681773
fill-template(template, [
@@ -2936,6 +2941,4 @@ defsyntax core :
29362941

29372942

29382943
;============== Error Messages ============================
2939-
val BAD-ARGLIST-MSG = "Incorrect syntax for argument list. Did you forget to put a space between the function name and the argument list?"
29402944
val BAD-MATCH-MSG = "Incorrect syntax for match expression. Is there an extra space between match and the argument list?"
2941-
val BAD-FOR-MSG = "Missing operating function in for expression. Did you forget to put a do after the bindings?"

compiler/dl-ir.stanza

+37-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defpackage stz/dl-ir :
66
import stz/type-fargs
77
import stz/absolute-info
88
import stz/base-dir
9+
import stz/printing-utils
910

1011
;============================================================
1112
;======================== PackageIO =========================
@@ -31,16 +32,29 @@ defmethod hash (p : ImportedPackage) :
3132
defmethod equal? (p1 : ImportedPackage, p2 : ImportedPackage) :
3233
equal?(package-name(p1), package-name(p2))
3334

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.
3443
public defstruct PackageIO :
3544
package: Symbol
3645
imported-packages: Tuple<ImportedPackage> with: (updater => sub-imported-packages)
46+
forwarded-imports: Tuple<Symbol>
47+
direct-imports: Tuple<Symbol>
3748
imports: Tuple<Import> with: (updater => sub-imports)
3849
exports: Tuple<Export> with: (updater => sub-exports)
3950
documentation?:False|String with: (updater => sub-documentation)
4051

52+
;Subset of PackageIO which does not include 'Import' field.
4153
public defstruct PackageExports :
4254
package: Symbol
4355
imported-packages: Tuple<ImportedPackage>
56+
forwarded-imports: Tuple<Symbol>
57+
direct-imports: Tuple<Symbol>
4458
exports: Tuple<Export> with: (updater => sub-exports)
4559

4660
;============================================================
@@ -442,7 +456,7 @@ public defn match? (x:Rec, y:Rec, types-in-io:HashSet<TypeId>|False) -> True|Fal
442456
;============================================================
443457

444458
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))
446460

447461
public defn to-package-exports? (io:PackageIO|False) :
448462
match(io:PackageIO) :
@@ -567,10 +581,26 @@ defmethod print (o:OutputStream, x:Export) :
567581
lnprint(o2, "doc: %_" % [documentation?(x)])
568582

569583
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)])
574604

575605
defmethod print (o:OutputStream, x:PackageExports) :
576606
print(o, "package %~ :" % [package(x)])
@@ -603,7 +633,8 @@ defsyntax dl-ir :
603633
?imports:#import ...
604634
?exports:#export ...) :
605635
;[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)
607638

608639
defproduction dtype : DType
609640
defrule dtype = (byte) : DByte()

compiler/el-ir.stanza

+1-1
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ defsyntax el-ir :
10651065
defrule epackage = (package ?name:#symbol : (?ss:#tstmt ... #E)) :
10661066
val ins = to-tuple(filter-by<Import>(ss))
10671067
val exs = to-tuple(filter-by<Export>(ss))
1068-
val io = PackageIO(name, [], ins, exs, false)
1068+
val io = PackageIO(name, [], [], [], ins, exs, false)
10691069
val es = to-tuple(filter-by<ETExp>(ss))
10701070
EPackage(io, to-tuple(es))
10711071

compiler/el.stanza

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ defn collapse (epackages:Tuple<EPackage>) -> EPackage :
262262
for ex in exports(packageio(e)) seq :
263263
val n* = global-rec-ids[id(rec(ex))]
264264
sub-n(ex, n*)
265-
PackageIO(`prog, [], [], exports*, false)
265+
PackageIO(`prog, [], [], [], [], exports*, false)
266266

267267
;Rename one specific package
268268
defn renamed-exps (epackage:EPackage) :

compiler/front-end.stanza

+3-2
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,12 @@ defn FrontEnd (sys:FrontEndInputs) -> FrontEnd :
540540
val resolved = resolve-packages(package-names, errorlist)
541541
val new-inputs = HashTable<Symbol,PackageInFile>()
542542
for e in errorlist do :
543-
match(e:MissingType) :
543+
match(e:MissingType|MissingForwardedPackage) :
544544
match(source-file?(src-package(e))) :
545545
(file:String) : new-inputs[src-package(e)] = PackageInFile(src-package(e), file)
546546
(file:False) : throw(FrontEndErrors(errorlist))
547-
else : throw(FrontEndErrors(errorlist))
547+
else :
548+
throw(FrontEndErrors(errorlist))
548549
[resolved, to-tuple(values(new-inputs))]
549550

550551
defn resolve-packages! (package-names:Tuple<Symbol>) -> ResolverResult :

compiler/il-ir.stanza

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ defpackage stz/il-ir :
1010
;General Multis for IExp
1111
public defmulti info (e:IExp) -> False|AbsoluteFileInfo
1212

13+
;- imports: Corresponds one-to-one with the user's 'import' statements
14+
; nested under 'defpackage'.
15+
;- forwarded-imports: If package A imports B, and B forwards C,
16+
; then we say that C is imported into A via forwarding (assuming
17+
; that C is not already directly imported into A).
18+
; This field stores all packages that are imported via forwarding.
1319
public defstruct IPackage :
1420
name: Symbol
1521
documentation?: IDoc|False
1622
imports: Tuple<IImport> with: (updater => sub-imports)
23+
forwarded-imports: Tuple<Symbol> with: (updater => sub-forwarded-imports)
1724
exps: List<IExp> with: (updater => sub-exps)
1825
info: AbsoluteFileInfo|False
1926
namemap: NameMap with: (default => void, updater => sub-namemap)
@@ -63,9 +70,6 @@ with:
6370
IVisibility :
6471
exp: IExp
6572
visibility: Visibility
66-
ILoadPackage :
67-
filename: String
68-
pkg: ? ;TGPackage|KPackage
6973

7074
;=== Doc Form ===
7175
IDoc :
@@ -400,8 +404,6 @@ with:
400404
(v:Public) : "$public"
401405
(v:Protected) : "$protected"
402406
(v:Private) : "$private"}
403-
ILoadPackage :
404-
($loadpackage filename pkg)
405407

406408
IDoc :
407409
($doc string)
@@ -595,7 +597,6 @@ with:
595597
public defn name! (e:IExp) -> Symbol :
596598
match(e) :
597599
(e:IVar|LetPackage) : name(e)
598-
(e:ILoadPackage) : name(pkg(e))
599600
(e:IDefType) : name!(class(e))
600601
(e:IDefPackage|IDefChild|IDef|IDefVar|IDefn|IDefmulti|
601602
ISet|ICap|ILSField|ILSTagof|ILSLabeledBlock|

compiler/il-to-tl.stanza

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ defn to-imported-package (i:IImport) -> ImportedPackage :
169169
;The imported/exported entries will be populated
170170
;after type inference.
171171
defn to-packageio (ipackage:IPackage) -> PackageIO :
172+
val direct-imports = to-tuple(seq(package, imports(ipackage)))
172173
val imports = to-tuple(seq(to-imported-package, imports(ipackage)))
173174
val doc? = match(documentation?(ipackage)) :
174175
(d:IDoc) : value(string(d) as ILiteral) as String
175176
(f:False) : false
176-
PackageIO(name(ipackage), imports, [], [], doc?)
177+
PackageIO(name(ipackage), imports, forwarded-imports(ipackage), direct-imports, [], [], doc?)
177178

178179
;============================================================
179180
;=============== Conversion Functions =======================

compiler/input.stanza

+3-4
Original file line numberDiff line numberDiff line change
@@ -468,23 +468,23 @@ defn split-packages (e:IExp,
468468
val e = all-exps[i + 1] as IDefPackage
469469
val [exps, end] = package-exps(i + 2)
470470
val imports = to-tuple $ seq(to-iimport, imports(e) as List<IImportExp>)
471-
add(packages, IPackage(name!(e), doc, imports, exps, info(e)))
471+
add(packages, IPackage(name!(e), doc, imports, [], exps, info(e)))
472472
loop(end)
473473

474474
;Package without preceding IDoc form.
475475
DefPackageExp:
476476
val e = all-exps[i] as IDefPackage
477477
val [exps, end] = package-exps(i + 1)
478478
val imports = to-tuple $ seq(to-iimport, imports(e) as List<IImportExp>)
479-
add(packages, IPackage(name!(e), false, imports, exps, info(e)))
479+
add(packages, IPackage(name!(e), false, imports, [], exps, info(e)))
480480
loop(end)
481481

482482
;Default package.
483483
WithinPackageExp:
484484
val [exps, end] = package-exps(i)
485485
val info = info(head(exps)) when not empty?(exps)
486486
val name = gensym(`default)
487-
add(packages, IPackage(name, false, default-imports, exps, info))
487+
add(packages, IPackage(name, false, default-imports, [], exps, info))
488488
loop(end)
489489

490490
;Return packages
@@ -522,7 +522,6 @@ defn to-iimport (e:IImportExp) -> IImport :
522522
IDefPackage:
523523
{name:v imports:(imp ...)}
524524
custom{ensure-unique-imports(e)}
525-
ILoadPackage: ()
526525
IBegin: {exps:(pe ...)}
527526
+ te
528527

compiler/main.stanza

-1
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,6 @@ add-stanza-command(defs-db-command())
12101210
;============================================================
12111211

12121212
public defn stanza-main (commands:Collection<Command>, default-command:String|False) :
1213-
initialize-process-launcher()
12141213
set-max-heap-size(STANZA-MAX-COMPILER-HEAP-SIZE)
12151214
simple-command-line-cli(version-message(), to-tuple(commands), default-command, true)
12161215

compiler/params.stanza

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public defn compiler-flags () :
1818
to-tuple(COMPILE-FLAGS)
1919

2020
;========= Stanza Configuration ========
21-
public val STANZA-VERSION = [0 18 58]
21+
public val STANZA-VERSION = [0 18 67]
2222
public var STANZA-INSTALL-DIR:String = ""
2323
public var OUTPUT-PLATFORM:Symbol = `platform
2424
public var STANZA-PKG-DIRS:List<String> = List()

compiler/pkg-serializer.stanza

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ defserializer PkgSerializer (include-asm?:True|False) :
154154
deftype packageio (PackageIO) :
155155
package:symbol
156156
imported-packages:tuple(importedpackage)
157+
forwarded-imports:tuple(symbol)
158+
direct-imports:tuple(symbol)
157159
imports:tuple(dimport)
158160
exports:tuple(dexport)
159161
documentation?:opt(string)

compiler/repl.stanza

+1
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ defn REPLEnv () :
797797
IPackage(gensym(`repl),
798798
false,
799799
to-tuple(values(exp-imports)),
800+
[]
800801
List(wrap-display-result(exp)),
801802
info(exp))
802803

0 commit comments

Comments
 (0)