Start to work on 5.33
parent
1dc65b4ffd
commit
ba682d8f6a
|
@ -1,4 +1,5 @@
|
||||||
(load "util.scm")
|
(load "util.scm")
|
||||||
|
(load "misc/ch5-compiler.scm")
|
||||||
|
|
||||||
(display "\nex-5.31 - save-and-restore-for-apply\n")
|
(display "\nex-5.31 - save-and-restore-for-apply\n")
|
||||||
|
|
||||||
|
@ -61,10 +62,63 @@ ev-appl-did-operator-no-restore
|
||||||
; before runtime
|
; before runtime
|
||||||
(display "[answered]\n")
|
(display "[answered]\n")
|
||||||
|
|
||||||
(display "\nex-5.33\n")
|
|
||||||
|
|
||||||
(display "CONTINUE at 5.5.3\n")
|
(display "\nex-5.33 - compare-factorial-definitions\n")
|
||||||
|
|
||||||
|
(define (compile-to-file code target linkage file-name)
|
||||||
|
(define (write-list-to-port xs port)
|
||||||
|
(if (null? xs)
|
||||||
|
'()
|
||||||
|
(begin
|
||||||
|
(display (car xs) port)
|
||||||
|
(display "\n" port)
|
||||||
|
(write-list-to-port (cdr xs) port))))
|
||||||
|
(let* ((compile-result (compile code target linkage))
|
||||||
|
(assembly-insts (statements compile-result))
|
||||||
|
(port (open-output-file file-name)))
|
||||||
|
(write-list-to-port assembly-insts port)
|
||||||
|
(display "[")
|
||||||
|
(display file-name)
|
||||||
|
(display "]\n")
|
||||||
|
(close-output-port port)))
|
||||||
|
|
||||||
|
; Uncomment the following lines to write the assembly code for the to methods
|
||||||
|
; into files.
|
||||||
|
|
||||||
|
;(compile-to-file
|
||||||
|
; '(define (factorial n)
|
||||||
|
; (if (= n 1)
|
||||||
|
; 1
|
||||||
|
; (* (factorial (- n 1)) n)))
|
||||||
|
; 'val 'next "factorial.sicp-asm")
|
||||||
|
;
|
||||||
|
;; reset label counter to the same labels for diff
|
||||||
|
;(define label-counter 0)
|
||||||
|
;
|
||||||
|
;(compile-to-file
|
||||||
|
; '(define (factorial-alt n)
|
||||||
|
; (if (= n 1)
|
||||||
|
; 1
|
||||||
|
; (* n (factorial-alt (- n 1)))))
|
||||||
|
; 'val 'next "factorial-alt.sicp-asm")
|
||||||
|
|
||||||
|
; $ diff factorial.sicp-asm factorial-alt.sicp-asm
|
||||||
|
; 33,36c33,34
|
||||||
|
; < (assign val (op lookup-variable-value) (const n) (reg env))
|
||||||
|
; < (assign argl (op list) (reg val))
|
||||||
|
; < (save argl)
|
||||||
|
; ---
|
||||||
|
; > (save env)
|
||||||
|
; > (assign proc (op lookup-variable-value) (const factorial-alt) (reg env))
|
||||||
|
; 63c61,63
|
||||||
|
; < (restore argl)
|
||||||
|
; ---
|
||||||
|
; > (assign argl (op list) (reg val))
|
||||||
|
; > (restore env)
|
||||||
|
; > (assign val (op lookup-variable-value) (const n) (reg env))
|
||||||
|
|
||||||
|
|
||||||
(display "\nex-5.34\n")
|
(display "\nex-5.34\n")
|
||||||
;(display "\nex-5.35\n")
|
|
||||||
|
(display "\nex-5.35\n")
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
;;;;Then you can compile Scheme programs as shown in section 5.5.5
|
;;;;Then you can compile Scheme programs as shown in section 5.5.5
|
||||||
|
|
||||||
;;**implementation-dependent loading of syntax procedures
|
;;**implementation-dependent loading of syntax procedures
|
||||||
(load "ch5-syntax.scm") ;section 4.1.2 syntax procedures
|
(load "misc/ch5-syntax.scm") ;section 4.1.2 syntax procedures
|
||||||
|
|
||||||
|
|
||||||
;;;SECTION 5.5.1
|
;;;SECTION 5.5.1
|
||||||
|
|
Loading…
Reference in New Issue