X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FRtsAPI.c;h=5f8648bb86a8c080caf6a10bda8991c548382043;hb=8813f77032fc4898a908fa63f75e21de32a0b072;hp=d4214d14a872fe0478efffe3522f740cbd1e5087;hpb=7f309f1c021e7583f724cce599ce2dd3c439361b;p=ghc-hetmet.git diff --git a/ghc/rts/RtsAPI.c b/ghc/rts/RtsAPI.c index d4214d1..5f8648b 100644 --- a/ghc/rts/RtsAPI.c +++ b/ghc/rts/RtsAPI.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- - * $Id: RtsAPI.c,v 1.4 1999/02/05 16:02:49 simonm Exp $ + * $Id: RtsAPI.c,v 1.7 1999/05/21 14:46:19 sof Exp $ * * (c) The GHC Team, 1998-1999 * @@ -20,7 +20,7 @@ HaskellObj rts_mkChar (char c) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Czh_con_info; + p->header.info = (const StgInfoTable*)&Czh_con_info; p->payload[0] = (StgClosure *)((StgInt)c); return p; } @@ -29,7 +29,7 @@ HaskellObj rts_mkInt (int i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Izh_con_info; + p->header.info = (const StgInfoTable*)&Izh_con_info; p->payload[0] = (StgClosure *)(StgInt)i; return p; } @@ -42,7 +42,7 @@ rts_mkInt8 (int i) instead of the one for Int8, but the types have identical representation. */ - p->header.info = &Izh_con_info; + p->header.info = (const StgInfoTable*)&Izh_con_info; /* Make sure we mask out the bits above the lowest 8 */ p->payload[0] = (StgClosure *)(StgInt)((unsigned)i & 0xff); return p; @@ -56,7 +56,7 @@ rts_mkInt16 (int i) instead of the one for Int8, but the types have identical representation. */ - p->header.info = &Izh_con_info; + p->header.info = (const StgInfoTable*)&Izh_con_info; /* Make sure we mask out the relevant bits */ p->payload[0] = (StgClosure *)(StgInt)((unsigned)i & 0xffff); return p; @@ -67,7 +67,7 @@ rts_mkInt32 (int i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); /* see mk_Int8 comment */ - p->header.info = &Izh_con_info; + p->header.info = (const StgInfoTable*)&Izh_con_info; p->payload[0] = (StgClosure *)(StgInt)i; return p; } @@ -78,7 +78,7 @@ rts_mkInt64 (long long int i) long long *tmp; StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2)); /* see mk_Int8 comment */ - p->header.info = &I64zh_con_info; + p->header.info = (const StgInfoTable*)&I64zh_con_info; tmp = (long long*)&(p->payload[0]); *tmp = (StgInt64)i; return p; @@ -88,7 +88,7 @@ HaskellObj rts_mkWord (unsigned int i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Wzh_con_info; + p->header.info = (const StgInfoTable*)&Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)i; return p; } @@ -98,7 +98,7 @@ rts_mkWord8 (unsigned int w) { /* see rts_mkInt* comments */ StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Wzh_con_info; + p->header.info = (const StgInfoTable*)&Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)(w & 0xff); return p; } @@ -108,7 +108,7 @@ rts_mkWord16 (unsigned int w) { /* see rts_mkInt* comments */ StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Wzh_con_info; + p->header.info = (const StgInfoTable*)&Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)(w & 0xffff); return p; } @@ -118,7 +118,7 @@ rts_mkWord32 (unsigned int w) { /* see rts_mkInt* comments */ StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Wzh_con_info; + p->header.info = (const StgInfoTable*)&Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)w; return p; } @@ -127,13 +127,12 @@ HaskellObj rts_mkWord64 (unsigned long long w) { unsigned long long *tmp; - extern StgInfoTable W64zh_con_info; StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2)); /* see mk_Int8 comment */ - p->header.info = &W64zh_con_info; + p->header.info = (const StgInfoTable*)&W64zh_con_info; tmp = (unsigned long long*)&(p->payload[0]); - *tmp = (StgNat64)w; + *tmp = (StgWord64)w; return p; } @@ -141,7 +140,7 @@ HaskellObj rts_mkFloat (float f) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = &Fzh_con_info; + p->header.info = (const StgInfoTable*)&Fzh_con_info; ASSIGN_FLT((P_)p->payload, (StgFloat)f); return p; } @@ -150,7 +149,7 @@ HaskellObj rts_mkDouble (double d) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,sizeofW(StgDouble))); - p->header.info = &Dzh_con_info; + p->header.info = (const StgInfoTable*)&Dzh_con_info; ASSIGN_DBL((P_)p->payload, (StgDouble)d); return p; } @@ -159,7 +158,7 @@ HaskellObj rts_mkStablePtr (StgStablePtr s) { StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1); - p->header.info = &StablePtr_con_info; + p->header.info = (const StgInfoTable*)&StablePtr_con_info; p->payload[0] = (StgClosure *)s; return p; } @@ -168,7 +167,7 @@ HaskellObj rts_mkAddr (void *a) { StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1); - p->header.info = &Azh_con_info; + p->header.info = (const StgInfoTable*)&Azh_con_info; p->payload[0] = (StgClosure *)a; return p; } @@ -209,7 +208,8 @@ rts_apply (HaskellObj f, HaskellObj arg) char rts_getChar (HaskellObj p) { - if (p->header.info == &Czh_con_info || p->header.info == &Czh_static_info) { + if ( p->header.info == (const StgInfoTable*)&Czh_con_info || + p->header.info == (const StgInfoTable*)&Czh_static_info) { return (char)(StgWord)(p->payload[0]); } else { barf("getChar: not a Char"); @@ -219,7 +219,21 @@ rts_getChar (HaskellObj p) int rts_getInt (HaskellObj p) { - if (p->header.info == &Izh_con_info || p->header.info == &Izh_static_info) { + if ( 1 || + p->header.info == (const StgInfoTable*)&Izh_con_info || + p->header.info == (const StgInfoTable*)&Izh_static_info ) { + return (int)(p->payload[0]); + } else { + barf("getInt: not an Int"); + } +} + +int +rts_getInt32 (HaskellObj p) +{ + if ( 1 || + p->header.info == (const StgInfoTable*)&Izh_con_info || + p->header.info == (const StgInfoTable*)&Izh_static_info ) { return (int)(p->payload[0]); } else { barf("getInt: not an Int"); @@ -229,7 +243,21 @@ rts_getInt (HaskellObj p) unsigned int rts_getWord (HaskellObj p) { - if (p->header.info == &Wzh_con_info || p->header.info == &Wzh_static_info) { + if ( 1 || /* see above comment */ + p->header.info == (const StgInfoTable*)&Wzh_con_info || + p->header.info == (const StgInfoTable*)&Wzh_static_info ) { + return (unsigned int)(p->payload[0]); + } else { + barf("getWord: not a Word"); + } +} + +unsigned int +rts_getWord32 (HaskellObj p) +{ + if ( 1 || /* see above comment */ + p->header.info == (const StgInfoTable*)&Wzh_con_info || + p->header.info == (const StgInfoTable*)&Wzh_static_info ) { return (unsigned int)(p->payload[0]); } else { barf("getWord: not a Word"); @@ -239,7 +267,8 @@ rts_getWord (HaskellObj p) float rts_getFloat (HaskellObj p) { - if (p->header.info == &Fzh_con_info || p->header.info == &Fzh_static_info) { + if ( p->header.info == (const StgInfoTable*)&Fzh_con_info || + p->header.info == (const StgInfoTable*)&Fzh_static_info ) { return (float)(PK_FLT((P_)p->payload)); } else { barf("getFloat: not a Float"); @@ -249,7 +278,8 @@ rts_getFloat (HaskellObj p) double rts_getDouble (HaskellObj p) { - if (p->header.info == &Dzh_con_info || p->header.info == &Dzh_static_info) { + if ( p->header.info == (const StgInfoTable*)&Dzh_con_info || + p->header.info == (const StgInfoTable*)&Dzh_static_info ) { return (double)(PK_DBL((P_)p->payload)); } else { barf("getDouble: not a Double"); @@ -259,8 +289,8 @@ rts_getDouble (HaskellObj p) StgStablePtr rts_getStablePtr (HaskellObj p) { - if (p->header.info == &StablePtr_con_info || - p->header.info == &StablePtr_static_info) { + if ( p->header.info == (const StgInfoTable*)&StablePtr_con_info || + p->header.info == (const StgInfoTable*)&StablePtr_static_info ) { return (StgStablePtr)(p->payload[0]); } else { barf("getStablePtr: not a StablePtr"); @@ -270,7 +300,9 @@ rts_getStablePtr (HaskellObj p) void * rts_getAddr (HaskellObj p) { - if (p->header.info == &Azh_con_info || p->header.info == &Azh_static_info) { + if ( p->header.info == (const StgInfoTable*)&Azh_con_info || + p->header.info == (const StgInfoTable*)&Azh_static_info ) { + return (void *)(p->payload[0]); } else { barf("getAddr: not an Addr"); @@ -308,15 +340,22 @@ rts_eval_ (HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret) return schedule(tso, ret); } +/* + * rts_evalIO() evaluates a value of the form (IO a), forcing the action's + * result to WHNF before returning. + */ SchedulerStatus rts_evalIO (HaskellObj p, /*out*/HaskellObj *ret) { - StgTSO *tso = createIOThread(RtsFlags.GcFlags.initialStkSize, p); + StgTSO* tso = createStrictIOThread(RtsFlags.GcFlags.initialStkSize, p); return schedule(tso, ret); } +/* + * Like rts_evalIO(), but doesn't force the action's result. + */ SchedulerStatus -rts_evalIO_ (HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret) +rts_evalLazyIO (HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret) { StgTSO *tso = createIOThread(stack_size, p); return schedule(tso, ret);