[project @ 2003-10-29 19:05:55 by simonpj]
authorsimonpj <unknown>
Wed, 29 Oct 2003 19:05:56 +0000 (19:05 +0000)
committersimonpj <unknown>
Wed, 29 Oct 2003 19:05:56 +0000 (19:05 +0000)
Add info about compiling the Main module

ghc/docs/comm/index.html
ghc/docs/comm/the-beast/main.html [new file with mode: 0644]

index bf83fcb..09357b2 100644 (file)
@@ -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>
diff --git a/ghc/docs/comm/the-beast/main.html b/ghc/docs/comm/the-beast/main.html
new file mode 100644 (file)
index 0000000..332ffaa
--- /dev/null
@@ -0,0 +1,35 @@
+<!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>