Chapter 5, Computing with Register Machines
Exercise 5.40
Since it contain lot of small changes, i am putting the main change.
All the code generators now accept this new argument cenv
, except:
compile-self-evaluating
compile-quoted
compile-procedure-call
(not to be confused withcompile-application
wherecenv
did get passed bec it is required for compiling the arguments there).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(define (compile-lambda-body exp proc-entry cenv)
(let ((formals (lambda-parameters exp)))
(append-instruction-sequences
(make-instruction-sequence '(env proc argl) '(env)
`(,proc-entry
(assign env (op compiled-procedure-env) (reg proc))
(assign env
(op extend-environment)
(const ,formals)
(reg argl)
(reg env))))
(compile-sequence (lambda-body exp)
'val
'return
(extend-compile-time-env cenv formals)))) ;;;
(define (extend-compile-time-env cenv frame) ;;;
(cons frame cenv)) ;;;