Skip to content

Commit 042f2b6

Browse files
committed
Touch-up loot notes.
1 parent b2777f7 commit 042f2b6

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

www/notes/loot.scrbl

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,19 +707,19 @@ Here's the function for emitting closure construction code:
707707

708708
@#reader scribble/comment-reader
709709
(racketblock
710-
;; (Listof Variable) Label Expr CEnv -> Asm
711-
(define (compile-λ xs f e0 c)
710+
;; (Listof Variable) Label (Listof Varialbe) CEnv -> Asm
711+
(define (compile-λ xs f ys c)
712712
`(;; Save label address
713713
(lea rax (offset ,f 0))
714714
(mov (offset rdi 0) rax)
715-
715+
716716
;; Save the environment
717717
(mov r8 ,(length ys))
718718
(mov (offset rdi 1) r8)
719719
(mov r9 rdi)
720720
(add r9 16)
721721
,@(copy-env-to-heap ys c 0)
722-
722+
723723
;; Return a pointer to the closure
724724
(mov rax rdi)
725725
(or rax ,type-proc)
@@ -903,8 +903,8 @@ handle the tasks listed above:
903903
;; (Listof Variable) (Listof Lambda) Expr CEnv -> Asm
904904
(define (compile-letrec fs ls e c)
905905
(let ((c0 (compile-letrec-λs ls c))
906-
(c1 (compile-letrec-init fs ls (append fs c)))
907-
(c2 (compile-e e (append fs c))))
906+
(c1 (compile-letrec-init fs ls (append (reverse fs) c)))
907+
(c2 (compile-e e (append (reverse fs) c))))
908908
`(,@c0
909909
,@c1
910910
,@c2)))
@@ -969,9 +969,24 @@ We can give a spin:
969969
#f
970970
(even? (sub1 x))))))
971971
(even? 10))))
972+
973+
(asm-interp
974+
(compile
975+
'(letrec ((map (λ (f ls)
976+
(letrec ((mapper (λ (ls)
977+
(if (empty? ls)
978+
'()
979+
(cons (f (car ls)) (mapper (cdr ls)))))))
980+
(mapper ls)))))
981+
(map (λ (f) (f 0))
982+
(cons (λ (x) (add1 x))
983+
(cons (λ (x) (sub1 x))
984+
'()))))))
972985
]
973986

974987

988+
989+
975990
@section[#:tag-prefix "loot"]{Syntactic sugar for function definitions}
976991

977992
The @racket[letrec] form is a generlization of the

0 commit comments

Comments
 (0)