Implement 5.38a
This commit is contained in:
@@ -391,11 +391,6 @@ ev-appl-did-operator-no-restore
|
|||||||
|
|
||||||
(display "\nex-5.38 - optimize-procedure-application\n")
|
(display "\nex-5.38 - optimize-procedure-application\n")
|
||||||
|
|
||||||
; The expression (+ a 1) might be compiled into something as simple as:
|
|
||||||
|
|
||||||
; (assign val (op lookup-variable-value) (const a) (reg env))
|
|
||||||
; (assign val (op +) (reg val) (const 1))
|
|
||||||
|
|
||||||
; a. The open-coded primitives, unlike the special forms, all need their
|
; a. The open-coded primitives, unlike the special forms, all need their
|
||||||
; operands evaluated. Write a code generator spread-arguments for use by all
|
; operands evaluated. Write a code generator spread-arguments for use by all
|
||||||
; the open-coding code generators. Spread-arguments should take an operand list
|
; the open-coding code generators. Spread-arguments should take an operand list
|
||||||
@@ -403,12 +398,35 @@ ev-appl-did-operator-no-restore
|
|||||||
; Note that an operand may contain a call to an open-coded primitive, so
|
; Note that an operand may contain a call to an open-coded primitive, so
|
||||||
; argument registers will have to be preserved during operand evaluation.
|
; argument registers will have to be preserved during operand evaluation.
|
||||||
|
|
||||||
(define (spread-arguments operand-codes)
|
(define (spread-arguments operand-list)
|
||||||
(assert (length operand-codes) 2)
|
(define (compile-operands operand-list operand-number)
|
||||||
(make-instruction-sequence
|
(cond
|
||||||
'()
|
((null? operand-list) (empty-instruction-sequence))
|
||||||
'()
|
((and (= operand-number 1))
|
||||||
'((assign ))))
|
(preserving
|
||||||
|
'(arg1)
|
||||||
|
(compile (car operand-list) 'arg1 'next)
|
||||||
|
(compile-operands (cdr operand-list) (+ operand-number 1))))
|
||||||
|
((and (= operand-number 2))
|
||||||
|
(preserving
|
||||||
|
'(arg1 arg2)
|
||||||
|
(compile (car operand-list) 'arg2 'next)
|
||||||
|
(compile-operands (cdr operand-list) (+ operand-number 1))))
|
||||||
|
(else
|
||||||
|
(error "Only two arg registers supported -- SPREAD-ARGUMENTS"))))
|
||||||
|
|
||||||
|
(let ((operand-codes (compile-operands operand-list 1)))
|
||||||
|
operand-codes))
|
||||||
|
|
||||||
|
(define (display-lines xs)
|
||||||
|
(define (display-line x)
|
||||||
|
(display x) (newline))
|
||||||
|
(map display-line xs))
|
||||||
|
|
||||||
|
(display-lines (third (spread-arguments '(1 1))))
|
||||||
|
(newline)
|
||||||
|
|
||||||
|
(display "b. CONTINUE HERE\n")
|
||||||
|
|
||||||
; b. For each of the primitive procedures =, *, -, and +, write a code
|
; b. For each of the primitive procedures =, *, -, and +, write a code
|
||||||
; generator that takes a combination with that operator, together with a target
|
; generator that takes a combination with that operator, together with a target
|
||||||
|
|||||||
Reference in New Issue
Block a user