How to setup access links?
. suppose procedure p at depth np calls procedure x at depth nx.
. The code for setting up access links depends upon whether the called procedure is nested within the caller.
- np < nx
Called procedure is nested more deeply than p. Therefore, x must be declared in p. The access link in the called procedure must point to the access link of the activation just below it
- np ≥ nx
From scoping rules enclosing procedure at the depth 1,2,. ,nx-1 must be same. Follow np-(nx-1) links from the caller, we reach the most recent activation of the procedure that encloses both called and calling procedure
Suppose procedure p at depth np calls procedure x at depth nx . The code for setting up the access link in the called procedure depends on whether or not the called procedure is nested within the caller.
. Case np < nx. Since the called procedure x is nested more deeply than p, therefore, x must be declared in p, or it would not be accessible to p. This case occurs when sort calls quicksort and when quicksort calls partition in the previous example. In this case, the access link in the called procedure must point to the access link of the activation record of the caller just below it in the stack.
. Case np ≥ nx. From the scope rules, the enclosing procedures at the nesting depths 1,2,. ,nx-1 of the called and calling procedures must be the same. Following np-nx+1 access links from the caller, we reach the most recent activation record of the procedure that statically encloses both the called and calling procedures most closely. The access link reached is the one to which the access link in the called procedure must point. This case occurs when quicksort calls itself in the previous example.
|