Comparative Languages Assignments, Spring 2005
Activation records, dynamic and static links

  • Subprograms (Slides from Ch. 9 - see slides 57-65)
  • See p. 409-416 in your text.
         Fig. 10.9 on page 414 is an activation record for the ADA program on p. 412-413.
         First, look at the structure of the program.  The overall procedure is Main_2.  
         Nested inside Main_2 is procedure Bigsub.  Nested inside Bigsub are procedures Sub1 and Sub2.  
         Inside Sub2 is procedure Sub3.
         
         The program starts with a call to Bigsub from Main_2.  Next is a call to Sub2 from Bigsub. 
         Sub3 is called from Sub2, and Sub1 is called from Sub3.
         
         A static link is built at compile time.  The static link points to the bottom of the 
         activation record of the parent procedure. (defined on p. 409)
         
         See Fig 10.9: (see slides 24-26 - slide 26 is the activation record for program on slide 24)
               Bigsub (inside Main_2) has a static link to the bottom of Main_2 record
    	   Sub2 (inside Bigsub) has a static link to the bottom of Bigsub record
    	   Sub3 (inside Sub2) has a static link to the bottom of Sub2
    	   Sub1 (inside Bigsub) has a static link to the bottom of Bigsub
       
         A dynamic link (defined on p. 402) points to the top of the activation record of the 
         calling procedure. 
         Dynamic links are defined at run time, when you're running the program.
         
         	   Bigsub calls Sub2: Sub2 has a dynamic link to the top of Bigsub
    	   Main_2 calls Bigsub: Bigsub has a dynamic link to the top of Main_2
    	   Sub2 calls Sub3: Sub3 has a dynamic link to the top of Sub2
    	   Sub3 calls Sub1: Sub1 has a dynamic link to the top of Sub3
         
         The static depth (defined on p. 412) indicates how deeply a procedure's scope is nested 
         in the outermost scope.  
         In this example program, Main_2 is depth 0, Bigsub is depth 1, Sub1 and Sub2 are depth 2, 
         and Sub3 is depth 3.