Drill 5 Solutions
- Does the current compiler ever put the address of a memory location on the heap onto the stack?
- yes
- Does the current compiler ever put the address of a memory location on the heap into a register?
- yes
-
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
else
branch! 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 -
Which of the following sequences of assembly instructions is equivalent to the single instruction "call read_num"?
- ( )
jmp read_num; sub rsp, 8; mov [rsp + 0], rip
- (X)
sub rsp, 8; mov [rsp + 0], rip; jmp read_num
- ( )
mov [rsp + 0], rip; sub rsp, 8; jmp read_num
- ( )
jmp read_num; mov [rsp + 0], rip; sub rsp, 8
- ( )
-
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 store1
and2
on the heap, and put the memory address of1
intorax
.
- Yes. For example,
-
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 store1
and2
on the heap, and put the memory address of1
on the stack.
- Yes. For example,