[project @ 2001-08-14 13:40:07 by sewardj]
[ghc-hetmet.git] / ghc / rts / RtsAPI.c
index 1cb0aee..178d1f6 100644 (file)
@@ -1,12 +1,13 @@
 /* ----------------------------------------------------------------------------
- * $Id: RtsAPI.c,v 1.23 2000/12/04 12:31:21 simonmar Exp $
+ * $Id: RtsAPI.c,v 1.28 2001/08/14 13:40:09 sewardj Exp $
  *
- * (c) The GHC Team, 1998-2000
+ * (c) The GHC Team, 1998-2001
  *
  * API for invoking Haskell functions via the RTS
  *
  * --------------------------------------------------------------------------*/
 
+#include "PosixSource.h"
 #include "Rts.h"
 #include "Storage.h"
 #include "RtsAPI.h"
@@ -40,11 +41,7 @@ HaskellObj
 rts_mkInt8 (HsInt8 i)
 {
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
-  /* This is a 'cheat', using the static info table for Ints,
-     instead of the one for Int8, but the types have identical
-     representation.
-  */
-  p->header.info = Izh_con_info;
+  p->header.info = I8zh_con_info;
   /* Make sure we mask out the bits above the lowest 8 */
   p->payload[0]  = (StgClosure *)(StgInt)((unsigned)i & 0xff);
   return p;
@@ -54,11 +51,7 @@ HaskellObj
 rts_mkInt16 (HsInt16 i)
 {
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
-  /* This is a 'cheat', using the static info table for Ints,
-     instead of the one for Int8, but the types have identical
-     representation.
-  */
-  p->header.info = Izh_con_info;
+  p->header.info = I16zh_con_info;
   /* Make sure we mask out the relevant bits */
   p->payload[0]  = (StgClosure *)(StgInt)((unsigned)i & 0xffff);
   return p;
@@ -68,8 +61,7 @@ HaskellObj
 rts_mkInt32 (HsInt32 i)
 {
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
-  /* see mk_Int8 comment */
-  p->header.info = Izh_con_info;
+  p->header.info = I32zh_con_info;
   p->payload[0]  = (StgClosure *)(StgInt)i;
   return p;
 }
@@ -79,7 +71,6 @@ rts_mkInt64 (HsInt64 i)
 {
   long long *tmp;
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2));
-  /* see mk_Int8 comment */
   p->header.info = I64zh_con_info;
   tmp  = (long long*)&(p->payload[0]);
   *tmp = (StgInt64)i;
@@ -100,7 +91,7 @@ rts_mkWord8 (HsWord8 w)
 {
   /* see rts_mkInt* comments */
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
-  p->header.info = Wzh_con_info;
+  p->header.info = W8zh_con_info;
   p->payload[0]  = (StgClosure *)(StgWord)(w & 0xff);
   return p;
 }
@@ -110,7 +101,7 @@ rts_mkWord16 (HsWord16 w)
 {
   /* see rts_mkInt* comments */
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
-  p->header.info = Wzh_con_info;
+  p->header.info = W16zh_con_info;
   p->payload[0]  = (StgClosure *)(StgWord)(w & 0xffff);
   return p;
 }
@@ -120,7 +111,7 @@ rts_mkWord32 (HsWord32 w)
 {
   /* see rts_mkInt* comments */
   StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
-  p->header.info = Wzh_con_info;
+  p->header.info = W32zh_con_info;
   p->payload[0]  = (StgClosure *)(StgWord)w;
   return p;
 }
@@ -166,10 +157,10 @@ rts_mkStablePtr (HsStablePtr s)
 }
 
 HaskellObj
-rts_mkAddr (HsAddr a)
+rts_mkPtr (HsPtr a)
 {
   StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1);
-  p->header.info = Azh_con_info;
+  p->header.info = Ptr_con_info;
   p->payload[0]  = (StgClosure *)a;
   return p;
 }
@@ -188,7 +179,7 @@ rts_mkBool (HsBool b)
 HaskellObj
 rts_mkString (char *s)
 {
-  return rts_apply((StgClosure *)unpackCString_closure, rts_mkAddr(s));
+  return rts_apply((StgClosure *)unpackCString_closure, rts_mkPtr(s));
 }
 #endif /* COMPILER */
 
@@ -214,7 +205,7 @@ rts_getChar (HaskellObj p)
        p->header.info == Czh_static_info) {
     return (StgChar)(StgWord)(p->payload[0]);
   } else {
-    barf("getChar: not a Char");
+    barf("rts_getChar: not a Char");
   }
 }
 
@@ -224,9 +215,33 @@ rts_getInt (HaskellObj p)
   if ( 1 ||
        p->header.info == Izh_con_info || 
        p->header.info == Izh_static_info ) {
-    return (int)(p->payload[0]);
+    return (HsInt)(p->payload[0]);
+  } else {
+    barf("rts_getInt: not an Int");
+  }
+}
+
+HsInt8
+rts_getInt8 (HaskellObj p)
+{
+  if ( 1 ||
+       p->header.info == I8zh_con_info || 
+       p->header.info == I8zh_static_info ) {
+    return (HsInt8)(HsInt)(p->payload[0]);
   } else {
-    barf("getInt: not an Int");
+    barf("rts_getInt8: not an Int8");
+  }
+}
+
+HsInt16
+rts_getInt16 (HaskellObj p)
+{
+  if ( 1 ||
+       p->header.info == I16zh_con_info || 
+       p->header.info == I16zh_static_info ) {
+    return (HsInt16)(HsInt)(p->payload[0]);
+  } else {
+    barf("rts_getInt16: not an Int16");
   }
 }
 
