[project @ 2001-08-08 09:48:58 by chak]
[ghc-hetmet.git] / ghc / docs / comm / rts-libs / primitives.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
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>
7
8   <body BGCOLOR="FFFFFF">
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>
20
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. 
35
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"><code>primops.txt</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).
43     <p>
44       The utility <a
45         href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/utils/genprimopcode/"><code>genprimopcode</code></a> 
46       generates a series of Haskell files from <code>primops.txt</code>, which
47       encode the types and various properties of the primitive operations as
48       compiler internal data structures.  These Haskell files are not complete
49       modules, but program fragments, which are included into compiler modules
50       during the GHC build process.  The generated include files can be found
51       in the directory <code>fptools/ghc/compiler/</code> and carry names
52       matching the pattern <code>primop-*.hs-incl</code>.  They are generate
53       during the execution of the <code>boot</code> target in the
54       <code>fptools/ghc/</code> directory.  This scheme significantly
55       simplifies the maintenance of primitive operations.
56
57     <p><small>
58 <!-- hhmts start -->
59 Last modified: Wed Aug  8 19:29:12 EST 2001
60 <!-- hhmts end -->
61     </small>
62   </body>
63 </html>