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>
</ul>
<h2>RTS &amp; Libraries</h2>
......
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>The GHC Commentary - Compiling and running the Main module</title>
</head>
<body BGCOLOR="FFFFFF">
<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?
<p>
The current solution is this. Suppose the main function is <code>Foo.run</code>.
<ul>
<li>
Then, when compiling module <code>Foo</code>, GHC adds an extra definition:
<pre>
:Main.main = runIO Foo.run
</pre>
Now the RTS can invoke <code>:Main.main</code> to start the program. (This extra
definition is inserted in TcRnDriver.checkMain.)
<p><li>
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
<pre>
init_zcMain() { init_Foo; }
</pre>
This extra initialisation code is generated in CodeGen.mkModuleInit.
</ul>
</body>
</html>
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