Skip to content

Commit 07b2f20

Browse files
committed
Make empty list a literal instead of disjoint AST node.
1 parent bd62c1b commit 07b2f20

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

ziggy/src/ast.rkt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#lang crook
2-
{:= A B C D0 D0.A D1 E0 E1 F H0 H1 I J K L}
2+
{:= A B C D0 D0.A D1 E0 E1 F F.A H0 H1 I J K L}
33
(provide {:> A} Lit {:> E0} Prim0 {:> B} Prim1 {:> F} Prim2 {:> H1} Prim3
4-
{:> C D0} IfZero {:> D0} If {:> E0} Eof {:> E0} Begin {:> F} Let
5-
{:> F} Var {:> H0} Empty {:> I} Prog {:> I} Defn {:> I} App
4+
{:> C D0} IfZero {:> D0} If {:> E0} Eof {:> E0} Begin
5+
{:> F} Let {:> F} Var {:> I} Prog {:> I} Defn {:> I} App
6+
{:> F.A H} Cond {:> F.A H} Case
67
{:> K} Match {:> K} Box {:> K} Cons {:> K} Conj {:> L} Lam)
78

89
{:> I} ;; type Prog = (Prog (Listof Defn) Expr)
@@ -14,7 +15,6 @@
1415
{:> A D0} ;; type Expr = (Lit Integer)
1516
{:> D0} ;; type Expr = (Lit Datum)
1617
{:> E0} ;; | (Eof)
17-
{:> H0} ;; | (Empty)
1818
{:> E0} ;; | (Prim0 Op0)
1919
{:> B} ;; | (Prim1 Op1 Expr)
2020
{:> F} ;; | (Prim2 Op2 Expr Expr)
@@ -23,10 +23,18 @@
2323
{:> D0} ;; | (If Expr Expr Expr)
2424
{:> D0.A D1}
2525
;; | (Cond [Listof CondClause] Expr)
26+
{:> F.A H0}
27+
;; | (Cond [Listof CondClause] Expr)
2628
{:> D0.A D1}
2729
;; | (Case Expr [Listof CaseClause] Expr)
30+
{:> F.A H0}
31+
;; | (Case Expr [Listof CaseClause] Expr)
2832
{:> E0} ;; | (Begin Expr Expr)
29-
{:> F} ;; | (Let Id Expr Expr)
33+
{:> F F.A}
34+
;; | (Let Id Expr Expr)
35+
{:> F.A H0}
36+
;; | (Let (Listof Id) (Listof Expr) Expr)
37+
{:> H0} ;; | (Let Id Expr Expr)
3038
{:> F} ;; | (Var Id)
3139
{:> I L} ;; | (App Id (Listof Expr))
3240
{:> L} ;; | (App Expr (Listof Expr))
@@ -37,6 +45,10 @@
3745
;; type CondClause = (Clause Expr Expr)
3846
{:> D0.A D1}
3947
;; type CaseClause = (Clause [Listof Datum] Expr)
48+
{:> F.A H0}
49+
;; type CondClause = (Clause Expr Expr)
50+
{:> F.A H0}
51+
;; type CaseClause = (Clause [Listof Datum] Expr)
4052

4153
{:> F} ;; type Id = Symbol
4254
{:> D0} ;; type Datum = Integer
@@ -66,7 +78,6 @@
6678
{:> K} ;; | (Conj Pat Pat)
6779

6880
{:> E0} (struct Eof () #:prefab)
69-
{:> H0} (struct Empty () #:prefab)
7081
{:> A D0} (struct Lit (i) #:prefab)
7182
{:> D0} (struct Lit (d) #:prefab)
7283
{:> E0} (struct Prim0 (p) #:prefab)
@@ -77,6 +88,8 @@
7788
{:> D0} (struct If (e1 e2 e3) #:prefab)
7889
{:> E0} (struct Begin (e1 e2) #:prefab)
7990
{:> F} (struct Let (x e1 e2) #:prefab)
91+
{:> F.A H} (struct Cond (cs es el) #:prefab)
92+
{:> F.A H} (struct Case (e ds es el) #:prefab)
8093
{:> F} (struct Var (x) #:prefab)
8194
{:> I} (struct App (f es) #:prefab)
8295
{:> L} (struct Lam (f xs e) #:prefab)

ziggy/src/compile.rkt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@
157157
[(Lit d) (compile-value d)]
158158
{:> E0}
159159
[(Eof) (compile-value eof)]
160-
{:> H0}
161-
[(Empty) (compile-value '())]
162160
{:> F}
163161
[(Var x) (compile-variable x c)]
164162
{:> E0}

ziggy/src/interp.rkt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@
8484
(match e
8585
[(Lit d) d]
8686
[(Eof) eof]
87-
{:> H0}
88-
[(Empty) '()]
8987
{:> F L}
9088
[(Var x) (lookup r x)]
9189
{:> L}

ziggy/src/parse.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{:> F}
1717
[(? symbol?) (Var s)]
1818
{:> H0}
19-
[(list 'quote (list)) (Empty)]
19+
[(list 'quote (list)) (Lit '())]
2020
{:> E0}
2121
[(list (? op0? o)) (Prim0 o)]
2222
{:> B}
@@ -66,7 +66,7 @@
6666
[(? datum?) (Lit s)]
6767
['eof (Eof)]
6868
[(? symbol?) (Var s)]
69-
[(list 'quote (list)) (Empty)]
69+
[(list 'quote (list)) (Lit '())]
7070
[(list (? op0? p0)) (Prim0 p0)]
7171
[(list (? op1? p1) e) (Prim1 p1 (parse-e e))]
7272
[(list (? op2? p2) e1 e2) (Prim2 p2 (parse-e e1) (parse-e e2))]

0 commit comments

Comments
 (0)