X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FRtsAPI.c;h=ea3e4a5fc0c10a1e65e7d2b24bf22e5cab41a835;hb=9213df4a0c5a8f121832d36d6d3afbf1c80f1a0a;hp=7ab8b444bc7533861ef68519631ff3c1588186fe;hpb=78edf8c95325edf57f5b87fd85f924ce1dfdb200;p=ghc-hetmet.git diff --git a/ghc/rts/RtsAPI.c b/ghc/rts/RtsAPI.c index 7ab8b44..ea3e4a5 100644 --- a/ghc/rts/RtsAPI.c +++ b/ghc/rts/RtsAPI.c @@ -1,7 +1,7 @@ /* ---------------------------------------------------------------------------- - * $Id: RtsAPI.c,v 1.16 2000/04/25 14:57:39 simonmar Exp $ + * $Id: RtsAPI.c,v 1.26 2001/03/22 03:51:10 hwloidl Exp $ * - * (c) The GHC Team, 1998-2000 + * (c) The GHC Team, 1998-2001 * * API for invoking Haskell functions via the RTS * @@ -19,16 +19,16 @@ Building Haskell objects from C datatypes. ------------------------------------------------------------------------- */ HaskellObj -rts_mkChar (char c) +rts_mkChar (HsChar c) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); p->header.info = Czh_con_info; - p->payload[0] = (StgClosure *)((StgInt)c); + p->payload[0] = (StgClosure *)(StgChar)c; return p; } HaskellObj -rts_mkInt (int i) +rts_mkInt (HsInt i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); p->header.info = Izh_con_info; @@ -37,49 +37,39 @@ rts_mkInt (int i) } HaskellObj -rts_mkInt8 (int i) +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; } HaskellObj -rts_mkInt16 (int i) +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; } HaskellObj -rts_mkInt32 (int i) +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; } HaskellObj -rts_mkInt64 (long long int i) +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; @@ -87,7 +77,7 @@ rts_mkInt64 (long long int i) } HaskellObj -rts_mkWord (unsigned int i) +rts_mkWord (HsWord i) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); p->header.info = Wzh_con_info; @@ -96,37 +86,37 @@ rts_mkWord (unsigned int i) } HaskellObj -rts_mkWord8 (unsigned int w) +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; } HaskellObj -rts_mkWord16 (unsigned int w) +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; } HaskellObj -rts_mkWord32 (unsigned int w) +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; } HaskellObj -rts_mkWord64 (unsigned long long w) +rts_mkWord64 (HsWord64 w) { unsigned long long *tmp; @@ -139,7 +129,7 @@ rts_mkWord64 (unsigned long long w) } HaskellObj -rts_mkFloat (float f) +rts_mkFloat (HsFloat f) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,1)); p->header.info = Fzh_con_info; @@ -148,7 +138,7 @@ rts_mkFloat (float f) } HaskellObj -rts_mkDouble (double d) +rts_mkDouble (HsDouble d) { StgClosure *p = (StgClosure *)allocate(CONSTR_sizeW(0,sizeofW(StgDouble))); p->header.info = Dzh_con_info; @@ -157,7 +147,7 @@ rts_mkDouble (double d) } HaskellObj -rts_mkStablePtr (StgStablePtr s) +rts_mkStablePtr (HsStablePtr s) { StgClosure *p = (StgClosure *)allocate(sizeofW(StgHeader)+1); p->header.info = StablePtr_con_info; @@ -166,17 +156,17 @@ rts_mkStablePtr (StgStablePtr s) } HaskellObj -rts_mkAddr (void *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; } #ifdef COMPILER /* GHC has em, Hugs doesn't */ HaskellObj -rts_mkBool (StgBool b) +rts_mkBool (HsBool b) { if (b) { return (StgClosure *)True_closure; @@ -188,7 +178,7 @@ rts_mkBool (StgBool 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 */ @@ -196,10 +186,10 @@ HaskellObj rts_apply (HaskellObj f, HaskellObj arg) { StgAP_UPD *ap = (StgAP_UPD *)allocate(AP_sizeW(1)); - SET_HDR(ap, &AP_UPD_info, CCS_SYSTEM); + SET_HDR(ap, &stg_AP_UPD_info, CCS_SYSTEM); ap->n_args = 1; ap->fun = f; - ap->payload[0] = (P_)arg; + ap->payload[0] = arg; return (StgClosure *)ap; } @@ -207,18 +197,18 @@ rts_apply (HaskellObj f, HaskellObj arg) Deconstructing Haskell objects ------------------------------------------------------------------------- */ -char +HsChar rts_getChar (HaskellObj p) { if ( p->header.info == Czh_con_info || p->header.info == Czh_static_info) { - return (char)(StgWord)(p->payload[0]); + return (StgChar)(StgWord)(p->payload[0]); } else { barf("getChar: not a Char"); } } -int +HsInt rts_getInt (HaskellObj p) { if ( 1 || @@ -230,19 +220,19 @@ rts_getInt (HaskellObj p) } } -int +HsInt32 rts_getInt32 (HaskellObj p) { if ( 1 || - p->header.info == Izh_con_info || - p->header.info == Izh_static_info ) { + p->header.info == I32zh_con_info || + p->header.info == I32zh_static_info ) { return (int)(p->payload[0]); } else { barf("getInt: not an Int"); } } -unsigned int +HsWord rts_getWord (HaskellObj p) { if ( 1 || /* see above comment */ @@ -254,19 +244,19 @@ rts_getWord (HaskellObj p) } } -unsigned int +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"); } } -float +HsFloat rts_getFloat (HaskellObj p) { if ( p->header.info == Fzh_con_info || @@ -277,7 +267,7 @@ rts_getFloat (HaskellObj p) } } -double +HsDouble rts_getDouble (HaskellObj p) { if ( p->header.info == Dzh_con_info || @@ -288,7 +278,7 @@ rts_getDouble (HaskellObj p) } } -StgStablePtr +HsStablePtr rts_getStablePtr (HaskellObj p) { if ( p->header.info == StablePtr_con_info || @@ -299,20 +289,19 @@ rts_getStablePtr (HaskellObj p) } } -void * -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("getPtr: not an Ptr"); } } #ifdef COMPILER /* GHC has em, Hugs doesn't */ -int +HsBool rts_getBool (HaskellObj p) { if (p == True_closure) { @@ -367,28 +356,21 @@ 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 rts_checkSchedStatus ( char* site, SchedulerStatus rc ) -{ - if ( rc == Success ) { - return; - } else { - barf("%s: Return code (%d) not ok",(site),(rc)); - } +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)); + } }