CODE proc A () { int x = 0; proc B() { int y = 1; int z = 1; proc C() { int y; y = z; x = z; return; } proc D() { call C(); z = x + y; return; } x = 3; call D(); return; } proc E() { int y = 3; x = x + 1; x = x + 1; call B(); y = 4; return; } x = 5; call E(); return; } --------------------------------------------------------------------------- STACK FRAME TEMPLATES (ACTIVATION RECORDS) offset content A 0 return address 1 static link 2 x B 0 return address 1 static link 2 y 3 z C 0 return address 1 static link 2 y D 0 return address 1 static link E 0 return address 1 static link 2 y --------------------------------------------------------------------------- RESOLVING VARIABLES (STATIC SCOPE) In procedure variable (static link steps, offset) A x (0, 2) B x (1, 2) y (0, 2) z (0, 3) C x (2, 2) y (0, 2) z (1, 3) D x (2, 2) y (1, 2) z (1, 3) E x (1, 2) y (0, 2) --------------------------------------------------------------------------- RUN-TIME STACK (FIGURE 3.5) CALL SEQUENCE:A, E, B, D, C static links Stack frame ---------------- C <--- top of stack | | | | | -------------- D | | | | | | | -------------> B ---------------> ------------- | | | | --------- E | | | | | | | | | --------> A -------------->