@@ -234,23 +249,60 @@ HsInt32
 rts_getInt32 (HaskellObj p)
 {
   if ( 1 ||
-       p->header.info == Izh_con_info || 
-       p->header.info == Izh_static_info ) {
-    return (int)(p->payload[0]);
+       p->header.info == I32zh_con_info || 
+       p->header.info == I32zh_static_info ) {
+    return (HsInt32)(p->payload[0]);
   } else {
-    barf("getInt: not an Int");
+    barf("rts_getInt32: not an Int32");
   }
 }
 
+HsInt64
+rts_getInt64 (HaskellObj p)
+{
+  HsInt64* tmp;
+  if ( 1 ||
+       p->header.info == I64zh_con_info || 
+       p->header.info == I64zh_static_info ) {
+    tmp = (HsInt64*)&(p->payload[0]);
+    return *tmp;
+  } else {
+    barf("rts_getInt64: not an Int64");
+  }
+}
 HsWord
 rts_getWord (HaskellObj p)
 {
   if ( 1 || /* see above comment */
        p->header.info == Wzh_con_info ||
        p->header.info == Wzh_static_info ) {
-    return (unsigned int)(p->payload[0]);
+    return (HsWord)(p->payload[0]);
   } else {
-    barf("getWord: not a Word");
+    barf("rts_getWord: not a Word");
+  }
+}
+
+HsWord8
+rts_getWord8 (HaskellObj p)
+{
+  if ( 1 || /* see above comment */
+       p->header.info == W8zh_con_info ||
+       p->header.info == W8zh_static_info ) {
+    return (HsWord8)(HsWord)(p->payload[0]);
+  } else {
+    barf("rts_getWord8: not a Word8");
+  }
+}
+
+HsWord16
+rts_getWord16 (HaskellObj p)
+{
+  if ( 1 || /* see above comment */
+       p->header.info == W16zh_con_info ||
+       p->header.info == W16zh_static_info ) {
+    return (HsWord16)(HsWord)(p->payload[0]);
+  } else {
+    barf("rts_getWord16: not a Word16");
   }
 }
 
@@ -258,11 +310,26 @@ HsWord32
 rts_getWord32 (HaskellObj p)
 {
   if ( 1 || /* see above comment */
-       p->header.info == Wzh_con_info ||
-       p->header.info == Wzh_static_info ) {
+       p->header.info == W32zh_con_info ||
+       p->header.info == W32zh_static_info ) {
     return (unsigned int)(p->payload[0]);
   } else {
-    barf("getWord: not a Word");
+    barf("rts_getWord: not a Word");
+  }
+}
+
+
+HsWord64
+rts_getWord64 (HaskellObj p)
+{
+  HsWord64* tmp;
+  if ( 1 || /* see above comment */
+       p->header.info == W64zh_con_info ||
+       p->header.info == W64zh_static_info ) {
+    tmp = (HsWord64*)&(p->payload[0]);
+    return *tmp;
+  } else {
+    barf("rts_getWord64: not a Word64");
   }
 }
 
@@ -273,7 +340,7 @@ rts_getFloat (HaskellObj p)
        p->header.info == Fzh_static_info ) {
     return (float)(PK_FLT((P_)p->payload));
   } else {
-    barf("getFloat: not a Float");
+    barf("rts_getFloat: not a Float");
   }
 }
 
@@ -284,7 +351,7 @@ rts_getDouble (HaskellObj p)
        p->header.info == Dzh_static_info ) {
     return (double)(PK_DBL((P_)p->payload));
   } else {
-    barf("getDouble: not a Double");
+    barf("rts_getDouble: not a Double");
   }
 }
 
@@ -295,19 +362,18 @@ rts_getStablePtr (HaskellObj p)
        p->header.info == StablePtr_static_info ) {
     return (StgStablePtr)(p->payload[0]);
   } else {
-    barf("getStablePtr: not a StablePtr");
+    barf("rts_getStablePtr: not a StablePtr");
   }
 }
 
-HsAddr
-rts_getAddr (HaskellObj p)
+HsPtr
+rts_getPtr (HaskellObj p)
 {
-  if ( p->header.info == Azh_con_info || 
-       p->header.info == Azh_static_info ) {
-  
+  if ( p->header.info == Ptr_con_info || 
+       p->header.info == Ptr_static_info ) {
     return (void *)(p->payload[0]);
   } else {
-    barf("getAddr: not an Addr");
+    barf("rts_getPtr: not an Ptr");
   }
 }
 
@@ -320,7 +386,7 @@ rts_getBool (HaskellObj p)
   } else if (p == False_closure) {
     return 0;
   } else {
-    barf("getBool: not a Bool");
+    barf("rts_getBool: not a Bool");
   }
 }
 #endif /* COMPILER */
@@ -367,21 +433,6 @@ rts_evalLazyIO (HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret)
   return waitThread(tso, ret);
 }
 
-#if defined(PAR) || defined(SMP)
-/*
-  Needed in the parallel world for non-Main PEs, which do not get a piece
-  of work to start with --- they have to humbly ask for it
-*/
-
-SchedulerStatus
-rts_evalNothing(unsigned int stack_size)
-{
-  /* ToDo: propagate real SchedulerStatus back to caller */
-  scheduleThread(END_TSO_QUEUE);
-  return Success;
-}
-#endif
-
 /* Convenience function for decoding the returned status. */
 
 void