Variable Accesses Flashcards
local variables
declared in the method that accesses them
global variables
not declared in any method, accessible to all
Non-local vars
variables declared in one sub-program and used in a nested sub-program
for dynamic scope, bars used in a method w/o being declared there
stack pointer points to
next 4-byte slot to use
frame pointer points to
4-byte slot that holds the return address
How are doubles stored
pairs of floating point registers with consecutive numbers {f0, f1}. Instructions only refer to the even numbered register of each pair
non-local vars in statically scoped languages
variable declared in one sub-program and accessed in another, nested sub program.
Where are non-local vars stored in statically scoped languages?
Stored in the AR of the sub-program that declares them
What happens when non-local vars are used in statically scoped languages?
the activation record in which they are stored is found at runtime using access links or display
How can an activation record be found for statically scoped languages?
Access links or display
How do dynamically scoped languages work?
A variable can be declared in one method, and accessed in a called method.
Idea of acess links
Add a new field to each AR
If P is nested inside Q, then at runtime P’s access link will point to the access link field in the AR of the most recent activation of Q
For static scoping access links, how to determine how many links of the chain to follow at runtime
Use a “level number” attribute for the non-local variable, x, and “current level number” of the subprogram accessing x
If level i uses x and x was declared in level j, follow i-j links, then use x’s offset attribute to find x’s storage space in AR
Who is access link set up by?
calling procedure
2 cases for how to set up access links?
1) calling procedure’s level is < the called procedure
2) calling procedure’s level is >= to the called procedure’s level