Concepts of Programming Languages

(Sean Pound) #1

458 Chapter 10 Implementing Subprograms


is no visible scope containing a declaration for the variable D, so this reference
to D is a static semantics error. The error would be detected when the compiler
attempted to compute the chain_offset / local_offset pair. The reference to E is
to the local E in Sub2, which can be accessed with the pair (0, 5).
In summary, the references to the variable A at points 1, 2, and 3 would be
represented by the following points:


  • (0, 3) (local)

  • (2, 3) (two levels away)

  • (1, 3) (one level away)


Figure 10.9


Stack contents at
position 1 in the
program Main_2


ARI = activation record instance

B

Local
Local
Parameter
Dynamic link
Static link

ARI for
Sub2

X

E

B
A

X

C

C

Local E
Local
Dynamic link
Static link
Return (to Sub2)

ARI for
Sub3

A

D
Top

Local

Local

Local
Dynamic link
Static link
Return (to Main_2)
Local

ARI for
Bigsub

ARI for
Main_2

Return (to Bigsub)

Local
Local
Dynamic link
Static link
Return (to Sub3)

ARI for
Sub1
Free download pdf