1 / 6

Procedure Environments & Activations

Procedure Environments & Activations. We’ll have another take on what makes up a closure. Louden discusses the fully static environment model of Fortran77. Such a primitive procedure activation model associates preallocated storage with each procedure.

Download Presentation

Procedure Environments & Activations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Procedure Environments & Activations • We’ll have another take on what makes up a closure. • Louden discusses the fully static environment model of Fortran77. Such a primitive procedure activation model associates preallocated storage with each procedure. • Our primary concern will be Stack-based runtime environments.

  2. Stack-based Runtime Environments • The activation records (frames) are maintained in a stack. The current procedure’s activation information is recorded in the stack top. It’s caller’s activation is the next element in the stack, and so forth. Below the top element, which corresponds to the active procedure, the stack is a LIFO list of all suspended calls. • It is common to refer to the current frame pointer or current activation record pointer as the environment pointer, or ep. • Louden refers to the activation stack pointer, which I call the dynamic chain pointer, the control link. • In compiled languages, the code for a function is typically allocated in static storage. The address of a function is referred to as its instruction pointer, or ip.

  3. Addressing variables in the Frame • In a statically compiled language, as each variable declaration is encountered in a procedure definition, all the relevant attributes of that variable are known. These include its • type • size • offset in the activation record • Thus, in a compiled language, we do not need to keep track of variable names at runtime.

  4. Other Information in Each Frame • The control link must appear in the stack so that we can restore our referencing environment (the environment pointer) after completion of the call. • The return address (address of the instruction following the call instruction) in the calling context must be stored so we can restore our execution state after completion of the call. • The address of the most recently created frame for the statically enclosing environment must be stored so we can get access to nonlocal data. Louden calls this the access link(Note, this is not necessary in C, Java, and C++ because there is no way to define a function whose nonlocal referencing environment is anything other than the global environment.)

  5. Execution of Louden’s Example ep p: < ,ip1> ... procedure lastex is procedure p(n:integer) isprocedure show isbegin if n > 0 then p(n-1); end if; put(n); new_line; end show; begin -- p show; end p; begin -- lastex p(1); end lastex; control link access link n:1 show:< ,ip2> control link access link control link access link n:0 show:< ,ip2> control link access link

  6. Dynamically Computed Environments and Stack Allocation • Consider the following scheme code:(define (makecount) ;; define a function, makecount (let ((x 0)) ;; create a block containing x (lambda () (set! x (+ x 1)) ;; make a function value)) • This can be used as follows:(set! mycount (makecount)) ;; mycount is the function value ;; returned by makecount(mycount);; returns 1(mycount);; returns 2(mycount);; returns 3 • Now let’s draw the activation record structures corresponding to all of this. • We see that a simple stack cannot be employed, because an ep to the makecount activation persists in its result function after makecount’s activation is terminated. • Clearly activation records in such a dynamic language must be allocated on the heap and garbage collected.

More Related