[project @ 2000-04-11 20:44:17 by panne]
[ghc-hetmet.git] / ghc / rts / PrimOps.hc
index 01d0a0a..27f6f84 100644 (file)
@@ -1,7 +1,7 @@
 /* -----------------------------------------------------------------------------
- * $Id: PrimOps.hc,v 1.38 2000/01/13 12:40:15 simonmar Exp $
+ * $Id: PrimOps.hc,v 1.50 2000/04/11 20:44:19 panne Exp $
  *
- * (c) The GHC Team, 1998-1999
+ * (c) The GHC Team, 1998-2000
  *
  * Primitive functions / data
  *
@@ -19,6 +19,8 @@
 #include "StablePriv.h"
 #include "HeapStackCheck.h"
 #include "StgRun.h"
+#include "Itimer.h"
+#include "Prelude.h"
 
 /* ** temporary **
 
@@ -183,7 +185,13 @@ W_ GHC_ZCCReturnable_static_info[0];
 #else /* 0 Regs available */
 
 #define PUSH_P(o,x) Sp[-o] = (W_)(x)
-#define PUSH_N(o,x) Sp[1-o] = (W_)(x); /* Sp[-o] = ARGTAG(1) */
+
+#ifdef DEBUG
+#define PUSH_N(o,x) Sp[1-o] = (W_)(x);  Sp[-o] = ARG_TAG(1);
+#else
+#define PUSH_N(o,x) Sp[1-o] = (W_)(x);
+#endif
+
 #define PUSHED(m)   Sp -= (m); JMP_(ENTRY_CODE(Sp[m]));
 
 /* Here's how to construct these macros:
@@ -316,14 +324,14 @@ FN_(newMutVarzh_fast)
    -------------------------------------------------------------------------- */
 
 #ifndef PAR
-FN_(makeForeignObjzh_fast)
+FN_(mkForeignObjzh_fast)
 {
   /* R1.p = ptr to foreign object,
   */
   StgForeignObj *result;
   FB_
 
-  HP_CHK_GEN_TICKY(sizeofW(StgForeignObj), NO_PTRS, makeForeignObjzh_fast,);
+  HP_CHK_GEN_TICKY(sizeofW(StgForeignObj), NO_PTRS, mkForeignObjzh_fast,);
   TICK_ALLOC_PRIM(sizeofW(StgHeader),
                  sizeofW(StgForeignObj)-sizeofW(StgHeader), 0);
   CCS_ALLOC(CCCS,sizeofW(StgForeignObj)); /* ccs prof */
@@ -361,12 +369,16 @@ FN_(mkWeakzh_fast)
 {
   /* R1.p = key
      R2.p = value
-     R3.p = finalizer
+     R3.p = finalizer (or NULL)
   */
   StgWeak *w;
   FB_
 
-  HP_CHK_GEN_TICKY(sizeofW(StgWeak), R1_PTR|R2_PTR|R3_PTR, mkWeakzh_fast,);
+  if (R3.cl == NULL) {
+    R3.cl = &NO_FINALIZER_closure;
+  }
+
+  HP_CHK_GEN_TICKY(sizeofW(StgWeak),R1_PTR|R2_PTR|R3_PTR, mkWeakzh_fast,);
   TICK_ALLOC_PRIM(sizeofW(StgHeader)+1,  // +1 is for the link field
                  sizeofW(StgWeak)-sizeofW(StgHeader)-1, 0);
   CCS_ALLOC(CCCS,sizeofW(StgWeak)); /* ccs prof */
@@ -376,11 +388,7 @@ FN_(mkWeakzh_fast)
 
   w->key        = R1.cl;
   w->value      = R2.cl;
-  if (R3.cl) {
-     w->finalizer  = R3.cl;
-  } else {
-     w->finalizer  = &NO_FINALIZER_closure;
-  }
+  w->finalizer  = R3.cl;
 
   w->link       = weak_ptr_list;
   weak_ptr_list = w;
@@ -633,7 +641,7 @@ FN_(word64ToIntegerzh_fast)
 FN_(name)                                                              \
 {                                                                      \
   MP_INT arg1, arg2, result;                                           \
-  I_ s1, s2;                                                   \
+  I_ s1, s2;                                                           \
   StgArrWords* d1;                                                     \
   StgArrWords* d2;                                                     \
   FB_                                                                  \
@@ -668,7 +676,7 @@ FN_(name)                                                           \
 FN_(name)                                                              \
 {                                                                      \
   MP_INT arg1, arg2, result1, result2;                                 \
-  I_ s1, s2;                                                   \
+  I_ s1, s2;                                                           \
   StgArrWords* d1;                                                     \
   StgArrWords* d2;                                                     \
   FB_                                                                  \
@@ -897,7 +905,13 @@ FN_(putMVarzh_fast)
 #endif
 
   if (info == &FULL_MVAR_info) {
-    barf("putMVar#: MVar already full");
+#ifdef INTERPRETER
+    fprintf(stderr, "fatal: put on a full MVar in Hugs; aborting\n" );
+    exit(1);
+#else
+    R1.cl = (StgClosure *)PutFullMVar_closure;
+    JMP_(raisezh_fast);
+#endif
   }
   
   mvar->value = R2.cl;
@@ -907,7 +921,14 @@ FN_(putMVarzh_fast)
    */
   if (mvar->head != (StgTSO *)&END_TSO_QUEUE_closure) {
     ASSERT(mvar->head->why_blocked == BlockedOnMVar);
+#if defined(GRAN)
+    mvar->head = RET_STGCALL2(StgTSO *,unblockOne,mvar->head,mvar);
+#elif defined(PAR)
+    // ToDo: check 2nd arg (mvar) is right
+    mvar->head = RET_STGCALL2(StgTSO *,unblockOne,mvar->head,mvar);
+#else
     mvar->head = RET_STGCALL1(StgTSO *,unblockOne,mvar->head);
+#endif
     if (mvar->head == (StgTSO *)&END_TSO_QUEUE_closure) {
       mvar->tail = (StgTSO *)&END_TSO_QUEUE_closure;
     }
@@ -996,7 +1017,11 @@ FN_(delayzh_fast)
     /* Add on ticks_since_select, since these will be subtracted at
      * the next awaitEvent call.
      */
+#if defined(HAVE_SETITIMER) || defined(mingw32_TARGET_OS)
     CurrentTSO->block_info.delay = R1.i + ticks_since_select;
+#else
+    CurrentTSO->block_info.target = R1.i + getourtimeofday();
+#endif
 
     APPEND_TO_BLOCKED_QUEUE(CurrentTSO);