Skip to content

Commit da768ad

Browse files
committed
Add missing match code to interp.
1 parent bedbbe4 commit da768ad

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

langs/neerdowell/interp-defun.rkt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,24 @@
111111
[(PAnd p1 p2)
112112
(match (interp-match-pat p1 v r)
113113
[#f #f]
114-
[r1 (interp-match-pat p2 v r1)])]))
114+
[r1 (interp-match-pat p2 v r1)])]
115+
[(PStruct t ps)
116+
(match v
117+
[(StructVal n vs)
118+
(and (eq? t n)
119+
(interp-match-pats ps (vector->list vs) r))]
120+
[_ #f])]))
121+
122+
;; [Listof Pat] [Listof Val] Env -> [Maybe Env]
123+
(define (interp-match-pats ps vs r)
124+
(match ps
125+
['() r]
126+
[(cons p ps)
127+
(match vs
128+
[(cons v vs)
129+
(match (interp-match-pat p v r)
130+
[#f #f]
131+
[r1 (interp-match-pats ps vs r1)])])]))
115132

116133
;; Id Env [Listof Defn] -> Answer
117134
(define (interp-var x r ds)

langs/neerdowell/interp-prims.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#lang racket
22
(require "ast.rkt")
3-
(provide interp-prim)
3+
(provide interp-prim StructVal)
44

55
;; type Struct = (StructVal Symbol (Vectorof Value))
66
(struct StructVal (name vals))

langs/neerdowell/interp.rkt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,24 @@
108108
[(PAnd p1 p2)
109109
(match (interp-match-pat p1 v r)
110110
[#f #f]
111-
[r1 (interp-match-pat p2 v r1)])]))
111+
[r1 (interp-match-pat p2 v r1)])]
112+
[(PStruct t ps)
113+
(match v
114+
[(StructVal n vs)
115+
(and (eq? t n)
116+
(interp-match-pats ps (vector->list vs) r))]
117+
[_ #f])]))
118+
119+
;; [Listof Pat] [Listof Val] Env -> [Maybe Env]
120+
(define (interp-match-pats ps vs r)
121+
(match ps
122+
['() r]
123+
[(cons p ps)
124+
(match vs
125+
[(cons v vs)
126+
(match (interp-match-pat p v r)
127+
[#f #f]
128+
[r1 (interp-match-pats ps vs r1)])])]))
112129

113130
;; Id Env [Listof Defn] -> Answer
114131
(define (interp-var x r ds)

0 commit comments

Comments
 (0)