Flashcards in Chapter 10 - Implementing Subprogram Deck (13):
what is subprogram linkage
the subprogram call and return operations of a language
5 things that a PL needs to do during a subprogram call
1) follow whatever parameter passing method is used
2) create local variables by allocating storage and binding those variables to storage
3) save the execution status of the calling program unit
4) arrange to transfer control to the subprogram and ensure that control can return to the proper place when the subprogram execution is complete
5) if nested subprograms are allowed, make non-local variables visible to the called subprogram
4 things a subprogram must do upon termination
1) move the local values of the associated formal parameters to the actual parameters for the out or inout mode semantics
2) deallocate storage used for local variables
3) restore the execution status of the calling program unit
4) return control to the calling program unit
What is a dynamic link?
a pointer variable that points to the top of the activation record (same as a stack frame) instance of the caller
what is a dynamic chain or call chain?
a collection of dynamic links in the stack at a given time
What is local_offset?
the location of local variables of a subprogram relative to the beginning of the activation record
8 characteristics of an Algol60-like program stack
-parameters often passed by two methods
-local variables are often dynamically allocated
-recursion must be supported
-static scoping must be supported
-activation record format is static but size is dynamic
-the dynamic link points to the top of an instance of the activation record of the caller
-an activation record instance is created dynamically when a subprogram is called
what is a static link?
a pointer variable that points to the bottom of the activation record of the static parent
only used when nested sub-programs are allowed in order to access non-local variables
what is a static chain?
a chain of static links that connect certain activation records
what is static depth?
an integer associated with a static scope whose value is the depth of nesting of that scope. (main starts at 0, and each nested sub-program is +1)
what is chain offset or nesting depth?
the static depth of reference - static depth of declaration
Two issues with static chain method
- nonlocal references are slow if # of scopes between reference and declaration variable (i.e. chain offset) is large
-cost of non-local references can change with code upgrades