1 / 16

Chapter 5: Programming Languages and Constructs by Ravi Sethi

Chapter 5: Programming Languages and Constructs by Ravi Sethi. Activation Records Dolores Zage. Activation Records. Each execution of the body is called an activation of the body

urban
Download Presentation

Chapter 5: Programming Languages and Constructs by Ravi Sethi

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. Chapter 5:Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage

  2. Activation Records • Each execution of the body is called an activation of the body • 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 • Compile • Activation • Run

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

  5. Activation Time • Binding of declarations to locations is done at activation time - this is important in recursive procedures Location scope activation state Name occurrence Declaration Value

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

  7. Control Flow Between Activations • In a sequential language, one procedure at at a time • P calls Q : P is put on hold, Q gets activated and when finishes execution resumes with P • 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 • Nodes in the tree represent activations • activation trees and the structure chart are closely related.

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

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

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

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

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

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

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

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

More Related