SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Run-Time EnvironmentsRun Time Environments
TCS-502
Compiler Design
P K Singh M M M E C GKP RTSM-1
Run-Time Environments
• How do we allocate the space for the generated target code and the data 
object of our source programs?
• The places of the data objects that can be determined at compile time will beThe places  of the data objects that can be determined at compile time will be 
allocated statically.
• But the places for the some of data objects will be allocated at run‐time.
• The allocation of de‐allocation of the data objects is managed by the run‐time 
support package.
– run‐time support package is loaded together with the generate target code.
– the structure of the run‐time support package depends on the semantics of the 
programming language (especially the semantics of procedures in that language).
• Each execution of a procedure is called as activation of that procedure.p f p
P K Singh M M M E C GKP RTSM-2
Procedure Activations
• An execution of a procedure starts at the beginning of the procedure body; 
• When the procedure is completed, it returns the control to the point immediately 
after the place where that procedure is called.
• Each execution of a procedure is called as its activation.
Lif ti f ti ti f d i th f th t b t th• Lifetime of an activation of a procedure is the sequence of the steps between the 
first and the last steps in the execution of that procedure  (including the other 
procedures called by that procedure).
• If a and b are procedure activations, then their lifetimes are either non‐overlapping 
or are nested.
• If a procedure is recursive a new activation can begin before an earlier activation of• If a procedure is recursive,  a new activation can begin before an earlier activation of 
the same procedure has ended.
P K Singh M M M E C GKP RTSM-3
Activation Tree
• We can use a tree (called activation tree) to show the way control 
enters and leaves activations.
• In an activation tree:
– Each node represents an activation of a procedure.
– The root represents the activation of the main program.
h d i f h d b iff h l fl f– The node a is a parent of the node b iff the control flows from a 
to b.
– The node a is left to to the node b iff the lifetime of a occursThe node a is left to to the node b iff the lifetime of a occurs 
before the lifetime of b.
P K Singh M M M E C GKP RTSM-4
Activation Tree (cont.)
program main; enter main
procedure s; enter pp p
begin ... end; enter q
procedure p; exit q
dprocedure q; enter s
begin ... end; exit s
begin q; s; end; exit pbegin q; s; end; exit p
begin p; s; end; enter s
exit s
exit main
A Nested Structure
P K Singh M M M E C GKP RTSM-5
A Nested Structure
Activation Tree (cont.)
mainmain
p sp s
q sq
P K Singh M M M E C GKP RTSM-6
Procedure Activations
program sort(input, output)
var a : array [0..10] of integer;
procedure readarray;
var i : integer;
b i
Activations:
begin sortbegin
for i := 1 to 9 do read(a[i])
end;
function partition(y, z : integer) : integer
var i, j, x, v : integer;
begin sort
enter readarray
leave readarray
enter quicksort(1,9)
enter partition(1,9)
begin …
end
procedure quicksort(m, n : integer);
var i : integer;
begin
e te pa t t o ( ,9)
leave partition(1,9)
enter quicksort(1,3)
…
leave quicksort(1,3)begin
if (n > m) then begin
i := partition(m, n);
quicksort(m, i - 1);
quicksort(i + 1, n)
q ( , )
enter quicksort(5,9)
…
leave quicksort(5,9)
leave quicksort(1,9)
end
end;
begin
a[0] := -9999; a[10] := 9999;
readarray;
q ( , )
end sort.
P K Singh M M M E C GKP RTSM-7
readarray;
quicksort(1, 9)
end.
Activation TreesActivation Trees
ss
q(1,9)r
q(1,3)
p(1,3) q(1,0) q(2,3)
p(1,9) q(5,9)
p(5,9) q(5,5) q(7,9)
q(2,1)p(2,3) q(3,3) q(7,7)p(7,9) q(9,9)
P K Singh M M M E C GKP RTSM-8
Control Stack
• The flow of the control in a program corresponds to a depth‐• The flow of the control in a program corresponds to a depth‐
first traversal of the activation tree that:
– starts at the root, ,
– visits a node before  its children, and 
– recursively visits children at each node an a left‐to‐right order.
• A stack (called control stack) can be used to keep track of 
live procedure activations.
– An activation record is pushed onto the control stack as the 
activation starts.
That activation record is popped when that activation ends– That activation record is popped when that activation ends.
• When node n is at the top of the control stack, the stack 
contains the nodes along the path from n to the root
P K Singh M M M E C GKP RTSM-9
contains the nodes along the path from n to the root.
Control Stack
Activations:ControlActivation tree:
s
(1 9)r
Activations:
begin sort
enter readarray
leave readarray
Control
stack:
Activation tree:
s
q(1,9)
q(1,3)p(1,9)
r enter quicksort(1,9)
enter partition(1,9)
leave partition(1,9)
enter quicksort(1,3)
q(1,9)
q(1,3)
q(2,3)
p(1,3) q(1,0) q(2,3)
enter partition(1,3)
leave partition(1,3)
enter quicksort(1,0)
leave quicksort(1,0)
(2 3)enter quicksort(2,3)
…
P K Singh M M M E C GKP RTSM-10
Variable Scopes
• The same variable name can be used in the different parts of the 
program.
• The scope rules of the language determine which declaration of a• The scope rules of the language determine which declaration of a 
name applies when the name appears in the program.
• An occurrence of a variable (a name) is:
– local: If that occurrence is in the same procedure in which that name is declared.
– non‐local: Otherwise (ie. it is declared outside of that procedure)
procedure p;
var b:real;
procedure p;procedure p;
var a: integer; a is local
begin a := 1; b := 2; end; b is non-local
begin end;
P K Singh M M M E C GKP RTSM-11
begin ... end;
Run-Time Storage Organization
Code
Memory locations for code are 
determined at compile time.
Static Data Locations of static data can also be 
determined at compile time.
Stack
Data objects allocated at run‐time.
(Activation Records)(Activation Records)
Other dynamically allocated data
Heap
Other dynamically allocated data
objects at run‐time. (For example,
malloc area in C).
P K Singh M M M E C GKP RTSM-12
Activation Records
• Information needed by a single execution of a procedure is 
managed using a contiguous block of storage called 
i i dactivation record.
• An activation record is allocated when a procedure is 
entered, and it is de‐allocated when that procedure exited.
• Size of each field can be determined at compile timeSize of each field can be determined at compile time 
(Although actual location of the activation record is 
determined at run‐time).)
– Except that if the procedure has a local variable and its size depends 
on a parameter, its size is determined at the run time.
P K Singh M M M E C GKP RTSM-13
p
Activation Records (cont.)
return value
The returned value of the called procedure is returned 
in this field to the calling procedure. In practice, we may
use a machine register for the return value.
actual parameters
optional control link
g
The field for actual parameters is used by the calling 
procedure to supply parameters to the called procedure.
Th i l l li k i h i i doptional control link
optional access link
The optional control link points to the activation record 
of the caller.
The optional access link is used to refer to nonlocal data
h ld i h i i d
saved machine status
local data
held in other activation records.
The field for saved machine status holds information about 
the state of the machine before the procedure is called.
temporaries
The field of local data holds data that local to an execution
of a procedure..
Temporay variables is stored in the field of temporaries.
P K Singh M M M E C GKP RTSM-14
Temporay variables is stored in the field of temporaries.
Activation Records (Ex1)
program main;
procedure p;
main
stack
procedure p;
var a:real;
procedure q;
var b:integer;
pbegin ... end;
begin q; end;
procedure s;
var c:integer;
p
a:
var c:integer;
begin ... end;
begin p; s; end; q
main
p
b:
p
q
s
P K Singh M M M E C GKP RTSM-15
q
Activation Records for Recursive Procedures
program main;
procedure p;
function q(a:integer):integer;
main
function q(a:integer):integer;
begin
if (a=1) then q:=1;
else q:=a+q(a-1);
p
end;
begin q(3); end;
begin p; end;
q(3)
a: 3
q(2)
a:2
q(1)
a:1
P K Singh M M M E C GKP RTSM-16
Creation of An Activation Record
• Who allocates an activation record of a procedure?
– Some part of the activation record of a procedure is created bySome part of the activation record of a procedure is created by 
that procedure immediately after that procedure is entered.
– Some part is created by the caller of that procedure before that 
procedure is entered.
• Who deallocates?• Who deallocates?
– Callee de‐allocates the part allocated by Callee.
– Caller de‐allocates the part allocated by Caller.Caller de allocates the part allocated by Caller. 
P K Singh M M M E C GKP RTSM-17
Creation of An Activation Record (cont.)
return value
actual parameters
ti l t l li k
Caller’s Activation Record
optional control link
optional access link
saved machine status
local data
temporaries
return value
Caller’s Responsibility
C ll ’ A i i R dreturn value
actual parameters
optional control link
Callee’s Activation Record
optional access link
saved machine status
local data
Callee’s Responsibility
P K Singh M M M E C GKP RTSM-18
temporaries
Variable Length Data
return value
actual parameters
ti l t l li k
Variable length data is allocated after
optional control link
optional access link
saved machine status
temporaries, and there is a link to from
local data to that array.
local data
pointer a
pointer b
temporaries
array a
array b
P K Singh M M M E C GKP RTSM-19
Dangling Reference
• Whenever a storage is de-allocated, the problem of dangling references
may accur.y
main () {
i *int *p;
p = dangle();
}
int *dangle*() {
int i=2;
return &i;return &i;
}
P K Singh M M M E C GKP RTSM-20
Access to Nonlocal Names
• Scope rules of a language determine the treatment of references to 
nonlocal names.
• Scope Rules:
– Lexical Scope (Static Scope)
• Determines the declaration that applies to a name by examining 
the program text alone at compile‐time.
• Most closely nested rule is used• Most‐closely nested rule is used.
• Pascal, C, ..
– Dynamic ScopeDynamic Scope
• Determines the declaration that applies to a name at run‐time.
• Lisp, APL, ...
P K Singh M M M E C GKP RTSM-21
Lexical Scope
• The scope of a declaration in a block‐structured language is given 
by the mostly closed rule.y y
• Each procedure (block) will have its own activation record.
– procedure
begin end blocks– begin‐end blocks 
• (treated same as procedure without creating most part of its activation record)
• A procedure may access to a nonlocal name using:
– access links in activation records, or
– displays (an efficient way to access to nonlocal names)
P K Singh M M M E C GKP RTSM-22
Access Links
program main;
var a:int;
procedure p;
main
access link
p p;
var d:int;
begin a:=1; end;
procedure q(i:int);
a:
q(1)
access link
var b:int;
procedure s;
var c:int;
i,b:
q(0)
access link
Access
Links
begin p; end;
begin
if (i<>0) then q(i-1)
else s;
i,b:
s
access linkelse s;
end;
begin q(1); end;
c:
p
access link
P K Singh M M M E C GKP RTSM-23
access link
d:
Access Links
s s s s
a x
q(1,9)
a x
q(1,9)
a x
q(1,9)
a x
q(1,9)q(1,9)
access
k v
q(1,9)
access
k v
q(1 3)
q(1,9)
access
k v
q(1 3)
q(1,9)
access
k v
q(1 3)q(1,3)
access
k v
q(1,3)
access
k v
p(1 3)
q(1,3)
access
k v
p(1 3)p(1,3)
access
i j
p(1,3)
access
i j
e(1 3)
24
e(1,3)
access
Procedure Parameters
program main;
procedure p(procedure a);
main
access link
procedure p(procedure a);
begin a; end;
procedure q;
procedure s;
q
access linkprocedure s;
begin ... end;
begin p(s) end;
begin q; end;
access link
p
li k
g q
access link
sAccess links must be passed with
access link
p
procedure parameters.
P K Singh M M M E C GKP RTSM-25
Displays
• An array of pointers to activation records can be used to access
activation recordsactivation records.
• This array is called as displays.
• For each level, there will be an array entry.
1:
2
Current activation record at level 1
C t ti ti d t l l 22:
3:
Current activation record at level 2
Current activation record at level 3
P K Singh M M M E C GKP RTSM-26
Accessing Nonlocal Variables
program main;
var a:int;
main
access link
addrC := offsetC(currAR)
t := *currARvar a:int;
procedure p;
var b:int;
begin q; end;
a:
p
addrB := offsetB(t)
t := *t
addrA := offsetA(t)begin q; end;
procedure q();
var c:int;
begin
p
access link
b:
ADD addrA,addrB,addrC
g
c:=a+b;
end;
begin p; end;
q
access link
c:
P K Singh M M M E C GKP RTSM-27
Accessing Nonlocal Variables using Display
program main;
var a:int;
main
access link
addrC := offsetC(D[3])
addrB := offsetB(D[2])
D[1]
var a:int;
procedure p;
var b:int;
begin q; end;
a:
p
addrB : offsetB(D[2])
addrA := offsetA(D[1])
ADD addrA,addrB,addrC
begin q; end;
procedure q();
var c:int;
begin
p
access link
b:
D[2]
g
c:=a+b;
end;
begin p; end;
q
access link
D[3]
c:
P K Singh M M M E C GKP RTSM-28
Parameter Passing Methods
• Call-by-value
• Call-by-referenceCall by reference
• Call-by-name (used by Algol)
P K Singh M M M E C GKP RTSM-29
Parameter Passing Methods
• Call-by-value: evaluate actual parameters and enter r-values
in activation record
• Call-by-reference: enter pointer to the storage of the actual
parameter
• Copy-restore (value-result): evaluate actual parameters and
enter r-values, after the call copy r-values of formal
parameters into actualsparameters into actuals
• Call-by-name: use a form of in-line code expansion (thunk) to
evaluate parameterseva uate pa a ete s
30
SOME OTHER ISSUES
• Symbol Tables hold scope information.
• Dynamic Scope:
– uses control link (similar to access links)
• Dynamic Storage Allocation (Heap Management)
different allocation techniques– different allocation techniques
P K Singh M M M E C GKP RTSM-31

