Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
-
Upload
shanon-wells -
Category
Documents
-
view
225 -
download
8
Transcript of Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
![Page 1: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/1.jpg)
Chapter 5:Programming Languages
and Constructs by Ravi Sethi
Activation Records
Dolores Zage
![Page 2: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/2.jpg)
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
![Page 3: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/3.jpg)
Mapping or Binding Times
Compile Activation Run
![Page 4: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/4.jpg)
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);
}
![Page 5: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/5.jpg)
Activation Time
Binding of declarations to locations is done at activation time - this is important in recursive procedures
LocationName occurrence
Declaration Value
scope activation state
![Page 6: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/6.jpg)
Run Time
The binding of locations to values is done dynamically at run time and can be changed by assignments
![Page 7: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/7.jpg)
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
![Page 8: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/8.jpg)
Activation trees
Nodes in the tree represent activations activation trees and the structure chart are
closely related.
![Page 9: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/9.jpg)
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
![Page 10: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/10.jpg)
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
![Page 11: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/11.jpg)
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
![Page 12: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/12.jpg)
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
![Page 13: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/13.jpg)
Memory Layout
Code
Static global data
Stack local data
Heap dynamic data
![Page 14: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/14.jpg)
Dangling Pointers
A pointer that refers to storage that is being used for another purpose
(see page 186 for example)
![Page 15: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/15.jpg)
Displays
Optimization technique for obtaining faster access to nonlocals
array of pointers to activation records, indexed by lexical nesting depth
![Page 16: Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.](https://reader036.fdocuments.in/reader036/viewer/2022071715/56649eba5503460f94bc1a43/html5/thumbnails/16.jpg)
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