![]() |
|
|
|
|
|
|
9
18th September 20:47
External User
Posts: 1
|
The key difficulty is that internal (nested) procedures need access
to variables defined in parent procedure. In practice, it is enough to have address of parent stack frame -- so one has to pass one piece of extra information. For normal calls one can just use a hidden parameter. The question is how to accomodate extra parameter in ENTRY variable? One way (used in the F compiler) is to use so called thick pointers: ENTRY variable consists of two machine words: one contain address of the machine code entry, the other one address of stack frame (DSA) of the parent procedure. Calling ENTRY variable loads address of the parent stack frame into dedicated register (R5). Another way is to use "trampolines": a small code fragments that load extra parameter into register and call the real code. When using trampolines ENTRY variable is just one word, but one also have to allocate memory for a trampoline. Trampolines may be allocated on the stack (GNU C does this) or one can use dynamically allocated memory (typical for Lisp and similar systems). Both methods have advantages and disadwantages, but for C (as a non-standard extension supported by GNU C) trampolines have a very big advantage: C programmers expect that function pointer can be stored in any other pointer variable (non-standard, but common expectation). So, using thick pointers would double size of all pointers (or break many programs). Using trampolines means that function pointers are compatible with all other pointers. The same argument works for non-C languages if internal ENTRY variables may be passed to C routines. -- Waldek Hebisch hebisch@math.uni.wroc.pl |
|