CHAPTER 10 REVIEW
PROBLEMS
1. What is the definition used in this chapter for
“simple” subprograms?
- We begin with the task of implementing simple
subprograms. By “simple” we mean that subprograms cannot be nested and all local
variables are static. Early versions of Fortran were examples of languages that
had this kind of subprograms. The semantics of a call to a “simple” subprogram
requires the following actions:
1. Save the execution status of the current program unit.
2. Compute and pass the parameters.
3. Pass the return address to the called.
4. Transfer control to the called.
2. Which of the caller or callee saves execution status
information?
- Once again, the restoration of the execution status of
the caller could be done by either the caller or the called. In general, the
linkage actions of the called can occur at two different times, either at the
beginning of its execution or at the end. These are sometimes called the
prologue and epilogue of the subprogram linkage. In the case of a simple
subprogram, all of the linkage actions of the callee occur at the end of its
execution, so there is no need for a prologue.
4. What the task of a linker?
- In computer science, a linker or link editor is a
computer program that takes one or more object files generated by a compiler
and combines them into a single executable program. In IBM mainframe
environments such as OS/360 this program is known as a linkage editor. A
simpler version that wrote its output directly to memory was called the loader,
though loading is typically considered a separate process.
16. Describe the deep-access method of implementing
dynamic scoping.
- If local variables are stack dynamic and are part of
the activation records in a dynamic-scoped language, references to nonlocal
variables can be resolved by searching through the activation record instances
of the other subprograms that are currently active, beginning with the one most
recently activated.
17. Describe the shallow-access method of implementing
dynamic scoping.
- Shallow access is an alternative implementation method,
not an alternative semantics. As stated previously, the semantics of deep
access and shallow access are identical. In the shallow-access method,
variables declared in subprograms are not stored in the activation records of
those subprograms.
PROBLEM SET
6. Although local variables in Java methods are
dynamically allocated at the beginning of each activation, under what
circumstances could the value of a local variable in a particular activation
retain the value of previous activation?
- static is written shared and that means a member
function that can be accessed without object instantiation. Static within
function usually means that the variable life time is the life time of the
whole program.
9. The static-chain method could be expanded slightly by
using two static links in each activation record instance where the second
points to the static grandparent activation record instance. How would this
approach affect the time required for subprogram linkage and nonlocal
references?
- static chain :
is a chain of static links that connect certain activation record instance in
the stack.
static depth : an integer associated with a static scope
that indicates how deeply it is nested in the outermost scope.
nesting depth/chain offset : the difference between the
static depth of the subprogram containing the reference to X and the static
depth of the subprogram contining the declaration for X.
11. If a compiler uses the static chain approach to
implementing blocks, which of the entries in the activation records for
subprograms are needed in the activation records for blocks?
- A static chain
is a chain of static links that connects certain ARIs . The static link in an
ARI for subprogram A points to one of the ARIs of A's static parent. The static
chain from an ARI connects it to all of its static ancestors . To find the declaration for a reference to a
nonlocal variable: The compiler can easily determine how many levels of scope
separate the current subprogram from the definition Just walk the static chain
the correct number of steps. Static_depth is an integer associated with a
static scope whose value is the depth of nesting of that scope