sicp-ex-5.38



<< Previous exercise (5.37) | Index | Next exercise (5.39) >>


meteorgan

  
  
  
 (a) 
 ;; in compile 
 ((open-code? exp) (compile-open-code exp target linkage)) 
  
  (define (open-code? exp) 
     (memq (car exp) '(+ - * /))) 
  
 (define (spread-arguments operand1 operand2) 
  (let ((op1 (compile operand1 arg1 'next)) 
            (op2 (compile operand2 arg2 'next))) 
   (list op1 op2))) 
  
 (b) 
 (define (compile-open-code exp target linkage) 
  (let ((op (car exp)) 
            (args (spread-arguments (cadr exp) (caddr exp)))) 
   (end-with-linkage linkage 
    (append-instruction-sequences 
         (car args) 
         (preserving '(arg1) 
          (cadr args) 
          (make-instruction-sequence '(arg1 arg2) (list target) 
           `((assign ,target (op ,op) (reg arg1) (reg arg2)))))))))