projects
/
scheme.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tidy up
[scheme.git]
/
codegen.scm
diff --git
a/codegen.scm
b/codegen.scm
index 941dc158e89e61a4a30027b00641f942a80da0ef..7a12fc2228795b588cfbf117d3f1e7712f282be6 100644
(file)
--- a/
codegen.scm
+++ b/
codegen.scm
@@
-167,16
+167,16
@@
(emit "## storing captives")
; store the captured vars
(for-each
(emit "## storing captives")
; store the captured vars
(for-each
- (lambda (var-name
new
-offset)
- (let ([
orig
-offset (cdr (assoc var-name env))])
+ (lambda (var-name
heap
-offset)
+ (let ([
stack
-offset (cdr (assoc var-name env))])
(emit "### captive ~a" var-name)
(emit "### captive ~a" var-name)
- (if (eqv?
orig
-offset 'self-captive)
+ (if (eqv?
stack
-offset 'self-captive)
; captive refers to this closure:
; move heap addr of this closure to stack!
; captive refers to this closure:
; move heap addr of this closure to stack!
- (emit "movq %rax, ~a(%rax)"
new
-offset)
+ (emit "movq %rax, ~a(%rax)"
heap
-offset)
(begin
(begin
- (emit "movq ~a(%rbp), %rbx"
orig
-offset)
- (emit "movq %rbx, ~a(%rax)"
new
-offset)))))
+ (emit "movq ~a(%rbp), %rbx"
stack
-offset)
+ (emit "movq %rbx, ~a(%rax)"
heap
-offset)))))
captured
heap-offsets)))
captured
heap-offsets)))
@@
-240,7
+240,7
@@
(params (append captives args))
(stack-offsets (map (lambda (i)
(params (append captives args))
(stack-offsets (map (lambda (i)
- (* (- wordsize)
i
))
+ (* (- wordsize)
(+ 1 i)
))
(range 0 (length params))))
(env (map cons params stack-offsets)))
(range 0 (length params))))
(env (map cons params stack-offsets)))
@@
-259,7
+259,6
@@
(emit "push %rbp") ; preserve caller's base pointer
(emit "movq %rsp, %rbp") ; set up our own base pointer
(emit "push %rbp") ; preserve caller's base pointer
(emit "movq %rsp, %rbp") ; set up our own base pointer
- (emit "subq $8, %rbp")
; load the captured vars onto the stack
(for-each
; load the captured vars onto the stack
(for-each
@@
-267,7
+266,7
@@
(begin
(emit "# loading captive ~a" (list-ref captives i))
(emit "movq ~a(~a), %rbx" (* wordsize i) (param-register 0))
(begin
(emit "# loading captive ~a" (list-ref captives i))
(emit "movq ~a(~a), %rbx" (* wordsize i) (param-register 0))
- (emit "movq %rbx, ~a(%rbp)" (* (- wordsize)
i
))))
+ (emit "movq %rbx, ~a(%rbp)" (* (- wordsize)
(+ 1 i)
))))
(range 0 (length captives)))
; load the args onto the stack
(range 0 (length captives)))
; load the args onto the stack
@@
-277,7
+276,7
@@
(emit "movq ~a, %rbx" (param-register (+ 1 i)))
(emit "movq %rbx, ~a(%rbp)"
(* (- wordsize)
(emit "movq ~a, %rbx" (param-register (+ 1 i)))
(emit "movq %rbx, ~a(%rbp)"
(* (- wordsize)
- (+ (length captives) i)))))
+ (+
1
(length captives) i)))))
(range 0 (length args)))
(codegen-expr body (* (- wordsize) (+ 1 (length params))) env)
(range 0 (length args)))
(codegen-expr body (* (- wordsize) (+ 1 (length params))) env)
@@
-541,7
+540,8
@@
(initialize-heap)
(emit "movq %rsp, %rbp") ; set up the base pointer
(initialize-heap)
(emit "movq %rsp, %rbp") ; set up the base pointer
- (codegen-expr xform-prog 0 '())
+
+ (codegen-expr xform-prog (- wordsize) '())
; exit syscall
(emit "mov %rax, %rdi")
; exit syscall
(emit "mov %rax, %rdi")