Static Chain
Static Chain:
Mechanism to implement non-local variable access in Static Scope
Each Variable (Local or Non-local) is represented as a 2-tuple:
(chain-offset , local-offset)
Chain-offset calculated as:
- Number of static links between activation record of referencing subprogram and
activation record of declaring subprogram on the stack
- Depth of referencing subprogram - Depth of declaring subprogram in Static Tree
Local-offset of a variable is calculated as:
- Offset of the local variable in the activation record of the declaring subprogram
Advantage:
- Efficient: Chain-offset, local-offset calculated at compile time, plugged into code
Disadvantage:
- Expensive: Access of non-local variable is expensive when Chain-offset is large