Weitere ähnliche Inhalte

Was ist angesagt?

Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)bolovv
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generationIffat Anjum
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksEelco Visser
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignmentKarthi Keyan
 
Cupdf.com introduction to-data-structures-and-algorithm
Cupdf.com introduction to-data-structures-and-algorithmCupdf.com introduction to-data-structures-and-algorithm
Cupdf.com introduction to-data-structures-and-algorithmTarikuDabala1
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisEelco Visser
 
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...vtunotesbysree
 
Basic Structure of a Computer System
Basic Structure of a Computer SystemBasic Structure of a Computer System
Basic Structure of a Computer SystemAmirthavalli Senthil
 
Instruction Level Parallelism Compiler optimization Techniques Anna Universit...
Instruction Level Parallelism Compiler optimization Techniques Anna Universit...Instruction Level Parallelism Compiler optimization Techniques Anna Universit...
Instruction Level Parallelism Compiler optimization Techniques Anna Universit...Dr.K. Thirunadana Sikamani
 
Multi layered perceptron (mlp)
Multi layered perceptron (mlp)Multi layered perceptron (mlp)
Multi layered perceptron (mlp)Handson System
 
Algorithm & data structure lec2
Algorithm & data structure lec2Algorithm & data structure lec2
Algorithm & data structure lec2Abdul Khan
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithmRicha Kumari
 

