Skip to content

Commit ee838f1

Browse files
committed
Fix ommission of match in literals.
1 parent 52b039c commit ee838f1

6 files changed

Lines changed: 39 additions & 1 deletion

File tree

langs/mountebank/ast.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
;; | (PBox Pat)
5151
;; | (PCons Pat Pat)
5252
;; | (PAnd Pat Pat)
53+
;; | (PSymb Symbol)
5354
;; type Lit = Boolean
5455
;; | Character
5556
;; | Integer
@@ -75,3 +76,4 @@
7576
(struct PBox (p) #:prefab)
7677
(struct PCons (p1 p2) #:prefab)
7778
(struct PAnd (p1 p2) #:prefab)
79+
(struct PSymb (s) #:prefab)

langs/mountebank/compile-literals.rkt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@
7979
(append (literals-e e1) (append-map literals-e es))]
8080
[(Lam f xs e)
8181
(literals-e e)]
82+
[(Match e ps es)
83+
(append (literals-e e) (append-map literals-match-clause ps es))]
84+
[_ '()]))
85+
86+
;; Pat Expr -> [Listof Symbol]
87+
(define (literals-match-clause p e)
88+
(append (literals-pat p) (literals-e e)))
89+
90+
;; Pat -> [Listof Symbol]
91+
(define (literals-pat p)
92+
(match p
93+
[(PSymb s) (list s)]
94+
[(PBox p) (literals-pat p)]
95+
[(PCons p1 p2) (append (literals-pat p1) (literals-pat p2))]
96+
[(PAnd p1 p2) (append (literals-pat p1) (literals-pat p2))]
8297
[_ '()]))
8398

8499
;; Datum -> [Listof (U Symbol String)]

langs/mountebank/test/test-runner.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@
308308
(check-equal? (run '(string? (symbol->string 'foo))) #t)
309309
(check-equal? (run '(eq? (symbol->string 'foo) "foo")) #f)
310310
(check-equal? (run ''foo) 'foo)
311+
(check-equal? (run '(eq? (match #t [_ "foo"]) "bar")) #f)
312+
(check-equal? (run '(eq? (match #t [_ 'foo]) 'bar)) #f)
311313

312314
;; Mountebank examples
313315
(check-equal? (run '#())

langs/mug/ast.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
;; | (PBox Pat)
4848
;; | (PCons Pat Pat)
4949
;; | (PAnd Pat Pat)
50+
;; | (PSymb Symbol)
5051
;; type Lit = Boolean
5152
;; | Character
5253
;; | Integer
@@ -77,3 +78,4 @@
7778
(struct PBox (p) #:prefab)
7879
(struct PCons (p1 p2) #:prefab)
7980
(struct PAnd (p1 p2) #:prefab)
81+
(struct PSymb (s) #:prefab)

langs/mug/compile-literals.rkt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
(append (literals-e e1) (append-map literals-e es))]
8181
[(Lam f xs e)
8282
(literals-e e)]
83+
[(Match e ps es)
84+
(append (literals-e e) (append-map literals-match-clause ps es))]
8385
[_ '()]))
8486

8587
;; [Listof Char] -> Asm
@@ -89,3 +91,16 @@
8991
[(cons c cs)
9092
(seq (Dd (char->integer c))
9193
(compile-string-chars cs))]))
94+
95+
;; Pat Expr -> [Listof Symbol]
96+
(define (literals-match-clause p e)
97+
(append (literals-pat p) (literals-e e)))
98+
99+
;; Pat -> [Listof Symbol]
100+
(define (literals-pat p)
101+
(match p
102+
[(PSymb s) (list s)]
103+
[(PBox p) (literals-pat p)]
104+
[(PCons p1 p2) (append (literals-pat p1) (literals-pat p2))]
105+
[(PAnd p1 p2) (append (literals-pat p1) (literals-pat p2))]
106+
[_ '()]))

langs/mug/test/test-runner.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@
307307
(check-equal? (run '(eq? (symbol->string 'foo) (symbol->string 'foo))) #f)
308308
(check-equal? (run '(string? (symbol->string 'foo))) #t)
309309
(check-equal? (run '(eq? (symbol->string 'foo) "foo")) #f)
310-
(check-equal? (run ''foo) 'foo))
310+
(check-equal? (run ''foo) 'foo)
311+
(check-equal? (run '(eq? (match #t [_ "foo"]) "bar")) #f)
312+
(check-equal? (run '(eq? (match #t [_ 'foo]) 'bar)) #f))
311313

312314
(define (test-runner-io run)
313315
;; Evildoer examples

0 commit comments

Comments
 (0)