Académique Documents
Professionnel Documents
Culture Documents
Abstraction
Control Abstraction
Abstraction
Control abstraction
Data abstraction
Subroutines
caller
Chapter contents...
Parameter passing
mode determines
...Chapter contents
Coroutines
Hardware support
Variable-sized arguments?
method 1
method 2
pass just the address (to caller object) & dope vector
copy object to normal variable-sized area when subroutine is entered
10
11
Example
Figure slide -1
C is called from B
we know that B must be active (and has a frame in
the stack)
C gets visible only when control enters B
C is visible only from B & D (and routines declared
in C & D)
12
Display
Using display
14
Closures
15
Calling sequences...
pass parameters
save return address
update program counter
update stack pointer (to allocate space)
save registers (including the frame pointer)
16
...Calling sequences
passing parameters
in general, things that may be different for different calls
the more work in the callee the less space we need for the code
17
Saving registers
Simpler solution
Compromise
18
Callers responsibility
Standard approach
Maintaining displays
callee at level j
save Display[j] in the stack
replace Display[j] with callees FP
why does it work: page 433
Leaf routines
19
Implementing closures
restore Display[1..j]
20
Cost of maintenance
Static chains
Display
Hardware support
Notes
Stack frame...
(slide +1)
optimization
24
...Stack frame
sp grows, fp stays
C: alloca library routine
fast to implement, automatic reclaiming
see slide +1
not C
use some register to pass the static link (r2)
25
26
Returning values
Structures
possible cases
27
Caller
Callee (prologue)
Callee (epilogue)
Optimizations
e.g. no caller-saves
Debugger support
30
Inline expansion
space allocation
branching to and from subroutine
saving and restoring registers (not always)
Language design
pragma inline
31
In-line expansion
Macros
32
programmers can use good programming style and still get good
performance
expand once
33
34
Parameter passing
Formal parameters
control behavior
provide data to operate on
parameters make subroutines more abstract
names in the declaration of a subroutine
Section contents
Parameter-passing modes
Additional mechanisms
Prefix
Infix
Mixfix
Note on uniformity
37
Parameter modes
38
what is passed to p?
call by value: a copy of x
39
Pascal
Fortran
40
Implementation
41
Function returns
return expression
immediate termination of the subroutine
if the function still has something to do, then place the return
value into a temporary variable
rtn := expression
...
return rtn
43
...Function return
Fortran
function name := ...
return
Ada example
return expression
SR example