Runtime environments
An activation is one execution of a procedure, not its source-code definition. Recursion creates several simultaneous activations of the same procedure, each with its own live state.
5.1 Storage regions and activation records
Past papers · CS 2014–2026 (23 papers): 3 questions, 4 marks
| Allocation | Lifetime and suitability |
|---|---|
| Static | Address/lifetime fixed independently of individual calls; globals and static-duration objects |
| Stack | Activation lifetimes are nested; supports ordinary recursion and automatic locals |
| Heap | Lifetimes need not follow call/return nesting; dynamically created objects and escaping environments |
An activation record may contain arguments, return value, return address, saved registers, temporaries, locals, dynamic link and static link. The exact order, register use and stack-growth direction belong to the calling convention. No universal frame-layout byte count exists.
A dynamic/control link points to the caller's frame. A static/access link points to the frame of the lexically enclosing procedure. The return address identifies where execution resumes; it is not either link. Stack and frame pointers locate the active storage, and the caller/callee split specifies who saves or restores each item.
An activation tree has one node per call, with children ordered by call time. Calls appear in preorder; returns appear in postorder. At any instant, active ordinary calls form a root-to-current-node path.
5.2 Scope, static chains and nonlocal access
Under lexical/static scope, a use binds according to textual nesting. Under dynamic scope, it binds to the most recent active declaration found along the caller chain. A dynamic link is about calls; a static link is about lexical ancestry. A procedure's caller need not be its lexical parent.
A display stores a pointer to the active frame at each lexical level, allowing direct indexed access; calls and returns save and restore affected entries. A closure pairs code with its lexical environment. If that environment outlives its creating call, a simple stack-only representation of the environment is insufficient.
5.3 Parameter passing and aliasing
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
| Mechanism | What the callee receives | Effect of assigning to the formal |
|---|---|---|
| Value | Copy of the argument value | Changes the formal's local copy |
| Reference | Access to the argument's storage location | Changes that location |
| Value-result | Local copy on entry, copied back on return | Affects actual storage at copy-out |
| Name | Delayed computation of the actual expression in the appropriate environment | Access is re-evaluated when used; assignment needs an assignable actual |
Passing a pointer by value copies the pointer, but writing through it can still change the pointed-to object. If two reference parameters alias one variable, assignments through either are immediately visible through both. With value-result and aliased actuals, copy-out order can determine the final value. Do not invent that order.
Last-minute recall
- An activation record belongs to a call, not a procedure name.
- Calls are preorder; returns are postorder in the activation tree.
- Peak stack space follows the deepest active path, not total call count.
- Static links follow lexical nesting; dynamic links follow callers.
- Recursion needs distinct live activation state, not necessarily a heap.
- Reference parameters may alias.
- Value-result requires a copy-out order when actuals overlap.