Was ist angesagt? (20)

Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Cupdf.com introduction to-data-structures-and-algorithm
Cupdf.com introduction to-data-structures-and-algorithmCupdf.com introduction to-data-structures-and-algorithm
Cupdf.com introduction to-data-structures-and-algorithm
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
 
Basic Structure of a Computer System
Basic Structure of a Computer SystemBasic Structure of a Computer System
Basic Structure of a Computer System
 
Instruction Level Parallelism Compiler optimization Techniques Anna Universit...
Instruction Level Parallelism Compiler optimization Techniques Anna Universit...Instruction Level Parallelism Compiler optimization Techniques Anna Universit...
Instruction Level Parallelism Compiler optimization Techniques Anna Universit...
 
Multi layered perceptron (mlp)
Multi layered perceptron (mlp)Multi layered perceptron (mlp)
Multi layered perceptron (mlp)
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Algorithm & data structure lec2
Algorithm & data structure lec2Algorithm & data structure lec2
Algorithm & data structure lec2
 
Parallel sorting algorithm
Parallel sorting algorithmParallel sorting algorithm
Parallel sorting algorithm
 

Ähnlich wie Run time

Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environmentIffat Anjum
 
Runtimeenvironment
RuntimeenvironmentRuntimeenvironment
RuntimeenvironmentAnusuya123
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPIyaman dua
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorMasahiko Sawada
 
RTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffffRTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffffadugnanegero
 
Concurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfConcurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfDenys Goldiner
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
008. PROGRAM EFFICIENCY computer science.pdf
008. PROGRAM EFFICIENCY computer science.pdf008. PROGRAM EFFICIENCY computer science.pdf
008. PROGRAM EFFICIENCY computer science.pdfomchoubey297
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitorssgpraju
 
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache FlinkTzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache FlinkVerverica
 
Postgres Vision 2018: Making Postgres Even Faster
Postgres Vision 2018: Making Postgres Even FasterPostgres Vision 2018: Making Postgres Even Faster
Postgres Vision 2018: Making Postgres Even FasterEDB
 
State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...
State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...
State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...Paris Carbone
 
Algorithm analysis.pptx
Algorithm analysis.pptxAlgorithm analysis.pptx
Algorithm analysis.pptxDrBashirMSaad
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321Teddy Hsiung
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxstilliegeorgiana
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxdenneymargareta
 

Ähnlich wie Run time (20)

Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Runtimeenvironment
RuntimeenvironmentRuntimeenvironment
Runtimeenvironment
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributor
 
RTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffffRTOS Material hfffffffffffffffffffffffffffffffffffff
RTOS Material hfffffffffffffffffffffffffffffffffffff
 
Concurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdfConcurrency in Go by Denys Goldiner.pdf
Concurrency in Go by Denys Goldiner.pdf
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
OSCh7
OSCh7OSCh7
OSCh7
 
OS_Ch7
OS_Ch7OS_Ch7
OS_Ch7
 
008. PROGRAM EFFICIENCY computer science.pdf
008. PROGRAM EFFICIENCY computer science.pdf008. PROGRAM EFFICIENCY computer science.pdf
008. PROGRAM EFFICIENCY computer science.pdf
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
So you think you can stream.pptx
So you think you can stream.pptxSo you think you can stream.pptx
So you think you can stream.pptx
 
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache FlinkTzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
Tzu-Li (Gordon) Tai - Stateful Stream Processing with Apache Flink
 
