projects
/
scheme.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e51b9e4
)
Add recursive let-bindings
author
Luke Lau
<luke_lau@icloud.com>
Mon, 22 Jul 2019 19:41:24 +0000
(20:41 +0100)
committer
Luke Lau
<luke_lau@icloud.com>
Mon, 22 Jul 2019 19:41:24 +0000
(20:41 +0100)
codegen.scm
patch
|
blob
|
history
diff --git
a/codegen.scm
b/codegen.scm
index d30adc54e61a144097c3b0bb541a5835af8c028a..e1b51a60a5ac6c9fcde9f23dd4ca58e9c02f2274 100644
(file)
--- a/
codegen.scm
+++ b/
codegen.scm
@@
-51,12
+51,17
@@
(inner-si (- si (* (length bindings) wordsize)))
(names (map car bindings))
(exprs (map cadr bindings))
(inner-si (- si (* (length bindings) wordsize)))
(names (map car bindings))
(exprs (map cadr bindings))
- (inner-env (append (map cons names stack-offsets) env)))
- (for-each (lambda (expr offset)
+
+ ; recursive let bindings: build environment as we go
+ (inner-env (fold-left
+ (lambda (env name expr offset)
(codegen-expr expr inner-si env)
(codegen-expr expr inner-si env)
- (emit "movq %rax, ~a(%rsp)" offset))
- exprs stack-offsets)
- (for-each (lambda (form) (codegen-expr form inner-si inner-env)) body)))
+ (emit "movq %rax, ~a(%rsp)" offset)
+ (cons (cons name offset) env))
+ env names exprs stack-offsets)))
+ (for-each (lambda (form)
+ (codegen-expr form inner-si inner-env))
+ body)))
(define (codegen-var name si env)
(when (not (assoc name env))
(define (codegen-var name si env)
(when (not (assoc name env))