According to the project specification, subsection 4.2 Scope:
Function definitions open a new local scope. The function’s parameters belong to this local scope. Blocks additionally open new local scopes.
As a result, it might be possible that a fuction parameter is shadowed by a local variable in the body of this function.
Coming to code generation for a function definition based on the rule in the script Subsection 9.3.3: The Function Prologue and Epilogue, which states that
The code c of the body s of a function f with parameters k1 x1; …; km xm; can be generated by considering the function’s body wrapped in a block where parameters are declared as local variables.
Therefore, if a function f has a block as its body, then for code generation it’s cosidered as a block which contains its body (a nested block). However, the pro- and epilogue machine code in the same subsection seems to state that the parameters are prepended to the body as local variable declarations. In other words, function parameters and local variables in its body share the same scope (of code generation) since they share the same offset function, which seems not logical as shadowing a parameter by a local variable (directly contained by the function’s body) is no longer possible.
The questions are:
- Do the function parameters and the local variables defined in its body share the same offset function (i.e. the same scope of code generation)?
- If yes, how does it work in the case that a parameter is shadowed by a local variable?