Postgres Vision 2018: Making Postgres Even Faster
Postgres Vision 2018: Making Postgres Even FasterPostgres Vision 2018: Making Postgres Even Faster
Postgres Vision 2018: Making Postgres Even Faster
 
State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...
State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...
State Management in Apache Flink : Consistent Stateful Distributed Stream Pro...
 
Algorithm analysis.pptx
Algorithm analysis.pptxAlgorithm analysis.pptx
Algorithm analysis.pptx
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
 
Appsec obfuscator reloaded
Appsec obfuscator reloadedAppsec obfuscator reloaded
Appsec obfuscator reloaded
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 

Mehr von Royalzig Luxury Furniture

A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...
A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...
A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...Royalzig Luxury Furniture
 
India's Luxury Furniture Brand Royalzig setting-Up a New Production Unit
India's Luxury Furniture Brand Royalzig setting-Up a New Production UnitIndia's Luxury Furniture Brand Royalzig setting-Up a New Production Unit
India's Luxury Furniture Brand Royalzig setting-Up a New Production UnitRoyalzig Luxury Furniture
 
Hand Carved Luxury & Designer Wooden arm chair
Hand Carved Luxury & Designer Wooden arm chairHand Carved Luxury & Designer Wooden arm chair
Hand Carved Luxury & Designer Wooden arm chairRoyalzig Luxury Furniture
 
Hand Carved Luxury & Designer Wooden Dining Table
Hand Carved Luxury & Designer Wooden Dining Table Hand Carved Luxury & Designer Wooden Dining Table
Hand Carved Luxury & Designer Wooden Dining Table Royalzig Luxury Furniture
 
Hand Carved Luxury & Designer Wooden sofa set
Hand Carved Luxury & Designer Wooden sofa setHand Carved Luxury & Designer Wooden sofa set
Hand Carved Luxury & Designer Wooden sofa setRoyalzig Luxury Furniture
 
Royalzig Hand Carved Luxury & Designer Wood Bed
Royalzig Hand Carved Luxury & Designer Wood BedRoyalzig Hand Carved Luxury & Designer Wood Bed
Royalzig Hand Carved Luxury & Designer Wood BedRoyalzig Luxury Furniture
 

Mehr von Royalzig Luxury Furniture (20)

A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...
A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...
A Glimpse of Beautiful Hand-Carved Luxury Italian Furniture Photos from Royal...
 
French Style Slim Carving Bedroom Sets
French Style Slim Carving Bedroom SetsFrench Style Slim Carving Bedroom Sets
French Style Slim Carving Bedroom Sets
 
India's Luxury Furniture Brand Royalzig setting-Up a New Production Unit
India's Luxury Furniture Brand Royalzig setting-Up a New Production UnitIndia's Luxury Furniture Brand Royalzig setting-Up a New Production Unit
India's Luxury Furniture Brand Royalzig setting-Up a New Production Unit
 
Luxury furniture manufacturer in india
Luxury furniture manufacturer in indiaLuxury furniture manufacturer in india
Luxury furniture manufacturer in india
 
bone inlay hand carved luxury table
bone inlay hand carved luxury table bone inlay hand carved luxury table
bone inlay hand carved luxury table
 
Hand Carved Luxury & Designer Wooden arm chair
Hand Carved Luxury & Designer Wooden arm chairHand Carved Luxury & Designer Wooden arm chair
Hand Carved Luxury & Designer Wooden arm chair
 
beautiful hand carved dressing table
beautiful hand carved dressing table  beautiful hand carved dressing table
beautiful hand carved dressing table
 
Hand Carved Luxury & Designer Wooden Dining Table
Hand Carved Luxury & Designer Wooden Dining Table Hand Carved Luxury & Designer Wooden Dining Table
Hand Carved Luxury & Designer Wooden Dining Table
 
Hand Carved Luxury & Designer Wooden sofa set
Hand Carved Luxury & Designer Wooden sofa setHand Carved Luxury & Designer Wooden sofa set
Hand Carved Luxury & Designer Wooden sofa set
 
Royalzig Hand Carved Luxury & Designer Wood Bed
Royalzig Hand Carved Luxury & Designer Wood BedRoyalzig Hand Carved Luxury & Designer Wood Bed
Royalzig Hand Carved Luxury & Designer Wood Bed
 
hand carved luxury wedding throne
hand carved luxury wedding thronehand carved luxury wedding throne
hand carved luxury wedding throne
 
Hand carved Luxury wood divan
Hand carved Luxury wood divanHand carved Luxury wood divan
Hand carved Luxury wood divan
 
