我想知道当变量不在编译时环境中时如何使用文本建议的(op get-global-environment)。由于我必须将 env 设置为指向全局环境,我添加了保存和恢复命令,但感觉不舒服,因为文本总是使用保留来保存和恢复寄存器。这是我的代码,有什么想法吗?
(define (compile-assignment exp target linkage cmpl-env)
(let ((var (assignment-variable exp))
(get-value-code
(compile (assignment-value exp cmpl-env) 'val 'next))
(laddr (find-variable var cmpl-env)))
(end-with-linkage
linkage
(preserving '(env)
get-value-code
(if (eq? laddr 'not-found)
(make-instruction-sequence
'(env val) (list target)
`((save env) ;;;here;;;;
(assign env (op get-global-environment))
(perform (op set-variable-value!)
(const ,var)
(reg val)
(reg env))
(restore env) ;;;and here ;;;;
(assign ,target (const ok))))
(make-instruction-sequence
'(env val) (list target)
`((perform lexical-address-set! laddr (reg val) (reg env)))
(assign ,target (const ok)))))))))