From b28ebc39a82c1726c52fa219d48842b7a4ea093e Mon Sep 17 00:00:00 2001 From: chak Date: Fri, 10 Aug 2001 01:47:40 +0000 Subject: [PATCH] [project @ 2001-08-10 01:47:39 by chak] Added SimonM's explanation about f.e.d. stubs. --- ghc/docs/comm/index.html | 5 ++-- ghc/docs/comm/the-beast/alien.html | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 ghc/docs/comm/the-beast/alien.html diff --git a/ghc/docs/comm/index.html b/ghc/docs/comm/index.html index c4601d6..073ab82 100644 --- a/ghc/docs/comm/index.html +++ b/ghc/docs/comm/index.html @@ -6,7 +6,7 @@ -

The Glasgow Haskell Compiler (GHC) Commentary [v0.1]

+

The Glasgow Haskell Compiler (GHC) Commentary [v0.2]

-Last modified: Wed Aug 8 00:11:49 EST 2001 +Last modified: Fri Aug 10 11:48:22 EST 2001 diff --git a/ghc/docs/comm/the-beast/alien.html b/ghc/docs/comm/the-beast/alien.html new file mode 100644 index 0000000..e0e00a0 --- /dev/null +++ b/ghc/docs/comm/the-beast/alien.html @@ -0,0 +1,55 @@ + + + + + The GHC Commentary - Alien Functions + + + +

The GHC Commentary - Alien Functions

+

+ 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. + +

FFI Stub Files

+

+ For each Haskell module that contains a foreign export + dynamic declaration, GHC generates a _stub.c file + that needs to be linked with any program that imports the Haskell + module. When asked about it Simon Marlow 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 Addr (or Ptr). + 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 StablePtr + 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 + minimum. +

+

+ The stub code is generated by DSForeign.fexportEntry. + + +

+ +Last modified: Fri Aug 10 11:47:41 EST 2001 + + + + -- 1.7.10.4