Chapter 7 Runtime Environments Section 0 Overview 1.Program vs program execution • A program consists of several procedures (functions) • An execution of a program is called as a process • An execution of a program would cause the activation of the related procedures • A name (e.g, a variable name)in a procedure would be related to different data objects Notes: An activation may manipulate data objects allocated for its use.
Chapter 7 Runtime Environments Section 0 Overview. 1.Program vs program execution A program consists of several procedures (functions) An execution of a program is called as a process An execution of a program would cause the activation of the related procedures - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Chapter 7 Runtime Environments Section 0 Overview
1.Program vs program execution • A program consists of several procedures (functions)• An execution of a program is called as a process• An execution of a program would cause the
activation of the related procedures• A name (e.g, a variable name)in a procedure would
be related to different data objects
Notes: An activation may manipulate data objects allocated for its use.
Chapter 7 Runtime Environments Section 0 Overview
2. Allocation and de-allocation of data objects
– Managed by the run-time support package
– Allocation of a data object is just to allocate storage space to the data object relating to the name in the procedure
Notes: The representation of a data object at run time is determined by its type.
Chapter 7 Runtime Environments Section 0 Overview
3.Activation Trees
A tree to depict the control flow enters and leaves activation of a procedure
Enter f(2)Enter f(1)Leave f(1)Enter f(0)Leave f(0)Leave f(2)Leave f(4)
Chapter 7 Runtime Environments Section 0 Overview
4.Control stacks
A stack to keep track of live procedure activations
Chapter 7 Runtime Environments Section 0 Overview
5.Bindings of Names
When an environment associates storage location s with a name x, we say that x is bound to s; the association itself is referred to as a binding of x.
Notes: 1)Even each name is declared once in a program, the same name may denote different object at run time
2)The “ data object” corresponds to a storage location that can hold values
Chapter 7 Runtime Environments Section 0 Overview
5.Bindings of NamesNotes: 3)In programming language semantics,
the term “environment” refers to a function that maps a name to a storage location, and term “state” refers to a function that maps a storage location to the value held there.
environment state
name storage value
Chapter 7 Runtime Environments Section 0 Overview
5.Bindings of Names
Notes: 4)Environments and states are different; an assignment changes the state, but not the environment
5)If x is not of a basic type, the storage s for x may be a collection of memory words
6)A binding is the dynamic counterpart of a declaration
Chapter 7 Runtime Environments Section 0 Overview
5.Factors that determines the run time environment of a program
– Recursive definition
– Local name storage space allocation strategy
– global name storage space allocation strategy
– Parameter passing mechanism
– A function is whether allowed to be a parameter of or return value of a function
– A separate area of run-time memory, called a heap.
– Heap allocation parcels out pieces of contiguous storage, as needed for activation records or other objects. Pieces may be de-allocated in any order.
– Based on the idea of a control stack; storage is organized as a stack, and activation records are pushed and popped as activations begin and end, respectively.
– Storage for the locals in each call of a procedure is contained in the activation record for that call.
– Locals are bound to fresh storage in each activation
4. Stack allocation3)Stack allocation for non-nested procedureint f(int n){ if (n<=1) return 1;else { int t1,t2,t; t1=f(n-1); t2=f(n-2);t=t1+t2; return t} }
…..Activation Record of the function called by Main functionActivation Record of Main functionGlobal Variable Data Area
Storage Organization of C Language
The Form of Activation Record of any a function in C
Unit for Returned Value of functionInternal Temporary Work UnitsLocal Variable Data Storage UnitsFormal parameter Storage UnitsNumber of Formal ParametersReturned Address Caller’s SP (Start Address of caller’s activation record)
3.Call-by-Reference1) also known as call-by-address or call-by-
location.2)implementation
– If an actual parameter is a name or an expression having an l-value, then that l-value itself is passed.
– If the actual parameter is an expression that has no l-value, then the expression is evaluated in a new location, and the address of that location is passed.
Chapter 7 Runtime Environments Section 4 Symbol Tables
1.Functions of symbol tables• Keep track of scope and binding information about
names• Allow us to add new entries and find existing entries
efficiently
Notes: 1)Changes to the table occur if a new name or new information about an existing name is discovered
2)The table may be a linear list or a hash table
3)It is useful for a compiler to be able to grow the symbol table dynamically, if necessary, at compile time
Chapter 7 Runtime Environments Section 4 Symbol Tables
2.Symbol-table entries• Each entry in the symbol table is for the
declaration of a name• Each entry can be implemented as a record
consisting of a sequence of consecutive words of memory
Notes: 1)Information may be entered into the symbol table at various times
2)Attributes of a name are entered in response to declarations