ML Homework 5: Snapshot of the Runtime Stack for Given ML Code, Assignments of Programming Languages

A ml code snippet and instructions for drawing a snapshot of the runtime stack immediately before the last call to the 'plus' function returns to the body of 'repeat'. The necessary components of an activation record and the role of closures. It is a useful resource for students studying functional programming and stack frames.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-4kb
koofers-user-4kb 🇺🇸

5

(1)

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 5
due before class Oct 31, 2008
1. (20pts) Draw a snapshot of the runtime stack for the following ML code immediately
before the last call to plus returns to the body of repeat.
1 fun plus(x) = x + 1;
2 fun main(x) =
3 let val y = x + 1
4 in let fun repeat(f,x) =
5 let y = f(x)
6 in f(y)
7 end
8 in repeat(plus, y)
9 end
10 end;
11 main (5);
12
The activation record for each function needs to have a control link, an access link,
a return address, a return value address, parameters, and local variables. Remember
that function values are represented by closures and that a closure is a pair consisting
of an environment (pointer to an activation record) and compiled code. Use the line
numbers in the code to indicate the return address of each function call (the line
number immediately following the function call). Follow guidelines in lab8.
1

Partial preview of the text

Download ML Homework 5: Snapshot of the Runtime Stack for Given ML Code and more Assignments Programming Languages in PDF only on Docsity!

Homework 5

due before class Oct 31, 2008

  1. (20pts) Draw a snapshot of the runtime stack for the following ML code immediately before the last call to plus returns to the body of repeat.

1 fun plus(x) = x + 1; 2 fun main(x) = 3 let val y = x + 1 4 in let fun repeat(f,x) = 5 let y = f(x) 6 in f(y) 7 end 8 in repeat(plus, y) 9 end 10 end; 11 main (5); 12

The activation record for each function needs to have a control link, an access link, a return address, a return value address, parameters, and local variables. Remember that function values are represented by closures and that a closure is a pair consisting of an environment (pointer to an activation record) and compiled code. Use the line numbers in the code to indicate the return address of each function call (the line number immediately following the function call). Follow guidelines in lab8.