Beruflich Dokumente
Kultur Dokumente
Procedure Semantics
• Most current language implementations follow the tenets of block
structure in procedure call semantics.
• Each procedure definition is a block.
• When a procedure is invoked, an activation record (frame) is created to
contain name bindings for that procedure during its lifetime. This
activation record contains two critical references:
– The dynamic chain pointer (this points to the caller’s activation
record in the stack. This is remembered so that the caller’s
activation can be restored upon return)
– The static chain pointer (this points to the most recent activation
record of the block in which this procedure was declared. This is
remembered so that references to non-local variables can be
found from the lexical (or static) nesting structure of the
program.
Parameter Passing Methods
• Pass by Value
This method is common and useful. The values of the arguments are
copied into the activation record of the called procedure. As C
demonstrates, aliases can occur if pointers are passed by value.
means passing a copy of the value as an argument.
If a variable is passed, the method receives a copy of the variable's
value. The value of the original variable cannot be changed within the
method. This seems reasonable because the method only has a copy
of the value; it does not have access to the original variable. This
process is called pass by value.
• Pass by Reference
• Pass by Value-Result
1. The values of the arguments are copied into the fomal parameters.
2. The final values of the parameters are copied back out to the
arguments.
• Pass by Name
This method (from Algol 60) was created when parameter passing was
poorly understood. It involves implementing the same behavior as
would occur if the arguments were textually substituted (with
appropriate renamings) in place of the parameters in the body, and the
body were then evaluated. The concept of a thunk(a piece of code to
evaluate the name parameter) was invented to implement this
complex method. The complexity is clear when one realizes it’s
impossible to write a swap procedure using name parameter passing.