The length of the static chain needed to reach the correct activation record instance for a nonlocal reference to a variable x is exactly the difference between the static_depth of the subprogram containing the reference to x and the static_depth of the subprogram containing the declaration for x. This dif- ference is called the nesting_depth, or chain_offset, of the reference. The actual reference can be represented by an ordered pair of integers (chain_offset, local_offset), where chain_offset is the number of links to the correct activa- tion record instance (local_offset is described in Section 10.3.2). For example, consider the following skeletal Python program: + Global scope def f1(): def f2(): def 13(): # end of f3 + end of f2 + end of fi The static_depths of the global scope, r1, 12, and r3 are 0, 1, 2, and 3, respec- tively. If procedure f3 references a variable declared in f1, the chain_offset of that reference would be 2 (static_depth of 13 minus the static_depth of r1). If procedure f3 references a variable declared in f2, the chain_offset of that reference would be 1. References to locals can be handled using the same mech- activation record instance of the subprogram where the variable was declared as the base address, the EP is used. To illustrate the complete process of nonlocal accesses, consider the fol- lowing skeletal JavaScript program: function main(){ var x; function bigsub () { var a, b, c; function subl { var a, d; a - b + c; ... } // end of subl function sub2 (x) { var b, e; function sub3 () { var c, e; subl (); e = b + a; <- } // end of sub3 sub3 () ; a - d + e; <-- } // end of sub2 sub2 (7); } // end of bigsub bigsub(); } // end of main The sequence of procedure calls is main calls bigsub bigsub calls sub2 sub2 calls sub3 sub3 calls subl The stack situation when execution first arrives at point 1 in this program is shown in Figure 10.9. At position 1 in procedure sub1, the reference is to the local variable, a, not to the nonlocal variable a from bigsub. This reference to a has the chain_off- set/local_offset pair (0, 3). The reference to b is to the nonlocal b from bigsub. It can be represented by the pair (1,4). The local_offset is 4, because a 3 offset Figure 10.9 Stack contents at Local Top position 1 in the program main Local ARI for Dynamic link subl Static link Return (to sub3) Local Local ARI for Dynamic link sub3 Static link Return (to sub2) Local Local ь ARI for Parameter х sub2 Dynamic link Static link Retum (to bigsub) Local Local ARI for Local bigsub Dynamic link Static link Return (to main) ARI for main_2 Local ARI = activation record instance
The length of the static chain needed to reach the correct activation record instance for a nonlocal reference to a variable x is exactly the difference between the static_depth of the subprogram containing the reference to x and the static_depth of the subprogram containing the declaration for x. This dif- ference is called the nesting_depth, or chain_offset, of the reference. The actual reference can be represented by an ordered pair of integers (chain_offset, local_offset), where chain_offset is the number of links to the correct activa- tion record instance (local_offset is described in Section 10.3.2). For example, consider the following skeletal Python program: + Global scope def f1(): def f2(): def 13(): # end of f3 + end of f2 + end of fi The static_depths of the global scope, r1, 12, and r3 are 0, 1, 2, and 3, respec- tively. If procedure f3 references a variable declared in f1, the chain_offset of that reference would be 2 (static_depth of 13 minus the static_depth of r1). If procedure f3 references a variable declared in f2, the chain_offset of that reference would be 1. References to locals can be handled using the same mech- activation record instance of the subprogram where the variable was declared as the base address, the EP is used. To illustrate the complete process of nonlocal accesses, consider the fol- lowing skeletal JavaScript program: function main(){ var x; function bigsub () { var a, b, c; function subl { var a, d; a - b + c; ... } // end of subl function sub2 (x) { var b, e; function sub3 () { var c, e; subl (); e = b + a; <- } // end of sub3 sub3 () ; a - d + e; <-- } // end of sub2 sub2 (7); } // end of bigsub bigsub(); } // end of main The sequence of procedure calls is main calls bigsub bigsub calls sub2 sub2 calls sub3 sub3 calls subl The stack situation when execution first arrives at point 1 in this program is shown in Figure 10.9. At position 1 in procedure sub1, the reference is to the local variable, a, not to the nonlocal variable a from bigsub. This reference to a has the chain_off- set/local_offset pair (0, 3). The reference to b is to the nonlocal b from bigsub. It can be represented by the pair (1,4). The local_offset is 4, because a 3 offset Figure 10.9 Stack contents at Local Top position 1 in the program main Local ARI for Dynamic link subl Static link Return (to sub3) Local Local ARI for Dynamic link sub3 Static link Return (to sub2) Local Local ь ARI for Parameter х sub2 Dynamic link Static link Retum (to bigsub) Local Local ARI for Local bigsub Dynamic link Static link Return (to main) ARI for main_2 Local ARI = activation record instance
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
In chapter 10, 'Concepts of
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education