Royalzig luxury furniture
Royalzig luxury furnitureRoyalzig luxury furniture
Royalzig luxury furniture
 
Royalzigppt 004
Royalzigppt 004Royalzigppt 004
Royalzigppt 004
 
Royalzig high end furniture
Royalzig high end furnitureRoyalzig high end furniture
Royalzig high end furniture
 
Royalzigppt 002
Royalzigppt 002Royalzigppt 002
Royalzigppt 002
 
Transcript
TranscriptTranscript
Transcript
 
Topdown parsing
Topdown parsingTopdown parsing
Topdown parsing
 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
 
Run time
Run timeRun time
Run time
 

Kürzlich hochgeladen

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 

Kürzlich hochgeladen (20)

Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 

Run time

  • 1. Run-Time EnvironmentsRun Time Environments TCS-502 Compiler Design P K Singh M M M E C GKP RTSM-1
  • 2. Run-Time Environments • How do we allocate the space for the generated target code and the data  object of our source programs? • The places of the data objects that can be determined at compile time will beThe places  of the data objects that can be determined at compile time will be  allocated statically. • But the places for the some of data objects will be allocated at run‐time. • The allocation of de‐allocation of the data objects is managed by the run‐time  support package. – run‐time support package is loaded together with the generate target code. – the structure of the run‐time support package depends on the semantics of the  programming language (especially the semantics of procedures in that language). • Each execution of a procedure is called as activation of that procedure.p f p P K Singh M M M E C GKP RTSM-2
  • 3. Procedure Activations • An execution of a procedure starts at the beginning of the procedure body;  • When the procedure is completed, it returns the control to the point immediately  after the place where that procedure is called. • Each execution of a procedure is called as its activation. Lif ti f ti ti f d i th f th t b t th• Lifetime of an activation of a procedure is the sequence of the steps between the  first and the last steps in the execution of that procedure  (including the other  procedures called by that procedure). • If a and b are procedure activations, then their lifetimes are either non‐overlapping  or are nested. • If a procedure is recursive a new activation can begin before an earlier activation of• If a procedure is recursive,  a new activation can begin before an earlier activation of  the same procedure has ended. P K Singh M M M E C GKP RTSM-3
  • 4. Activation Tree • We can use a tree (called activation tree) to show the way control  enters and leaves activations. • In an activation tree: – Each node represents an activation of a procedure. – The root represents the activation of the main program. h d i f h d b iff h l fl f– The node a is a parent of the node b iff the control flows from a  to b. – The node a is left to to the node b iff the lifetime of a occursThe node a is left to to the node b iff the lifetime of a occurs  before the lifetime of b. P K Singh M M M E C GKP RTSM-4
  • 5. Activation Tree (cont.) program main; enter main procedure s; enter pp p begin ... end; enter q procedure p; exit q dprocedure q; enter s begin ... end; exit s begin q; s; end; exit pbegin q; s; end; exit p begin p; s; end; enter s exit s exit main A Nested Structure P K Singh M M M E C GKP RTSM-5 A Nested Structure
  • 6. Activation Tree (cont.) mainmain p sp s q sq P K Singh M M M E C GKP RTSM-6
  • 7. Procedure Activations program sort(input, output) var a : array [0..10] of integer; procedure readarray; var i : integer; b i Activations: begin sortbegin for i := 1 to 9 do read(a[i]) end; function partition(y, z : integer) : integer var i, j, x, v : integer; begin sort enter readarray leave readarray enter quicksort(1,9) enter partition(1,9) begin … end procedure quicksort(m, n : integer); var i : integer; begin e te pa t t o ( ,9) leave partition(1,9) enter quicksort(1,3) … leave quicksort(1,3)begin if (n > m) then begin i := partition(m, n); quicksort(m, i - 1); quicksort(i + 1, n) q ( , ) enter quicksort(5,9) … leave quicksort(5,9) leave quicksort(1,9) end end; begin a[0] := -9999; a[10] := 9999; readarray; q ( , ) end sort. P K Singh M M M E C GKP RTSM-7 readarray; quicksort(1, 9) end.
  • 8. Activation TreesActivation Trees ss q(1,9)r q(1,3) p(1,3) q(1,0) q(2,3) p(1,9) q(5,9) p(5,9) q(5,5) q(7,9) q(2,1)p(2,3) q(3,3) q(7,7)p(7,9) q(9,9) P K Singh M M M E C GKP RTSM-8
  • 9. Control Stack • The flow of the control in a program corresponds to a depth‐• The flow of the control in a program corresponds to a depth‐ first traversal of the activation tree that: – starts at the root, , – visits a node before  its children, and  – recursively visits children at each node an a left‐to‐right order. • A stack (called control stack) can be used to keep track of  live procedure activations. – An activation record is pushed onto the control stack as the  activation starts. That activation record is popped when that activation ends– That activation record is popped when that activation ends. • When node n is at the top of the control stack, the stack  contains the nodes along the path from n to the root P K Singh M M M E C GKP RTSM-9 contains the nodes along the path from n to the root.
  • 10. Control Stack Activations:ControlActivation tree: s (1 9)r Activations: begin sort enter readarray leave readarray Control stack: Activation tree: s q(1,9) q(1,3)p(1,9) r enter quicksort(1,9) enter partition(1,9) leave partition(1,9) enter quicksort(1,3) q(1,9) q(1,3) q(2,3) p(1,3) q(1,0) q(2,3) enter partition(1,3) leave partition(1,3) enter quicksort(1,0) leave quicksort(1,0) (2 3)enter quicksort(2,3) … P K Singh M M M E C GKP RTSM-10
  • 11. Variable Scopes • The same variable name can be used in the different parts of the  program. • The scope rules of the language determine which declaration of a• The scope rules of the language determine which declaration of a  name applies when the name appears in the program. • An occurrence of a variable (a name) is: – local: If that occurrence is in the same procedure in which that name is declared. – non‐local: Otherwise (ie. it is declared outside of that procedure) procedure p; var b:real; procedure p;procedure p; var a: integer; a is local begin a := 1; b := 2; end; b is non-local begin end; P K Singh M M M E C GKP RTSM-11 begin ... end;
  • 12. Run-Time Storage Organization Code Memory locations for code are  determined at compile time. Static Data Locations of static data can also be  determined at compile time. Stack Data objects allocated at run‐time. (Activation Records)(Activation Records) Other dynamically allocated data Heap Other dynamically allocated data objects at run‐time. (For example, malloc area in C). P K Singh M M M E C GKP RTSM-12
  • 13. Activation Records • Information needed by a single execution of a procedure is  managed using a contiguous block of storage called  i i dactivation record. • An activation record is allocated when a procedure is  entered, and it is de‐allocated when that procedure exited. • Size of each field can be determined at compile timeSize of each field can be determined at compile time  (Although actual location of the activation record is  determined at run‐time).) – Except that if the procedure has a local variable and its size depends  on a parameter, its size is determined at the run time. P K Singh M M M E C GKP RTSM-13 p
  • 14. Activation Records (cont.) return value The returned value of the called procedure is returned  in this field to the calling procedure. In practice, we may use a machine register for the return value. actual parameters optional control link g The field for actual parameters is used by the calling  procedure to supply parameters to the called procedure. Th i l l li k i h i i doptional control link optional access link The optional control link points to the activation record  of the caller. The optional access link is used to refer to nonlocal data h ld i h i i d saved machine status local data held in other activation records. The field for saved machine status holds information about  the state of the machine before the procedure is called. temporaries The field of local data holds data that local to an execution of a procedure.. Temporay variables is stored in the field of temporaries. P K Singh M M M E C GKP RTSM-14 Temporay variables is stored in the field of temporaries.
  • 15. Activation Records (Ex1) program main; procedure p; main stack procedure p; var a:real; procedure q; var b:integer; pbegin ... end; begin q; end; procedure s; var c:integer; p a: var c:integer; begin ... end; begin p; s; end; q main p b: p q s P K Singh M M M E C GKP RTSM-15 q
  • 16. Activation Records for Recursive Procedures program main; procedure p; function q(a:integer):integer; main function q(a:integer):integer; begin if (a=1) then q:=1; else q:=a+q(a-1); p end; begin q(3); end; begin p; end; q(3) a: 3 q(2) a:2 q(1) a:1 P K Singh M M M E C GKP RTSM-16
  • 17. Creation of An Activation Record • Who allocates an activation record of a procedure? – Some part of the activation record of a procedure is created bySome part of the activation record of a procedure is created by  that procedure immediately after that procedure is entered. – Some part is created by the caller of that procedure before that  procedure is entered. • Who deallocates?• Who deallocates? – Callee de‐allocates the part allocated by Callee. – Caller de‐allocates the part allocated by Caller.Caller de allocates the part allocated by Caller.  P K Singh M M M E C GKP RTSM-17
  • 18. Creation of An Activation Record (cont.) return value actual parameters ti l t l li k Caller’s Activation Record optional control link optional access link saved machine status local data temporaries return value Caller’s Responsibility C ll ’ A i i R dreturn value actual parameters optional control link Callee’s Activation Record optional access link saved machine status local data Callee’s Responsibility P K Singh M M M E C GKP RTSM-18 temporaries
  • 19. Variable Length Data return value actual parameters ti l t l li k Variable length data is allocated after optional control link optional access link saved machine status temporaries, and there is a link to from local data to that array. local data pointer a pointer b temporaries array a array b P K Singh M M M E C GKP RTSM-19
  • 20. Dangling Reference • Whenever a storage is de-allocated, the problem of dangling references may accur.y main () { i *int *p; p = dangle(); } int *dangle*() { int i=2; return &i;return &i; } P K Singh M M M E C GKP RTSM-20
  • 21. Access to Nonlocal Names • Scope rules of a language determine the treatment of references to  nonlocal names. • Scope Rules: – Lexical Scope (Static Scope) • Determines the declaration that applies to a name by examining  the program text alone at compile‐time. • Most closely nested rule is used• Most‐closely nested rule is used. • Pascal, C, .. – Dynamic ScopeDynamic Scope • Determines the declaration that applies to a name at run‐time. • Lisp, APL, ... P K Singh M M M E C GKP RTSM-21
  • 22. Lexical Scope • The scope of a declaration in a block‐structured language is given  by the mostly closed rule.y y • Each procedure (block) will have its own activation record. – procedure begin end blocks– begin‐end blocks  • (treated same as procedure without creating most part of its activation record) • A procedure may access to a nonlocal name using: – access links in activation records, or – displays (an efficient way to access to nonlocal names) P K Singh M M M E C GKP RTSM-22
  • 23. Access Links program main; var a:int; procedure p; main access link p p; var d:int; begin a:=1; end; procedure q(i:int); a: q(1) access link var b:int; procedure s; var c:int; i,b: q(0) access link Access Links begin p; end; begin if (i<>0) then q(i-1) else s; i,b: s access linkelse s; end; begin q(1); end; c: p access link P K Singh M M M E C GKP RTSM-23 access link d:
  • 24. Access Links s s s s a x q(1,9) a x q(1,9) a x q(1,9) a x q(1,9)q(1,9) access k v q(1,9) access k v q(1 3) q(1,9) access k v q(1 3) q(1,9) access k v q(1 3)q(1,3) access k v q(1,3) access k v p(1 3) q(1,3) access k v p(1 3)p(1,3) access i j p(1,3) access i j e(1 3) 24 e(1,3) access
  • 25. Procedure Parameters program main; procedure p(procedure a); main access link procedure p(procedure a); begin a; end; procedure q; procedure s; q access linkprocedure s; begin ... end; begin p(s) end; begin q; end; access link p li k g q access link sAccess links must be passed with access link p procedure parameters. P K Singh M M M E C GKP RTSM-25
  • 26. Displays • An array of pointers to activation records can be used to access activation recordsactivation records. • This array is called as displays. • For each level, there will be an array entry. 1: 2 Current activation record at level 1 C t ti ti d t l l 22: 3: Current activation record at level 2 Current activation record at level 3 P K Singh M M M E C GKP RTSM-26
  • 27. Accessing Nonlocal Variables program main; var a:int; main access link addrC := offsetC(currAR) t := *currARvar a:int; procedure p; var b:int; begin q; end; a: p addrB := offsetB(t) t := *t addrA := offsetA(t)begin q; end; procedure q(); var c:int; begin p access link b: ADD addrA,addrB,addrC g c:=a+b; end; begin p; end; q access link c: P K Singh M M M E C GKP RTSM-27
  • 28. Accessing Nonlocal Variables using Display program main; var a:int; main access link addrC := offsetC(D[3]) addrB := offsetB(D[2]) D[1] var a:int; procedure p; var b:int; begin q; end; a: p addrB : offsetB(D[2]) addrA := offsetA(D[1]) ADD addrA,addrB,addrC begin q; end; procedure q(); var c:int; begin p access link b: D[2] g c:=a+b; end; begin p; end; q access link D[3] c: P K Singh M M M E C GKP RTSM-28
  • 29. Parameter Passing Methods • Call-by-value • Call-by-referenceCall by reference • Call-by-name (used by Algol) P K Singh M M M E C GKP RTSM-29
  • 30. Parameter Passing Methods • Call-by-value: evaluate actual parameters and enter r-values in activation record • Call-by-reference: enter pointer to the storage of the actual parameter • Copy-restore (value-result): evaluate actual parameters and enter r-values, after the call copy r-values of formal parameters into actualsparameters into actuals • Call-by-name: use a form of in-line code expansion (thunk) to evaluate parameterseva uate pa a ete s 30
  • 31. SOME OTHER ISSUES • Symbol Tables hold scope information. • Dynamic Scope: – uses control link (similar to access links) • Dynamic Storage Allocation (Heap Management) different allocation techniques– different allocation techniques P K Singh M M M E C GKP RTSM-31