Chapter 10 - Implementing Subprogram Flashcards

1
Q

what is subprogram linkage

A

the subprogram call and return operations of a language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

5 things that a PL needs to do during a subprogram call

A

1) follow whatever parameter passing method is used
2) create local variables by allocating storage and binding those variables to storage
3) save the execution status of the calling program unit
4) arrange to transfer control to the subprogram and ensure that control can return to the proper place when the subprogram execution is complete
5) if nested subprograms are allowed, make non-local variables visible to the called subprogram

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

4 things a subprogram must do upon termination

A

1) move the local values of the associated formal parameters to the actual parameters for the out or inout mode semantics
2) deallocate storage used for local variables
3) restore the execution status of the calling program unit
4) return control to the calling program unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a dynamic link?

A

a pointer variable that points to the top of the activation record (same as a stack frame) instance of the caller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a dynamic chain or call chain?

A

a collection of dynamic links in the stack at a given time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is local_offset?

A

the location of local variables of a subprogram relative to the beginning of the activation record

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

8 characteristics of an Algol60-like program stack

A
  • parameters often passed by two methods
  • local variables are often dynamically allocated
  • recursion must be supported
  • static scoping must be supported
  • activation record format is static but size is dynamic
  • the dynamic link points to the top of an instance of the activation record of the caller
  • an activation record instance is created dynamically when a subprogram is called
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is a static link?

A

a pointer variable that points to the bottom of the activation record of the static parent

only used when nested sub-programs are allowed in order to access non-local variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a static chain?

A

a chain of static links that connect certain activation records

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is static depth?

A

an integer associated with a static scope whose value is the depth of nesting of that scope. (main starts at 0, and each nested sub-program is +1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is chain offset or nesting depth?

A

the static depth of reference - static depth of declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Two issues with static chain method

A
  • nonlocal references are slow if # of scopes between reference and declaration variable (i.e. chain offset) is large
  • cost of non-local references can change with code upgrades
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How are blocks represented on the stack?

A

as parameterless subprograms using the static chain process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly