Answer 5.46
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
*.ss#*
|
*.ss#*
|
||||||
.#*.ss
|
.#*.ss
|
||||||
|
|
||||||
|
test.scm
|
||||||
*.scm~
|
*.scm~
|
||||||
*.scm#*
|
*.scm#*
|
||||||
.#*.scm
|
.#*.scm
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
(load "shared/sicp-load-eceval-compiler")
|
(load "shared/sicp-load-eceval-compiler")
|
||||||
(load "shared/sicp-compiler")
|
(load "shared/sicp-compiler")
|
||||||
|
|
||||||
|
|
||||||
(display "\nex-5.45 - factorial-stack-usage-comparison\n")
|
(display "\nex-5.45 - factorial-stack-usage-comparison\n")
|
||||||
|
|
||||||
;(compile-and-go
|
;(compile-and-go
|
||||||
@@ -35,9 +34,62 @@
|
|||||||
|
|
||||||
; b. Use special handling for primitive procedures from exercise 5.38.
|
; b. Use special handling for primitive procedures from exercise 5.38.
|
||||||
|
|
||||||
(display "[answered]\n")
|
(display "[done]\n")
|
||||||
|
|
||||||
(display "\nex-5.46 - fibo-stack-usage-comparison\n")
|
(display "\nex-5.46 - fibo-stack-usage-comparison\n")
|
||||||
|
|
||||||
|
;(compile-and-go
|
||||||
|
; '(begin
|
||||||
|
; (define (fib n)
|
||||||
|
; (if (< n 2)
|
||||||
|
; n
|
||||||
|
; (+ (fib (- n 1)) (fib (- n 2)))))
|
||||||
|
; (fib 10)))
|
||||||
|
|
||||||
|
; | (fib 10) | pushes | depth |
|
||||||
|
; | -------------- | ------ | ------ |
|
||||||
|
; | machine | 264 | 18 |
|
||||||
|
; | compiled | 882 | 29 |
|
||||||
|
; | evaluator | 4950 | 53 |
|
||||||
|
|
||||||
|
; | (fib 20) | pushes | depth |
|
||||||
|
; | -------------- | ------ | ------ |
|
||||||
|
; | machine | 32835 | 38 |
|
||||||
|
; | compiled | 109452 | 59 |
|
||||||
|
; | evaluator | 612942 | 103 |
|
||||||
|
|
||||||
|
(display "[done]\n")
|
||||||
|
|
||||||
(display "\nex-5.47\n")
|
(display "\nex-5.47\n")
|
||||||
|
|
||||||
|
; Exercise 5.47. This section described how to modify the explicit-control
|
||||||
|
; evaluator so that interpreted code can call compiled procedures. Show how to
|
||||||
|
; modify the compiler so that compiled procedures can call not only primitive
|
||||||
|
; procedures and compiled procedures, but interpreted procedures as well. This
|
||||||
|
; requires modifying compile-procedure-call to handle the case of compound
|
||||||
|
; (interpreted) procedures. Be sure to handle all the same target and linkage
|
||||||
|
; combinations as in compile-proc-appl. To do the actual procedure application,
|
||||||
|
; the code needs to jump to the evaluator's compound-apply entry point. This
|
||||||
|
; label cannot be directly referenced in object code (since the assembler
|
||||||
|
; requires that all labels referenced by the code it is assembling be defined
|
||||||
|
; there), so we will add a register called compapp to the evaluator machine to
|
||||||
|
; hold this entry point, and add an instruction to initialize it:
|
||||||
|
|
||||||
|
; (assign compapp (label compound-apply))
|
||||||
|
; (branch (label external-entry)) ; branches if flag is set
|
||||||
|
;read-eval-print-loop
|
||||||
|
; ...
|
||||||
|
|
||||||
|
; To test your code, start by defining a procedure f that calls a procedure g.
|
||||||
|
; Use compile-and-go to compile the definition of f and start the evaluator.
|
||||||
|
; Now, typing at the evaluator, define g and try to call f.
|
||||||
|
|
||||||
|
|
||||||
|
(compile-and-go
|
||||||
|
'(define (f n)
|
||||||
|
(g n)))
|
||||||
|
|
||||||
|
(display "\nex-5.48\n")
|
||||||
|
|
||||||
|
; (display "\nex-5.49\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user