Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.

Similar presentations


Presentation on theme: "Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage."— Presentation transcript:

1 Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage

2 Activation Records n Each execution of the body is called an activation of the body n associated with each activation of a body is storage for the variables declared in the body called an activation record

3 Mapping or Binding Times n Compile n Activation n Run

4 Compile Time n Binding of name occurrences to declarations is defined in terms of lexical context # include int i; void main() { int i; for(i=0; i<4; i++) printf(“I is %d\n”, i); }

5 Activation Time n Binding of declarations to locations is done at activation time - this is important in recursive procedures Location Name occurrence DeclarationValue scopeactivationstate

6 Run Time n The binding of locations to values is done dynamically at run time and can be changed by assignments

7 Control Flow Between Activations n In a sequential language, one procedure at at a time n P calls Q : P is put on hold, Q gets activated and when finishes execution resumes with P n coroutines - suspend execution, return back to caller, and then resume execution later from where they were suspended example the classic producer-consumer application

8 Activation trees n Nodes in the tree represent activations n activation trees and the structure chart are closely related.

9 Elements of an Activation Record Control link Access link Saved state Parameters Function result Local variables Points to the activation record of the caller Static link, used to implement lexically scoped languages

10 Results can be different under lexical and dynamic scope n Lexical - pointer to the block that contains declaration n dynamic - follow the control links for the nearest binding n See program 15.4 again n produces ‘LL’ under lexical n produces ‘LD’ under dynamic

11 Heap n Storage spot for activation records n the records stay here as long as they are needed n pieces are allocated and freed in some relatively unstructured manner n problems of storage allocation, recovery, compaction and reuse may be severe n garbage collection - technique to reclaim storage that is no longer needed

12 Stack n Activation records held in a stack n storage reused efficiently n storage is allocated when activation begins and released when ends n stack imposes restrictions on language design - functions as parameters

13 Memory Layout Code Static global data Stack local data Heap dynamic data

14 Dangling Pointers n A pointer that refers to storage that is being used for another purpose n (see page 186 for example)

15 Displays n Optimization technique for obtaining faster access to nonlocals n array of pointers to activation records, indexed by lexical nesting depth

16 Summary of Procedures n Before there were programming languages there were procedures n giving a name to a piece of code n when called->activated n when activated where does it get its information n from names-> declarations->storage locations-> values


Download ppt "Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage."

Similar presentations


Ads by Google