More on up-level addressing Review: The activation record (AR) holds locals, parameters, and bookkeeping stuff The AR is pointed to by a register, called the frame pointer (FP). Among the bookkeeping values stored are the old FP, the return address, saved registers, and (if nested classes are allowed) the old static link. The problem of uplevel addressing is how to get hold of non-local, non-global values. (locals are just an offset from the current FP, globals are accessed via a symbolic name. It's the stuff in the middle that is the problem). Take an example nested procedure. (3 levels of nesting will do). Note that the AR's on the static chain mirrors the nested symbol tables. (Draw both pictures). One is constructed at compile time, one at run time. Note the steps involved in accessing nested variables. What is the address constructed for variables at each level? We can use the fact that the symbol table mirrors the AR. to automatically construct the address for a variable as we walk through the levels of the symbol table. (Go through this). This is what is done by the buildAST procedure. How are static chains set? Rule: the CALLER must set, must make the SC point to the AR for the surrounding scope. Only the Caller knows this, since a procedure might be called from many different levels of scope. Go through examples: 1. Calling one level down. The static chain is just the current AR. 2. Calling at same level (sibling) the SC is the same as the current SC. 3. Calling some levels up (could be any number of levels up) must find the SC and back up. Again, we can use a nifty trick and create the AST for the static chain as we are searching the symbol tables for a procedure name.