Drill 5

  1. Does the current compiler ever put the address of a memory location on the heap onto the stack?
  1. Does the current compiler ever put the address of a memory location on the heap into a register?
  1. 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)))
      
    • (let ((x false)) 
          (pair 1 (if x (pair 2 (pair 3 (pair 4 false))) 
                          (pair 2 (pair 3 false))
                  )
          )
      )
      
  2. 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)
    (+ 1 (let ((x 2)) x))
    (+ 1 (let ((x 2)) false))
    (left (pair 1 false))
    (left (left (pair 1 false)))
    (** 2 3)
    (if true (* 2 3) (** 2 3))
  3. 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)
    (+ 1 (let ((x 2)) x))
    (+ 1 (let ((x 2)) false))
    (left (pair 1 false))
    (left (left (pair 1 false)))
    (** 2 3)
    (if true (* 2 3) (** 2 3))