Subroutine abstraction

When implementing a programming languange, need to decide tasks for calling subroutines. Should the caller, or callee handle it? If the subroutine does as much as possible, space is saved. Time may be saved by putting “stuff” in the caller instead, where more information may be known.

Stack allocation of subroutines

Maintenance of stack is responsibility of calling sequence and subroutine prologue and epilogue. The calling sequence is the code executed in caller immediately before and after the call. The prologue is code executed at the beginning of the subroutine in the routine itself. The epilogue is the code executed at the end of the subroutine.

For inline keyword, functions that are inlined must be “plopped” into code in a semantically neutral way. In other words, the program meaning shouldn’t change by inlining.

Parameter passing

Pass by value is related to applicative order in the lambda calculus. Pass by name is like normal order reduction in the lambda calculus. Pass by reference is an alias for the corresponding actual parameter. Pass by value/result; the actual parameter is assigned into the formal parameter when the subroutine is called, then the value of the formal parameter is copied back into the actual parameter when subroutine exits.