X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FRtsAPI.c;h=992be891a577aae9b8d07f81021d29dce3d77c58;hb=efcd3f2b7aabe23e30ab482db1ed2eee5075e095;hp=5f8648bb86a8c080caf6a10bda8991c548382043;hpb=263aaaa57bf5564d06de6a87ebccb980b1b5d285;p=ghc-hetmet.git diff --git a/ghc/rts/RtsAPI.c b/ghc/rts/RtsAPI.c index 5f8648b..992be89 100644 --- a/ghc/rts/RtsAPI.c +++ b/ghc/rts/RtsAPI.c @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------------------- - * $Id: RtsAPI.c,v 1.7 1999/05/21 14:46:19 sof Exp $ + * $Id: RtsAPI.c,v 1.17 2000/04/26 10:17:41 simonmar Exp $ * - * (c) The GHC Team, 1998-1999 + * (c) The GHC Team, 1998-2000 * * API for invoking Haskell functions via the RTS * @@ -10,8 +10,10 @@ #include "Rts.h" #include "Storage.h" #include "RtsAPI.h" +#include "SchedAPI.h" #include "RtsFlags.h" #include "RtsUtils.h" +#include "Prelude.h" /* ---------------------------------------------------------------------------- Building Haskell objects from C datatypes. @@ -20,7 +22,7 @@ HaskellObj rts_mkChar (char c) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Czh_con_info; + p->header.info = Czh_con_info; p->payload[0] = (StgClosure *)((StgInt)c); return p; } @@ -29,7 +31,7 @@ HaskellObj rts_mkInt (int i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Izh_con_info; + p->header.info = Izh_con_info; p->payload[0] = (StgClosure *)(StgInt)i; return p; } @@ -42,7 +44,7 @@ rts_mkInt8 (int i) instead of the one for Int8, but the types have identical representation. */ - p->header.info = (const StgInfoTable*)&Izh_con_info; + p->header.info = 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 +58,7 @@ rts_mkInt16 (int i) instead of the one for Int8, but the types have identical representation. */ - p->header.info = (const StgInfoTable*)&Izh_con_info; + p->header.info = Izh_con_info; /* Make sure we mask out the relevant bits */ p->payload[0] = (StgClosure *)(StgInt)((unsigned)i & 0xffff); return p; @@ -67,7 +69,7 @@ rts_mkInt32 (int i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); /* see mk_Int8 comment */ - p->header.info = (const StgInfoTable*)&Izh_con_info; + p->header.info = Izh_con_info; p->payload[0] = (StgClosure *)(StgInt)i; return p; } @@ -78,7 +80,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 = (const StgInfoTable*)&I64zh_con_info; + p->header.info = I64zh_con_info; tmp = (long long*)&(p->payload[0]); *tmp = (StgInt64)i; return p; @@ -88,7 +90,7 @@ HaskellObj rts_mkWord (unsigned int i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Wzh_con_info; + p->header.info = Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)i; return p; } @@ -98,7 +100,7 @@ rts_mkWord8 (unsigned int w) { /* see rts_mkInt* comments */ StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Wzh_con_info; + p->header.info = Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)(w & 0xff); return p; } @@ -108,7 +110,7 @@ rts_mkWord16 (unsigned int w) { /* see rts_mkInt* comments */ StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Wzh_con_info; + p->header.info = Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)(w & 0xffff); return p; } @@ -118,7 +120,7 @@ rts_mkWord32 (unsigned int w) { /* see rts_mkInt* comments */ StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Wzh_con_info; + p->header.info = Wzh_con_info; p->payload[0] = (StgClosure *)(StgWord)w; return p; } @@ -130,7 +132,7 @@ rts_mkWord64 (unsigned long long w) StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,2)); /* see mk_Int8 comment */ - p->header.info = (const StgInfoTable*)&W64zh_con_info; + p->header.info = W64zh_con_info; tmp = (unsigned long long*)&(p->payload[0]); *tmp = (StgWord64)w; return p; @@ -140,7 +142,7 @@ HaskellObj rts_mkFloat (float f) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); - p->header.info = (const StgInfoTable*)&Fzh_con_info; + p->header.info = Fzh_con_info; ASSIGN_FLT((P_)p->payload, (StgFloat)f); return p; } @@ -149,7 +151,7 @@ HaskellObj rts_mkDouble (double d) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,sizeofW(StgDouble))); - p->header.info = (const StgInfoTable*)&Dzh_con_info; + p->header.info = Dzh_con_info; ASSIGN_DBL((P_)p->payload, (StgDouble)d); return p; } @@ -158,7 +160,7 @@ HaskellObj rts_mkStablePtr (StgStablePtr s) { StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1); - p->header.info = (const StgInfoTable*)&StablePtr_con_info; + p->header.info = StablePtr_con_info; p->payload[0] = (StgClosure *)s; return p; } @@ -167,39 +169,39 @@ HaskellObj rts_mkAddr (void *a) { StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1); - p->header.info = (const StgInfoTable*)&Azh_con_info; + p->header.info = Azh_con_info; p->payload[0] = (StgClosure *)a; return p; } #ifdef COMPILER /* GHC has em, Hugs doesn't */ HaskellObj -rts_mkBool (int b) +rts_mkBool (StgBool b) { if (b) { - return (StgClosure *)&True_closure; + return (StgClosure *)True_closure; } else { - return (StgClosure *)&False_closure; + return (StgClosure *)False_closure; } } HaskellObj rts_mkString (char *s) { - return rts_apply((StgClosure *)&unpackCString_closure, rts_mkAddr(s)); + return rts_apply((StgClosure *)unpackCString_closure, rts_mkAddr(s)); } +#endif /* COMPILER */ HaskellObj rts_apply (HaskellObj f, HaskellObj arg) { StgAP_UPD *ap = (StgAP_UPD *)allocate(AP_sizeW(1)); - ap->header.info = &AP_UPD_info; + SET_HDR(ap, &AP_UPD_info, CCS_SYSTEM); ap->n_args = 1; ap->fun = f; ap->payload[0] = (P_)arg; return (StgClosure *)ap; } -#endif /* COMPILER */ /* ---------------------------------------------------------------------------- Deconstructing Haskell objects @@ -208,8 +210,8 @@ rts_apply (HaskellObj f, HaskellObj arg) char rts_getChar (HaskellObj p) { - if ( p->header.info == (const StgInfoTable*)&Czh_con_info || - p->header.info == (const StgInfoTable*)&Czh_static_info) { + if ( p->header.info == Czh_con_info || + p->header.info == Czh_static_info) { return (char)(StgWord)(p->payload[0]); } else { barf("getChar: not a Char"); @@ -220,8 +222,8 @@ int rts_getInt (HaskellObj p) { if ( 1 || - p->header.info == (const StgInfoTable*)&Izh_con_info || - p->header.info == (const StgInfoTable*)&Izh_static_info ) { + p->header.info == Izh_con_info || + p->header.info == Izh_static_info ) { return (int)(p->payload[0]); } else { barf("getInt: not an Int"); @@ -232,8 +234,8 @@ int rts_getInt32 (HaskellObj p) { if ( 1 || - p->header.info == (const StgInfoTable*)&Izh_con_info || - p->header.info == (const StgInfoTable*)&Izh_static_info ) { + p->header.info == Izh_con_info || + p->header.info == Izh_static_info ) { return (int)(p->payload[0]); } else { barf("getInt: not an Int"); @@ -244,8 +246,8 @@ unsigned int rts_getWord (HaskellObj p) { if ( 1 || /* see above comment */ - p->header.info == (const StgInfoTable*)&Wzh_con_info || - p->header.info == (const StgInfoTable*)&Wzh_static_info ) { + p->header.info == Wzh_con_info || + p->header.info == Wzh_static_info ) { return (unsigned int)(p->payload[0]); } else { barf("getWord: not a Word"); @@ -256,8 +258,8 @@ 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 ) { + p->header.info == Wzh_con_info || + p->header.info == Wzh_static_info ) { return (unsigned int)(p->payload[0]); } else { barf("getWord: not a Word"); @@ -267,8 +269,8 @@ rts_getWord32 (HaskellObj p) float rts_getFloat (HaskellObj p) { - if ( p->header.info == (const StgInfoTable*)&Fzh_con_info || - p->header.info == (const StgInfoTable*)&Fzh_static_info ) { + if ( p->header.info == Fzh_con_info || + p->header.info == Fzh_static_info ) { return (float)(PK_FLT((P_)p->payload)); } else { barf("getFloat: not a Float"); @@ -278,8 +280,8 @@ rts_getFloat (HaskellObj p) double rts_getDouble (HaskellObj p) { - if ( p->header.info == (const StgInfoTable*)&Dzh_con_info || - p->header.info == (const StgInfoTable*)&Dzh_static_info ) { + if ( p->header.info == Dzh_con_info || + p->header.info == Dzh_static_info ) { return (double)(PK_DBL((P_)p->payload)); } else { barf("getDouble: not a Double"); @@ -289,8 +291,8 @@ rts_getDouble (HaskellObj p) StgStablePtr rts_getStablePtr (HaskellObj p) { - if ( p->header.info == (const StgInfoTable*)&StablePtr_con_info || - p->header.info == (const StgInfoTable*)&StablePtr_static_info ) { + if ( p->header.info == StablePtr_con_info || + p->header.info == StablePtr_static_info ) { return (StgStablePtr)(p->payload[0]); } else { barf("getStablePtr: not a StablePtr"); @@ -300,8 +302,8 @@ rts_getStablePtr (HaskellObj p) void * rts_getAddr (HaskellObj p) { - if ( p->header.info == (const StgInfoTable*)&Azh_con_info || - p->header.info == (const StgInfoTable*)&Azh_static_info ) { + if ( p->header.info == Azh_con_info || + p->header.info == Azh_static_info ) { return (void *)(p->payload[0]); } else { @@ -313,9 +315,9 @@ rts_getAddr (HaskellObj p) int rts_getBool (HaskellObj p) { - if (p == &True_closure) { + if (p == True_closure) { return 1; - } else if (p == &False_closure) { + } else if (p == False_closure) { return 0; } else { barf("getBool: not a Bool"); @@ -330,14 +332,16 @@ SchedulerStatus rts_eval (HaskellObj p, /*out*/HaskellObj *ret) { StgTSO *tso = createGenThread(RtsFlags.GcFlags.initialStkSize, p); - return schedule(tso, ret); + scheduleThread(tso); + return waitThread(tso, ret); } SchedulerStatus rts_eval_ (HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret) { StgTSO *tso = createGenThread(stack_size, p); - return schedule(tso, ret); + scheduleThread(tso); + return waitThread(tso, ret); } /* @@ -348,7 +352,8 @@ SchedulerStatus rts_evalIO (HaskellObj p, /*out*/HaskellObj *ret) { StgTSO* tso = createStrictIOThread(RtsFlags.GcFlags.initialStkSize, p); - return schedule(tso, ret); + scheduleThread(tso); + return waitThread(tso, ret); } /* @@ -358,16 +363,40 @@ SchedulerStatus rts_evalLazyIO (HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret) { StgTSO *tso = createIOThread(stack_size, p); - return schedule(tso, ret); + scheduleThread(tso); + return waitThread(tso, ret); } -/* Convenience function for decoding the returned status. */ +#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 +*/ -void rts_checkSchedStatus ( char* site, SchedulerStatus rc ) +SchedulerStatus +rts_evalNothing(unsigned int stack_size) { - if ( rc == Success ) { - return; - } else { - barf("%s: Return code (%d) not ok",(site),(rc)); - } + /* ToDo: propagate real SchedulerStatus back to caller */ + scheduleThread(END_TSO_QUEUE); + return Success; +} +#endif + +/* Convenience function for decoding the returned status. */ + +void +rts_checkSchedStatus ( char* site, SchedulerStatus rc ) +{ + switch (rc) { + case Success: + return; + case Killed: + barf("%s: uncaught exception",site); + case Interrupted: + barf("%s: interrupted", site); + case Deadlock: + barf("%s: no threads to run: infinite loop or deadlock?", site); + default: + barf("%s: Return code (%d) not ok",(site),(rc)); + } }