Files
mercury/compiler/notes/gc_and_c_code.html
Paul Bone d8b48ca53c Merge compiler notes
We had been maintaining two copies of these notes, this change attempts to
merge them into one set.  The cononical location for these notes is here in
compiler/notes/, they will be removed from the www repository.

I've also updated a number of URLs.

compiler/notes/allocation.html:
compiler/notes/bootstrapping.html:
compiler/notes/coding_standards.html:
compiler/notes/compiler_design.html:
compiler/notes/gc_and_c_code.html:
compiler/notes/glossary.html:
compiler/notes/release_checklist.html:
compiler/notes/reviews.html:
compiler/notes/todo.html:
compiler/notes/work_in_progress.html:
    Merge in differences with the versions of these files in the www
    repository.  Most differences are trivial.

compiler/notes/bytecode.html:
compiler/notes/c_coding_standard.html:
compiler/notes/developer_intro.html:
    Add files that were missing from the main repository but were on the
    website.
2014-02-12 13:37:00 +11:00

75 lines
1.6 KiB
HTML

<html>
<head>
<title>
Information On LLDS Accurate Garbage Collection And C Code
</title>
</head>
<body
bgcolor="#ffffff"
text="#000000"
>
<hr>
<!-------------------------->
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. <br>
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>
(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).
<p>
<hr>
<!-------------------------->
</body>
</html>