Implementing Dynamic Scope
. Deep Access
- Dispense with access links
- use control links to search into the stack
- term deep access comes from the fact that search may go deep into the stack
. Shallow Access
- hold current value of each name in static memory
- when a new activation of p occurs a local name n in p takes over the storage for n
- previous value of
n is saved in the activation record of p
We will discuss two approaches to implement dynamic scope. They bear resemblance to the use of access links and displays, respectively, in the implementation of the lexical scope.
1. Deep Access : Dynamic scope results if access links point to the same activation records that control links do. A simple implementation is to dispense with access links and use control links to search into the stack, looking for the first activation record containing storage for the non- local name. The term deep access comes from the fact that search may go deep into the stack. The depth to which the search may go depends on the input of the program and cannot be determined at compile time.
2. Shallow Access : Here the idea is to hold the current value of each name in static memory. When a new activation of a procedure p occurs, a local name n in p takes over the storage for n. The previous value of n is saved in the activation record for p and is restored when the activation of p ends.
|