[m-dev.] bug fix to frameopt
Fergus Henderson
fjh at cs.mu.oz.au
Thu Jul 24 08:43:27 AEST 1997
Zoltan Somogyi, you wrote:
>
> David and I just looked at the template in pragma_c_gen, and we
> couldn't quite figure out why for may_call_mercury pragma C code,
> the restore_registers was conditional on #ifndef CONSERVATIVE_GC
> but the corresponding save_registers wasn't. We thought it was
> to prepare for the restore_registers that is done when calling
> Mercury from C, but we weren't sure. Whether we were correct or not,
> the reason should be documented in pragma_c_gen.m.
Hi,
You were correct.
I had a look at the documentation, and it seemed clear enough.
The reason for the save_registers() and restore_registers() _is_
documented in pragma_c_gen.m, and it does explain why the
restore_registers() need only be done #ifndef CONSERVATIVE_GC.
% <save live variables onto the stack> /* see note (1) below */
% {
% <declaration of one local variable for each arg>
% <assignment of input values from registers to local variables>
% save_registers(); /* see notes (1) and (2) below */
% { <the c code itself> }
% #ifndef CONSERVATIVE_GC
% restore_registers(); /* see notes (1) and (3) below */
% #endif
% <assignment of the output values from local variables to registers>
% }
...
% Notes:
%
% (1) These parts are only emitted if the C code may call Mercury.
% If a pragma c_code(will_not_call_mercury, ...) declaration was used,
% they will not be emitted.
%
% (2) The call to save_registers() is needed so that if the
% C code calls Mercury code, we can call restore_registers()
% on entry to the Mercury code (see export.m) to get the
% right values of `sp', `hp', `curfr' and `maxfr' for the
% recursive invocation of Mercury.
%
% (3) The call to restore_registers() is needed in case the
% C code calls Mercury code which allocates some data
% on the heap, and this data is returned from Mercury
% through C back to Mercury. In that case, we need to
% keep the value of `hp' that was set by the recursive
% invocation of Mercury. The Mercury calling convention
% guarantees that the values of `sp', `curfr', and `maxfr'
% will be preserved, so if we're using conservative gc,
% there is nothing that needs restoring.
Of course if you have some concrete ideas about improving
this documentation, you're welcome to do so.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list