CS 3520 Homework 11   - Due December 4

Exercise 11.1, Continuations

The following are possible states of the interepreter with continuations. In each case, what will the final value of the program be?
  1. exp: 3
    env: {}
    cnt: [primother -, 2, {}, [done]]

  2. exp: x
    env: {x=7, {x=3, {}}}
    cnt: [primother +, x, {x=3, {}}, [done]]

  3. val: 10
    cnt: [app <x, proc(y)*(y, 2), {}>, [apparg 11, {}, [done]]]

  4. val: <x, proc(y)-(x, y), {x=3, {}}>
    cnt: [apparg 7, {x=3, {}}, [apparg x, {x=3, {}}, [done]]]

  5. val: <w, if w then (f proc(x)0) else w, {f=<g, *((g 3), 2), {}>, {}}>
    cnt: [app <g, *((g 3), 2), {}>, [done]]
Express your answer as a function answer-for-11.1 that takes no arguments and returns a list of 5 numbers.

Exercise 11.2, Garbage collection

Suppose a garbage-collected interepreter uses the following four kinds of records:(An "integer" is an immediate integer, not a tagged integer representing a value in the interpreted language.)

The interpreter has two registers, which always contain pointers, and a memory pool of size 30. The allocator/collector is a two-space copying collector, so each space is of size 15. Records are allocated consecutively in to-space, starting from the first memory location, 0.

The following is a snapshot of memory just before a collection where all memory has been allocated:

What are the values in the two registers and the new to-space after collection? Assume that unallocated memory in to-space contains 0.

Express your answer as a function answer-for-11.2 that takes no arguments and returns a list of 17 numbers (register 1, then register 2, then to-space slots).


Last update: Monday, November 26th, 2001
mflatt@cs.utah.edu