/* ----------------------------------------------------------------------------
- * $Id: RtsAPI.c,v 1.22 2000/11/13 14:40:37 simonmar Exp $
+ * $Id: RtsAPI.c,v 1.29 2001/08/29 11:20:40 simonmar 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"
rts_mkChar (HsChar c)
{
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Czh_con_info;
+ SET_HDR(p, Czh_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)(StgChar)c;
return p;
}
rts_mkInt (HsInt i)
{
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Izh_con_info;
+ SET_HDR(p, Izh_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)(StgInt)i;
return p;
}
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;
+ SET_HDR(p, I8zh_con_info, CCS_SYSTEM);
/* Make sure we mask out the bits above the lowest 8 */
p->payload[0] = (StgClosure *)(StgInt)((unsigned)i & 0xff);
return p;
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;
+ SET_HDR(p, I16zh_con_info, CCS_SYSTEM);
/* Make sure we mask out the relevant bits */
p->payload[0] = (StgClosure *)(StgInt)((unsigned)i & 0xffff);
return p;
rts_mkInt32 (HsInt32 i)
{
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- /* see mk_Int8 comment */
- p->header.info = Izh_con_info;
- p->payload[0] = (StgClosure *)(StgInt)i;
+ SET_HDR(p, I32zh_con_info, CCS_SYSTEM);
+ p->payload[0] = (StgClosure *)(StgInt)((unsigned)i & 0xffffffff);
return p;
}
{
long long *tmp;
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2));
- /* see mk_Int8 comment */
- p->header.info = I64zh_con_info;
+ SET_HDR(p, I64zh_con_info, CCS_SYSTEM);
tmp = (long long*)&(p->payload[0]);
*tmp = (StgInt64)i;
return p;
rts_mkWord (HsWord i)
{
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Wzh_con_info;
+ SET_HDR(p, Wzh_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)(StgWord)i;
return p;
}
{
/* see rts_mkInt* comments */
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Wzh_con_info;
+ SET_HDR(p, W8zh_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)(StgWord)(w & 0xff);
return p;
}
{
/* see rts_mkInt* comments */
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Wzh_con_info;
+ SET_HDR(p, W16zh_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)(StgWord)(w & 0xffff);
return p;
}
{
/* see rts_mkInt* comments */
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Wzh_con_info;
- p->payload[0] = (StgClosure *)(StgWord)w;
+ SET_HDR(p, W32zh_con_info, CCS_SYSTEM);
+ p->payload[0] = (StgClosure *)(StgWord)(w & 0xffffffff);
return p;
}
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2));
/* see mk_Int8 comment */
- p->header.info = W64zh_con_info;
+ SET_HDR(p, W64zh_con_info, CCS_SYSTEM);
tmp = (unsigned long long*)&(p->payload[0]);
*tmp = (StgWord64)w;
return p;
rts_mkFloat (HsFloat f)
{
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1));
- p->header.info = Fzh_con_info;
+ SET_HDR(p, Fzh_con_info, CCS_SYSTEM);
ASSIGN_FLT((P_)p->payload, (StgFloat)f);
return p;
}
rts_mkDouble (HsDouble d)
{
StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,sizeofW(StgDouble)));
- p->header.info = Dzh_con_info;
+ SET_HDR(p, Dzh_con_info, CCS_SYSTEM);
ASSIGN_DBL((P_)p->payload, (StgDouble)d);
return p;
}
rts_mkStablePtr (HsStablePtr s)
{
StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1);
- p->header.info = StablePtr_con_info;
+ SET_HDR(p, StablePtr_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)s;
return p;
}
HaskellObj
-rts_mkAddr (HsAddr a)
+rts_mkPtr (HsPtr a)
{
StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1);
- p->header.info = Azh_con_info;
+ SET_HDR(p, Ptr_con_info, CCS_SYSTEM);
p->payload[0] = (StgClosure *)a;
return p;
}
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 */
p->header.info == Czh_static_info) {
return (StgChar)(StgWord)(p->payload[0]);
} else {
- barf("getChar: not a Char");
+ barf("rts_getChar: not a Char");
}
}
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("getInt: not an Int");
+ 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("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");
}
}
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("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("getWord: not a Word");
+ 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");
}
}
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");
}
}
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");
}
}
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");
}
}
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");
}
}
} else if (p == False_closure) {
return 0;
} else {
- barf("getBool: not a Bool");
+ barf("rts_getBool: not a Bool");
}
}
#endif /* COMPILER */
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