Skip to content

Commit 81d6a1b

Browse files
committed
Merge branch 'fix-macros'
2 parents b1eb79b + b550066 commit 81d6a1b

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

compiler/core-macros.stanza

+17-15
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,17 @@ defsyntax core :
12971297

12981298
;Represents the entire defn header.
12991299
defproduction defnheader:DefnHeader
1300-
defrule defnheader = ((?args:#fnargbinding! ...) ?a2:#return-type?) :
1300+
defrule defnheader = ((#do? ?args:#fnargbinding! ...) ?a2:#return-type?) :
13011301
DefnHeader(closest-info(), to-tuple(args), a2)
13021302

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

@@ -1332,12 +1337,11 @@ defsyntax core :
13321337

13331338
;Represents the entire defn header.
13341339
defproduction lsdefnheader:DefnHeader
1335-
defrule lsdefnheader = ((?args:#lsfnargbinding! ...) #->! ?a2:#ls-type!) :
1340+
defrule lsdefnheader = ((#do? ?args:#lsfnargbinding! ...) #->! ?a2:#ls-type!) :
13361341
DefnHeader(closest-info(), to-tuple(args), One(a2))
13371342

13381343
;Error production
13391344
defproduction lsdefnheader!:DefnHeader
1340-
fail-if lsdefnheader! = ((@do _ ...)) : CSE(closest-info(), BAD-ARGLIST-MSG)
13411345
defrule lsdefnheader! = (?x:#lsdefnheader)
13421346
fail-if lsdefnheader! = () : CSE(closest-info(), "Invalid syntax for function arguments.")
13431347

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

13651369
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
1370+
defrule fnheader! = ((#do? ?args:#argbinding ...) -> ?a2:#type!) :
1371+
val [xs, a1] = [map(key, args), map(value, args)]
13701372
[xs, a1, a2]
1371-
defrule fnheader! = (?args:#arglist) :
1372-
val [xs, a1] = args
1373+
defrule fnheader! = ((#do? ?args:#argbinding ...)) :
1374+
val [xs, a1] = [map(key, args), map(value, args)]
13731375
[xs, a1, `($none)]
13741376
fail-if fnheader! = () :
13751377
CSE(closest-info(), "Expected argument list here.")
@@ -1759,10 +1761,12 @@ defsyntax core :
17591761
defproduction in-bindings! : List<KeyValue>
17601762
defrule in-bindings! = ((?b0:#in-binding ?bn:#in-binding! ...)) : cons(b0, bn)
17611763
defrule in-bindings! = (?b:#in-binding!) : List(b)
1764+
1765+
defproduction operator-exp!
1766+
defrule operator-exp! = (:) : `core/do
1767+
defrule operator-exp! = (?f:#exp! #:!) : f
17621768

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!) :
1769+
defrule exp4 = (for ?bs:#in-bindings! ?f:#operator-exp! ?body:#exp!) :
17661770
val template = `(f(fn xs : body, ys))
17671771
parse-syntax[core / #exp](
17681772
fill-template(template, [
@@ -2936,6 +2940,4 @@ defsyntax core :
29362940

29372941

29382942
;============== 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?"
29402943
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/il-ir.stanza

-6
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ with:
7070
IVisibility :
7171
exp: IExp
7272
visibility: Visibility
73-
ILoadPackage :
74-
filename: String
75-
pkg: ? ;TGPackage|KPackage
7673

7774
;=== Doc Form ===
7875
IDoc :
@@ -407,8 +404,6 @@ with:
407404
(v:Public) : "$public"
408405
(v:Protected) : "$protected"
409406
(v:Private) : "$private"}
410-
ILoadPackage :
411-
($loadpackage filename pkg)
412407

413408
IDoc :
414409
($doc string)
@@ -602,7 +597,6 @@ with:
602597
public defn name! (e:IExp) -> Symbol :
603598
match(e) :
604599
(e:IVar|LetPackage) : name(e)
605-
(e:ILoadPackage) : name(pkg(e))
606600
(e:IDefType) : name!(class(e))
607601
(e:IDefPackage|IDefChild|IDef|IDefVar|IDefn|IDefmulti|
608602
ISet|ICap|ILSField|ILSTagof|ILSLabeledBlock|

compiler/input.stanza

-1
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)