Chapter 5

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

AllocationLifetime and suitability
StaticAddress/lifetime fixed independently of individual calls; globals and static-duration objects
StackActivation lifetimes are nested; supports ordinary recursion and automatic locals
HeapLifetimes 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.

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

MechanismWhat the callee receivesEffect of assigning to the formal
ValueCopy of the argument valueChanges the formal's local copy
ReferenceAccess to the argument's storage locationChanges that location
Value-resultLocal copy on entry, copied back on returnAffects actual storage at copy-out
NameDelayed computation of the actual expression in the appropriate environmentAccess 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.

Revise offline: the whole Compiler Design handbook as one PDF

43 pages · 2.0 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections