Files
mercury/compiler/notes/gc_and_c_code.html
Zoltan Somogyi aba4b8a3e1 Minor fixes in notes.
compiler/notes/todo.html:
    Delete references to things that have been done, and to things
    that won't be done.

compiler/notes/coding_standards.html:
compiler/notes/failure.html:
compiler/notes/gc_and_c_code.html:
compiler/notes/glossary.html:
compiler/notes/reviews.html:
compiler/notes/trailing.html:
compiler/notes/type_class_transformation.html:
    Fix German Capitalization, and other minor nits.
2021-05-25 23:38:05 +10:00

61 lines
1.5 KiB
HTML

<!--
vim: ts=4 sw=4 expandtab ft=html
-->
<html>
<head>
<title>Information on LLDS accurate garbage collection and C code</title>
</head>
<body>
<h1>Information on LLDS accurate garbage collection and C code</h1>
When handwritten code is called from Mercury,
the garbage collection scheduler doesn't know anything about the code,
so it cannot replace the succip on the stack (if there is one)
with the collector's address.
<p>
If the handwritten code calls no other code, then this is fine,
the scheduler knows it can replace the succip variable
and when a proceed() occurs,
execution will return to mercury code which it knows about.
<p>
If handwritten code calls other handwritten code, we have a problem,
as succip will be saved on the stack
and we don't know where on the stack it is stored.
So we use a global variable 'saved_succip' which is succip is saved into.
Care must be taken to save saved_succip on the stack
so it doesn't get clobbered.
So
<pre>
detstackvar(1) = (int) succip;
</pre>
becomes
<pre>
detstackvar(1) = (int) saved_succip;
saved_succip = (int) succip;
</pre>
and, when restoring,
<pre>
succip = (int) detstackvar(1);
</pre>
becomes
<pre>
succip = saved_succip;
saved_succip = detstackvar(1);
</pre>
<p>
(With appropriate LVALUE_CASTs).
<p>
In this way, garbage collection
always knows where the succip is stored in handwritten code.
<p>
The garbage collection code must check that
the current execution is not still in a handwritten predicate --
if it is, it must re-schedule (essentially just the same as before).
</body>
</html>