Commit 8c7c30b1 authored by simonpj's avatar simonpj
Browse files

[project @ 2003-10-29 19:05:55 by simonpj]

Add info about compiling the Main module
parent 7c3d4a1f
......@@ -74,6 +74,7 @@
<li><a href="the-beast/ghci.html">GHCi</a>
<li><a href="the-beast/fexport.html">Implementation of
<code>foreign export</code></a>
<li><a href="the-beast/main.html">Compiling and running the Main module</code></a>
<h2>RTS &amp; Libraries</h2>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>The GHC Commentary - Compiling and running the Main module</title>
<h1>Compiling and running the Main module</h1>
GHC allows you to determine which module contains the "main" function, and
what that function is called, via the <code>-fmain-is</code> flag. The trouble is
that the runtime system is fixed, so what symbol should it link to?
The current solution is this. Suppose the main function is <code></code>.
Then, when compiling module <code>Foo</code>, GHC adds an extra definition:
:Main.main = runIO
Now the RTS can invoke <code>:Main.main</code> to start the program. (This extra
definition is inserted in TcRnDriver.checkMain.)
Before starting the program, though, the RTS also initialises the module tree
by calling <code>init_:Main</code>, so when compiling the main module (Foo in this case),
as well as generating <code>init_Foo</code> as usual, GHC also generates
init_zcMain() { init_Foo; }
This extra initialisation code is generated in CodeGen.mkModuleInit.
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