cs160-lec14 - CMPSC 160 Translation of Programming...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMPSC 160 Translation of Programming Languages Lectures 14: Activation Records, Addressability, Procedure Linkages What about run-time? The symbol tables are how we store information about the variables, scope, procedures at compile-time When we are compiling the program we build up a lexically-scoped symbol table and we use information in the compiler to help use compile a program But when we compile the program, how do we implement procedures? How can we track scope at run-time? We need to compile a special data structure into the program to help us keep track of procedures. We can then push and pop these data structures when procedure is called This data structure is called an activation record Control and Data To deal with procedures we need to keep track of two basic things Transfer of control between procedures: What is the return address Where is the context for the caller? We need a control link which will point to the context of the caller What is the return address? In languages such as C and Pascal callee cannot outlive its caller, this means that we can store the return addresses on a stack Where is the data: Where is the local data for the procedure? Again we can use a stack Where is the non-local data? If we can have nested scopes (as in Pascal) then we need an access link which will point to the next lexical scope Where do we keep this information: in an Activation Record Activation Record Basics parameters register save area return value return address access link control link local variables Activation Record Pointer (ARP) (aka frame pointer) Space for parameters of the procedure Saved register contents (to restore the machine status for the caller) Space for return value Address to resume caller Link for non-local access Stores callers ARP to restore callers AR on return Space for local values & variables (including temporaries) One AR for each invocation of a procedure (one AR for each node in the activation tree) Where Do We Store the Activation Record? Where do activation records live? If lifetime of AR matches lifetime of invocation AND If code normally executes a return (this is the case with C) Keep AR s on a stack If a procedure can outlive its caller OR If it can return an object that can reference its execution state AR s must be kept in the heap If a procedure makes no calls OR If language does not allow recursion AR can be allocated statically Classic Organization Placing Run-time Data Structures Code, static, and global data have known size > Use symbolic labels in the code Heap and stack both grow and shrink over time This is a virtual address space, it is relocatable Better utilization if stack and heap grow toward each other Uses address space, not allocated memory C o d e S G t l a & o t b i a c l H e a p S t a c k Single Logical Address Space high How Does This Really Work?...
View Full Document

Page1 / 26

cs160-lec14 - CMPSC 160 Translation of Programming...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online