Fix typo
[ghc-hetmet.git] / ghc / compiler / prelude / primops.txt.pp
index 2a58a75..ecde882 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------
--- $Id: primops.txt.pp,v 1.18 2002/04/10 11:43:43 stolz Exp $
+-- $Id: primops.txt.pp,v 1.37 2005/11/25 09:46:19 simonmar Exp $
 --
 -- Primitive Operations
 --
@@ -24,8 +24,8 @@
 --               abstract C operations.
 --             
 --     - or, for an out-of-line primop:
---             ghc/includes/PrimOps.h (just add the declaration)
---             ghc/rts/PrimOps.hc     (define it here)
+--             ghc/includes/StgMiscClosures.h (just add the declaration)
+--             ghc/rts/PrimOps.cmm     (define it here)
 --             ghc/rts/Linker.c       (declare the symbol for GHCi)
 --
 --     - the User's Guide 
@@ -65,6 +65,11 @@ defaults
 
 #include "MachDeps.h"
 
+-- We need platform defines (tests for mingw32 below).  However, we only
+-- test the TARGET platform, which doesn't vary between stages, so the
+-- stage1 platform defines are fine:
+#include "../stage1/ghc_boot_platform.h"
+
 section "The word size story."
        {Haskell98 specifies that signed integers (type {\tt Int})
         must contain at least 30 bits. GHC always implements {\tt
@@ -113,11 +118,7 @@ section "The word size story."
         -> Int\#}; otherwise it has type {\tt ByteArr\# -> Int\# ->
         Int32\#}.  This approach confines the necessary {\tt
         \#if}-defs to this file; no conditional compilation is needed
-        in the files that expose these primops, namely
-        \texttt{lib/std/PrelStorable.lhs},
-        \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated
-        fashion) in \texttt{hslibs/lang/ForeignObj.lhs} and
-        \texttt{hslibs/lang/Addr.lhs}.
+        in the files that expose these primops.
 
         Finally, there are strongly deprecated primops for coercing
          between {\tt Addr\#}, the primitive type of machine
@@ -1115,10 +1116,6 @@ primop  WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
    Addr# -> Int# -> Addr# -> State# s -> State# s
    with has_side_effects = True
 
-primop  WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
-   Addr# -> Int# -> ForeignObj# -> State# s -> State# s
-   with has_side_effects = True
-
 primop  WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
    Addr# -> Int# -> Float# -> State# s -> State# s
    with has_side_effects = True
@@ -1164,87 +1161,6 @@ primop  WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
    with has_side_effects = True
 
 ------------------------------------------------------------------------
-section "ForeignObj#"
-       {Operations on ForeignObj\#.  The indexing operations are
-       all deprecated.}
-------------------------------------------------------------------------
-
-primop  MkForeignObjOp "mkForeignObj#" GenPrimOp
-   Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
-   with
-   has_side_effects = True
-   out_of_line      = True
-
-primop  WriteForeignObjOp "writeForeignObj#" GenPrimOp
-   ForeignObj# -> Addr# -> State# s -> State# s
-   with
-   has_side_effects = True
-
-primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
-   ForeignObj# -> Addr#
-
-primop TouchOp "touch#" GenPrimOp
-   o -> State# RealWorld -> State# RealWorld
-   with
-   has_side_effects = True
-
-primop EqForeignObj "eqForeignObj#" GenPrimOp
-   ForeignObj# -> ForeignObj# -> Bool
-   with commutable = True
-
-primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Char#
-   {Read 8-bit character; offset in bytes.}
-
-primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Char#
-   {Read 31-bit character; offset in 4-byte words.}
-
-primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Int#
-
-primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Word#
-
-primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Addr#
-
-primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Float#
-
-primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Double#
-
-primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> StablePtr# a
-
-primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Int#
-
-primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Int#
-
-primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> INT32
-
-primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> INT64
-
-primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Word#
-
-primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> Word#
-
-primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> WORD32
-
-primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
-   ForeignObj# -> Int# -> WORD64
-
-
-
-------------------------------------------------------------------------
 section "Mutable variables"
        {Operations on MutVar\#s, which behave like single-element mutable arrays.}
 ------------------------------------------------------------------------
@@ -1274,6 +1190,18 @@ primop  SameMutVarOp "sameMutVar#" GenPrimOp
    with
    usage = { mangle SameMutVarOp [mkP, mkP] mkM }
 
+-- not really the right type, but we don't know about pairs here.  The
+-- correct type is
+--
+--   MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
+--
+primop  AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp
+   MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #)
+   with
+   usage = { mangle AtomicModifyMutVarOp [mkP, mkM, mkP] mkM }
+   has_side_effects = True
+   out_of_line = True
+
 ------------------------------------------------------------------------
 section "Exceptions"
 ------------------------------------------------------------------------
@@ -1300,6 +1228,15 @@ primop  RaiseOp "raise#" GenPrimOp
    usage       = { mangle RaiseOp [mkM] mkM }
    out_of_line = True
 
+-- raiseIO# needs to be a primop, because exceptions in the IO monad
+-- must be *precise* - we don't want the strictness analyser turning
+-- one kind of bottom into another, as it is allowed to do in pure code.
+
+primop  RaiseIOOp "raiseIO#" GenPrimOp
+   a -> State# RealWorld -> (# State# RealWorld, b #)
+   with
+   out_of_line = True
+
 primop  BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
         (State# RealWorld -> (# State# RealWorld, a #))
      -> (State# RealWorld -> (# State# RealWorld, a #))
@@ -1313,6 +1250,66 @@ primop  UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
    out_of_line = True
 
 ------------------------------------------------------------------------
+section "STM-accessible Mutable Variables"
+------------------------------------------------------------------------
+
+primop AtomicallyOp "atomically#" GenPrimOp
+      (State# RealWorld -> (# State# RealWorld, a #) )
+   -> State# RealWorld -> (# State# RealWorld, a #)
+   with
+   out_of_line = True
+   has_side_effects = True
+
+primop  RetryOp "retry#" GenPrimOp
+   State# RealWorld -> (# State# RealWorld, a #)
+   with 
+   out_of_line = True
+   has_side_effects = True
+
+primop  CatchRetryOp "catchRetry#" GenPrimOp
+      (State# RealWorld -> (# State# RealWorld, a #) )
+   -> (State# RealWorld -> (# State# RealWorld, a #) )
+   -> (State# RealWorld -> (# State# RealWorld, a #) )
+   with 
+   out_of_line = True
+   has_side_effects = True
+
+primop  CatchSTMOp "catchSTM#" GenPrimOp
+      (State# RealWorld -> (# State# RealWorld, a #) )
+   -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
+   -> (State# RealWorld -> (# State# RealWorld, a #) )
+   with 
+   out_of_line = True
+   has_side_effects = True
+
+primop NewTVarOp "newTVar#" GenPrimOp
+       a
+    -> State# s -> (# State# s, TVar# s a #)
+   {Create a new Tar\# holding a specified initial value.}
+   with
+   out_of_line  = True
+
+primop ReadTVarOp "readTVar#" GenPrimOp
+       TVar# s a
+    -> State# s -> (# State# s, a #)
+   {Read contents of TVar\#.  Result is not yet evaluated.}
+   with
+   out_of_line = True
+
+primop WriteTVarOp "writeTVar#" GenPrimOp
+       TVar# s a
+    -> a
+    -> State# s -> State# s
+   {Write contents of TVar\#.}
+   with
+   out_of_line     = True
+   has_side_effects = True
+
+primop  SameTVarOp "sameTVar#" GenPrimOp
+   TVar# s a -> TVar# s a -> Bool
+
+
+------------------------------------------------------------------------
 section "Synchronized Mutable Variables"
        {Operations on MVar\#s, which are shared mutable variables
        ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
@@ -1403,6 +1400,33 @@ primop  WaitWriteOp "waitWrite#" GenPrimOp
    has_side_effects = True
    out_of_line      = True
 
+#ifdef mingw32_TARGET_OS
+primop  AsyncReadOp "asyncRead#" GenPrimOp
+   Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
+   {Asynchronously read bytes from specified file descriptor.}
+   with
+   needs_wrapper    = True
+   has_side_effects = True
+   out_of_line      = True
+
+primop  AsyncWriteOp "asyncWrite#" GenPrimOp
+   Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
+   {Asynchronously write bytes from specified file descriptor.}
+   with
+   needs_wrapper    = True
+   has_side_effects = True
+   out_of_line      = True
+
+primop  AsyncDoProcOp "asyncDoProc#" GenPrimOp
+   Addr# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
+   {Asynchronously perform procedure (first arg), passing it 2nd arg.}
+   with
+   needs_wrapper    = True
+   has_side_effects = True
+   out_of_line      = True
+
+#endif
+
 ------------------------------------------------------------------------
 section "Concurrency primitives"
        {(In a non-concurrent implementation, ThreadId\# can be as singleton
@@ -1417,12 +1441,6 @@ primop  ForkOp "fork#" GenPrimOp
    has_side_effects = True
    out_of_line      = True
 
-primop ForkProcessOp "forkProcess#" GenPrimOp
-   State# RealWorld -> (# State# RealWorld, Int#  #)
-   with
-   has_side_effects = True
-   out_of_line      = True
-
 primop  KillThreadOp "killThread#"  GenPrimOp
    ThreadId# -> a -> State# RealWorld -> State# RealWorld
    with
@@ -1442,10 +1460,15 @@ primop  MyThreadIdOp "myThreadId#" GenPrimOp
    out_of_line = True
 
 primop LabelThreadOp "labelThread#" GenPrimOp
-   Addr# -> State# RealWorld -> State# RealWorld
+   ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
    with
    has_side_effects = True
    out_of_line      = True
+   
+primop  IsCurrentThreadBoundOp "isCurrentThreadBound#" GenPrimOp
+   State# RealWorld -> (# State# RealWorld, Int# #)
+   with
+   out_of_line = True
 
 ------------------------------------------------------------------------
 section "Weak pointers"
@@ -1469,7 +1492,7 @@ primop  DeRefWeakOp "deRefWeak#" GenPrimOp
 
 primop  FinalizeWeakOp "finalizeWeak#" GenPrimOp
    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, 
-              (State# RealWorld -> (# State# RealWorld, Unit #)) #)
+              (State# RealWorld -> (# State# RealWorld, () #)) #)
    with
    usage            = { mangle FinalizeWeakOp [mkM, mkP] 
                                (mkR . (inUB FinalizeWeakOp 
@@ -1477,6 +1500,11 @@ primop  FinalizeWeakOp "finalizeWeak#" GenPrimOp
    has_side_effects = True
    out_of_line      = True
 
+primop TouchOp "touch#" GenPrimOp
+   o -> State# RealWorld -> State# RealWorld
+   with
+   has_side_effects = True
+
 ------------------------------------------------------------------------
 section "Stable pointers and names"
 ------------------------------------------------------------------------
@@ -1521,16 +1549,18 @@ primop  StableNameToIntOp "stableNameToInt#" GenPrimOp
    usage = { mangle StableNameToIntOp [mkP] mkR }
 
 ------------------------------------------------------------------------
-section "Parallelism"
+section "Unsafe pointer equality"
+--  (#1 Bad Guy: Alistair Reid :)   
 ------------------------------------------------------------------------
 
-primop  SeqOp "seq#" GenPrimOp
-   a -> Int#
+primop  ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
+   a -> a -> Int#
    with
-   usage            = { mangle  SeqOp [mkO] mkR }
-   strictness       = { \ arity -> mkStrictSig (mkTopDmdType [evalDmd] TopRes) }
-      -- Seq is strict in its argument; see notes in ConFold.lhs
-   has_side_effects = True
+   usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
+
+------------------------------------------------------------------------
+section "Parallelism"
+------------------------------------------------------------------------
 
 primop  ParOp "par#" GenPrimOp
    a -> Int#
@@ -1605,6 +1635,9 @@ section "Tag to enum stuff"
 
 primop  DataToTagOp "dataToTag#" GenPrimOp
    a -> Int#
+   with
+   strictness  = { \ arity -> mkStrictSig (mkTopDmdType [seqDmd] TopRes) }
+       -- dataToTag# must have an evaluated argument
 
 primop  TagToEnumOp "tagToEnum#" GenPrimOp     
    Int# -> a
@@ -1620,12 +1653,12 @@ primop   AddrToHValueOp "addrToHValue#" GenPrimOp
    {Convert an Addr\# to a followable type.}
 
 primop   MkApUpd0_Op "mkApUpd0#" GenPrimOp
-   a -> (# a #)
+   BCO# -> (# a #)
    with
    out_of_line = True
 
 primop  NewBCOOp "newBCO#" GenPrimOp
-   ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
+   ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> Int# -> ByteArr# -> State# s -> (# State# s, BCO# #)
    with
    has_side_effects = True
    out_of_line      = True