Drill 5 Solutions
- Does the current compiler ever put the address of a memory location on the heap onto the stack?
- Yes. For example,
(let ((x (pair 1 2))) x)will store1and2on the heap, and put the memory address of1on the stack.
- Does the current compiler ever put the address of a memory location on the heap into a register?
- Yes. For example,
(pair 1 2)will store1and2on the heap, and put the memory address of1intorax.
-
How many 8-byte heap "cells" will be used when each of the following programs are compiled and executed? (Remember that each pair takes up two cells).
-
(+ (left (pair 1 2)) (right (pair 3 4)))
- 4
-
(let ((x false)) (pair 1 (if x (pair 2 (pair 3 (pair 4 false))) (pair 2 (pair 3 false)) ) ) )
-
- Remember that only one branch of the conditional will actually be executed: in this case, the
elsebranch! We can't count heap usage just by counting occurences ofpair.
- Remember that only one branch of the conditional will actually be executed: in this case, the
-
-
-
For each expression below, will it result in an error or a valid result when run in the interpreter we have built in class?
program error valid result (+ 1 3 4)x (+ 1 (let ((x 2)) x))x (+ 1 (let ((x 2)) false))x (left (pair 1 false))x (left (left (pair 1 false)))x (** 2 3)x (if true (* 2 3) (** 2 3))x -
For each expression below, will it result in a compile-time error, a run-time error, or a valid result when run in the compiler we have built in class? (Assume that we have added error handling for all supported operations).
program compile error runtime error valid result (+ 1 3 4)x (+ 1 (let ((x 2)) x))x (+ 1 (let ((x 2)) false))x (left (pair 1 false))x (left (left (pair 1 false)))x (** 2 3)x (if true (* 2 3) (** 2 3))x