sicp-ex-5.42



<< Previous exercise (5.41) | Index | Next exercise (5.43) >>


meteorgan

  
  
 ;; I skip compile-assignment. 
 (define (compile-variable exp target linkage ct-env) 
  (let ((r (find-variable exp ct-env))) 
   (if (eq? r 'not-found) 
           (end-with-linkage linkage 
            (make-instruction-sequence '(env) (list target) 
                 `((assign ,target 
                   (op lookup-variable-value) 
                   (const ,exp) 
                                   (reg env))))) 
           (end-with-linkage linkage 
            (make-instruction-sequence '(env) (list target) 
                 `(assign ,target 
                                   (op lexical-address-lookup) 
                                   (const ,r) 
                                   (reg env)))))))