Commit b28ebc39 authored by chak's avatar chak
Browse files

[project @ 2001-08-10 01:47:39 by chak]

Added SimonM's explanation about f.e.d. stubs.
parent 92b67d72
......@@ -6,7 +6,7 @@
<h1>The Glasgow Haskell Compiler (GHC) Commentary [v0.1]</h1>
<h1>The Glasgow Haskell Compiler (GHC) Commentary [v0.2]</h1>
<!-- Contributors: Whoever makes substantial additions or changes to the
document, please add your name and keep the order alphabetic. Moreover,
......@@ -47,6 +47,7 @@
<li><a href="the-beast/typecheck.html">Checking Types</a>
<li><a href="the-beast/simplifier.html">The Mighty Simplifier</a>
<li><a href="the-beast/mangler.html">The Evil Mangler</a>
<li><a href="the-beast/alien.html">Alien Functions</a>
<h2>RTS &amp; Libraries</h2>
......@@ -62,7 +63,7 @@
<!-- hhmts start -->
Last modified: Wed Aug 8 00:11:49 EST 2001
Last modified: Fri Aug 10 11:48:22 EST 2001
<!-- hhmts end -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>The GHC Commentary - Alien Functions</title>
<h1>The GHC Commentary - Alien Functions</h1>
GHC implements experimental (by now it is actually quite well tested)
support for access to foreign functions and generally the interaction
between Haskell code and code written in other languages. Code
generation in this context can get quite tricky. This section attempts
to cast some light on this aspect of the compiler.
<h4>FFI Stub Files</h4>
For each Haskell module that contains a <code>foreign export
dynamic</code> declaration, GHC generates a <code>_stub.c</code> file
that needs to be linked with any program that imports the Haskell
module. When asked about it <a
href="">Simon Marlow</a> justified the
existence of these files as follows:
The stub files contain the helper function which invokes the Haskell
code when called from C.
Each time the foreign export dynamic is invoked to create a new
callback function, a small piece of code has to be dynamically
generated. It is the address of this dynamically generated bit of
code that is returned as the <code>Addr</code> (or <a
When called from C, the dynamically generated code must somehow invoke
the Haskell function which was originally passed to the
f.e.d. function -- it does this by invoking the helper function,
passing it a <a
to the Haskell function. It's split this way for two reasons: the
same helper function can be used each time the f.e.d. function is
called, and to keep the amount of dynamically generated code to a
The stub code is generated by <a
<!-- hhmts start -->
Last modified: Fri Aug 10 11:47:41 EST 2001
<!-- hhmts end -->
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment