













































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of memory locations for variables in modern programming languages, focusing on activation records, static and dynamic allocation, and nesting links. It covers topics such as activation-specific variables, return addresses, and link to caller's activation record.
Typology: Slides
1 / 53
This page cannot be seen from the preview
Don't miss anything!














































Variables are bound (dynamically) to values
Those values must be stored somewhere
Therefore, variables must somehow be bound to memory locations
How?
Activation records
Static allocation of activation records
Stacks of activation records
Handling nested function definitions
Functions as parameters
Long-lived activation records
The lifetime of one execution of a function, from call to corresponding return, is called an activation of the function
When each activation has its own binding of a variable to a memory locations, it is an activation-specific variable
(Also called dynamic or automatic )
For block constructs that contain code, we can speak of an activation of the block The lifetime of one execution of the block A variable might be specific to an activation of a particular block within a function:
Chapter Twelve Modern Programming Languages, 2nd ed. 7
fun fact n = if (n=0) then 1 else let val b = fact (n-1) in nb end;*
Docsity.com
Most imperative languages have a way to declare a variable that is bound to a single memory location for the entire runtime Obvious binding solution: static allocation (classically, the loader allocates these)
Chapter Twelve Modern Programming Languages, 2nd ed. 8
int count = 0; int nextcount() { count = count + 1; return count; } Docsity.com
Object-oriented languages use variables whose lifetimes are associated with object lifetimes
Some languages have variables whose values are persistent: they last across multiple executions of the program
Today, we will focus on activation-specific variables
Language implementations usually allocate all the activation-specific variables of a function together as an activation record
The activation record also contains other activation-specific data, such as
Activation-specific variables
Static allocation of activation records
Stacks of activation records
Handling nested function definitions
Functions as parameters
Long-lived activation records
The simplest approach: allocate one activation record for every function, statically
Older dialects of Fortran and Cobol used this system
Simple and fast
Each function has one activation record
There can be only one activation alive at a time
Modern languages (including modern dialects of Cobol and Fortran) do not obey this restriction:
Activation-specific variables
Static allocation of activation records
Stacks of activation records
Handling nested function definitions
Functions as parameters
Long-lived activation records
Before, static: location of activation record was determined before runtime
Now, dynamic: location of the current activation record is not known until runtime
A function must know how to find the address of its current activation record
Often, a machine register is reserved to hold this
Chapter Twelve Modern Programming Languages, 2nd ed. 20
int fact(int n) { int result; if (n<2) result = 1; else result = n * fact(n-1); return result; }
We are evaluating fact(3). This shows the contents of memory just before the recursive call that creates a second activation.
previous activation record result:?
return address
n: 3
current activation record
Docsity.com