Skip to content

Commit 33d32f0

Browse files
committed
Forgot to pushed closed spec.
1 parent 7812cb5 commit 33d32f0

5 files changed

Lines changed: 47 additions & 2 deletions

File tree

langs/neerdowell/ast.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
;; | (PAnd Pat Pat)
5656
;; | (PSymb Symbol)
5757
;; | (PStr String)
58+
;; | (PStruct Id (Listof Pat))
5859
;; type Lit = Boolean
5960
;; | Character
6061
;; | Integer

langs/neerdowell/compile-expr.rkt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,42 @@
310310
(Label fail)
311311
(Add rsp (* 8 (length cm))) ; haven't pushed anything yet
312312
(Jmp next))
313-
cm2))])])]))
313+
cm2))])])]
314+
[(PStruct n ps)
315+
(match (compile-struct-patterns ps (cons #f cm) next 1)
316+
[(list i f cm)
317+
(let ((fail (gensym)))
318+
(list
319+
(seq (Mov r8 rax)
320+
(And r8 ptr-mask)
321+
(Cmp r8 type-struct)
322+
(Jne fail)
323+
(Xor rax type-struct)
324+
(Mov r8 (Offset rax 0))
325+
(Lea r9 (Plus (symbol->data-label n) type-symb))
326+
(Cmp r8 r9)
327+
(Jne fail)
328+
(Push rax)
329+
i)
330+
(seq f
331+
(Label fail)
332+
(Add rsp (* 8 (length cm)))
333+
(Jmp next))
334+
cm))])]))
335+
336+
;; [Listof Pat] CEnv Symbol Nat -> (list Asm Asm CEnv)
337+
(define (compile-struct-patterns ps cm next i)
338+
(match ps
339+
['() (list '() '() cm)]
340+
[(cons p ps)
341+
(match (compile-pattern p cm next)
342+
[(list i1 f1 cm1)
343+
(match (compile-struct-patterns ps cm1 next (add1 i))
344+
[(list is fs cmn)
345+
(list
346+
(seq (Mov rax (Offset rax (* 8 i)))
347+
i1
348+
(Mov rax (Offset rsp (* 8 (sub1 (length cm1)))))
349+
is)
350+
(seq f1 fs)
351+
cmn)])])]))

langs/neerdowell/fv.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
[(PCons p1 p2) (append (bv-pat* p1) (bv-pat* p2))]
3131
[(PAnd p1 p2) (append (bv-pat* p1) (bv-pat* p2))]
3232
[(PBox p) (bv-pat* p)]
33+
[(PStruct n ps) (append-map bv-pat* ps)]
3334
[_ '()]))

langs/neerdowell/parse.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@
126126
(PLit '())]
127127
[(cons 'list (cons p1 ps))
128128
(PCons (parse-pat p1)
129-
(parse-pat (cons 'list ps)))]))
129+
(parse-pat (cons 'list ps)))]
130+
[(cons (? symbol? n) ps)
131+
(PStruct n (map parse-pat ps))]))
130132

131133
(define (self-quoting? x)
132134
(or (integer? x)

www/assignments/6.scrbl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Here are the properties that should be checked of each program:
5050

5151
@itemlist[
5252

53+
@item{Programs are @emph{closed}; there are no unbound variables in
54+
the program.}
55+
5356
@item{Every @racket[define]d function should have a distinct name.}
5457

5558
@item{Every function parameter should be distinct from the other

0 commit comments

Comments
 (0)