Test Trac #9036
[ghc.git] / docs / comm / rts-libs / primitives.html
2 <html>
3 <head>
4 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
5 <title>The GHC Commentary - Primitives</title>
6 </head>
9 <h1>The GHC Commentary - Primitives</h1>
10 <p>
11 Most user-level Haskell types and functions provided by GHC (in
12 particular those from the Prelude and GHC's Prelude extensions) are
13 internally constructed from even more elementary types and functions.
14 Most notably, GHC understands a notion of <em>unboxed types,</em> which
15 are the Haskell representation of primitive bit-level integer, float,
16 etc. types (as opposed to their boxed, heap allocated counterparts) -
17 cf. <a
18 href="http://research.microsoft.com/Users/simonpj/Papers/unboxed-values.ps.Z">"Unboxed
19 Values as First Class Citizens."</a>
21 <h4>The Ultimate Source of Primitives</h4>
22 <p>
23 The hardwired types of GHC are brought into scope by the module
24 <code>PrelGHC</code>. This modules only exists in the form of a
25 handwritten interface file <a
26 href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/lib/std/PrelGHC.hi-boot"><code>PrelGHC.hi-boot</code>,</a>
27 which lists the type and function names, as well as instance
28 declarations. The actually types of these names as well as their
29 implementation is hardwired into GHC. Note that the names in this file
30 are z-encoded, and in particular, identifiers ending on <code>zh</code>
31 denote user-level identifiers ending in a hash mark (<code>#</code>),
32 which is used to flag unboxed values or functions operating on unboxed
33 values. For example, we have <code>Char#</code>, <code>ord#</code>, and
34 so on.
36 <h4>The New Primitive Definition Scheme</h4>
37 <p>
38 As of (about) the development version 4.11, the types and various
39 properties of primitive operations are defined in the file <a
40 href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/prelude/primops.txt.pp"><code>primops.txt.pp</code></a>.
41 (Personally, I don't think that the <code>.txt</code> suffix is really
42 appropriate, as the file is used for automatic code generation; the
43 recent addition of <code>.pp</code> means that the file is now mangled
44 by cpp.)
45 <p>
46 The utility <a
47 href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/utils/genprimopcode/"><code>genprimopcode</code></a>
48 generates a series of Haskell files from <code>primops.txt</code>, which
49 encode the types and various properties of the primitive operations as
50 compiler internal data structures. These Haskell files are not complete
51 modules, but program fragments, which are included into compiler modules
52 during the GHC build process. The generated include files can be found
53 in the directory <code>fptools/ghc/compiler/</code> and carry names
54 matching the pattern <code>primop-*.hs-incl</code>. They are generate
55 during the execution of the <code>boot</code> target in the
56 <code>fptools/ghc/</code> directory. This scheme significantly
57 simplifies the maintenance of primitive operations.
58 <p>
59 As of development version 5.02, the <code>primops.txt</code> file also allows the
60 recording of documentation about intended semantics of the primitives. This can
61 be extracted into a latex document (or rather, into latex document fragments)
62 via an appropriate switch to <code>genprimopcode</code>. In particular, see <code>primops.txt</code>
63 for full details of how GHC is configured to cope with different machine word sizes.
64 <p><small>
65 <!-- hhmts start -->
66 Last modified: Mon Nov 26 18:03:16 EST 2001
67 <!-- hhmts end -->
68 </small>
69 </body>
70 </html>