Changes between Version 2 and Version 3 of Commentary/PrimOps


Ignore:
Timestamp:
Sep 10, 2006 6:55:35 PM (9 years ago)
Author:
simonmar
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/PrimOps

    v2 v3  
    77PrimOps are made available to Haskell code through the virtual module {{{GHC.Prim}}}.  This module has no implementation, and its interface never resides on disk: if {{{GHC.Prim}}} is imported, we use a built-in {{{ModIface}}} value - see {{{ghcPrimIface}}} in [[GhcFile(compiler/iface/LoadIface.lhs)]].
    88
    9 == Implementation of !PrimOps: !MachOps ==
    10 
    119== The primops.txt.pp file ==
    1210
     11The file [[GhcFile(compiler/prelude/primops.txt.pp)]] includes all the information the compiler needs to know about a !PrimOp, bar its actual implementation.  For each !PrimOp, {{{primops.txt.pp}}} lists:
     12
     13 * Its name, as it appears in Haskell code (eg. int2Integer#)
     14 * Its type
     15 * The name of its constructor in GHC's {{{PrimOp}}} data type.
     16 * Various properties, such as whether the operation is commutable, or has side effects.
     17
     18For example, here's the integer multiplication !PrimOp:
     19
     20{{{
     21primop   IntegerMulOp   "timesInteger#" GenPrimOp   
     22   Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
     23   with commutable = True
     24        out_of_line = True
     25}}}
     26
     27The {{{primops.txt.pp}}} file is processed first by CPP, and then by the {{{genprimopcode}}} program (see [[GhcFile(utils/genprimopcode)]]).  {{{genprimopcode}}} generates the following bits from {{{primops.txt.pp}}}:
     28
     29 * Various files that are {{{#include}}}d into [[GhcFile(compiler/prelude/PrimOp.lhs)]],
     30   containing declarations of data types and functions describing the !PrimOps.  See
     31   [[GhcFile(compiler/Makefile)]].
     32
     33 * {{{libraries/base/GHC/PrimopWrappers.hs}}}, a file that contains (curried) wrapper
     34   functions for each of the !PrimOps, so that they are accessible from byte-code, and
     35   so that the [wiki:Commentary/Rts/Interpreter byte-code interpreter] doesn't need to implement any !PrimOps at all: it
     36   just invokes the compiled ones from {{{GHC.PrimopWrappers}}}.
     37
     38 * {{{libraries/base/GHC/Prim.hs}}}, a source file containing dummy declarations for
     39   all the !PrimOps, solely so that Haddock can include documentation for {{{GHC.Prim}}}
     40   in its documentation for the {{{base}}} package.  The file {{{GHC/Prim.hs}}} is never
     41   actually compiled, only processed by Haddock.
     42
     43== Implementation of !PrimOps ==
     44
     45!PrimOps are divided into two categories for the purposes of implementation: inline and out-of-line.
     46
     47=== Inline !PrimOps ===
     48
     49=== Out-of-line !PrimOps ===
     50
    1351== Adding a new !PrimOp ==