File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed
Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff 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
977992The @racket[letrec ] form is a generlization of the
You can’t perform that action at this time.
0 commit comments