-#endif
-
- if (
-#ifdef DEBUG
- ((++eCount) & 0x0F) == 0
-#else
- ++eCount == 0
-#endif
- ) {
- if (context_switch) {
- switch(hugsBlock.reason) {
- case NotBlocked: {
- xPushCPtr(obj); /* code to restart with */
- RETURN(ThreadYielding);
- }
- case BlockedOnDelay: /* fall through */
- case BlockedOnRead: /* fall through */
- case BlockedOnWrite: {
- ASSERT(cap->rCurrentTSO->why_blocked == NotBlocked);
- cap->rCurrentTSO->why_blocked = BlockedOnDelay;
- ACQUIRE_LOCK(&sched_mutex);
-
-#if defined(HAVE_SETITIMER) /* || defined(mingw32_TARGET_OS) */
- cap->rCurrentTSO->block_info.delay
- = hugsBlock.delay + ticks_since_select;
-#else
- cap->rCurrentTSO->block_info.target
- = hugsBlock.delay + getourtimeofday();
-#endif
- APPEND_TO_BLOCKED_QUEUE(cap->rCurrentTSO);
-
- RELEASE_LOCK(&sched_mutex);
-
- xPushCPtr(obj); /* code to restart with */
- RETURN(ThreadBlocked);
- }
- default:
- barf("Unknown context switch reasoning");
- }
- }
- }
-
- switch ( get_itbl(obj)->type ) {
- case INVALID_OBJECT:
- barf("Invalid object %p",obj);
-
- case BCO: bco_entry:
-
- /* ---------------------------------------------------- */
- /* Start of the bytecode evaluator */
- /* ---------------------------------------------------- */
- {
-# if USE_GCC_LABELS
-# define Ins(x) &&l##x
- static void *labs[] = { INSTRLIST };
-# undef Ins
-# define LoopTopLabel
-# define Case(x) l##x
-# define Continue goto *labs[BCO_INSTR_8]
-# define Dispatch Continue;
-# define EndDispatch
-# else
-# define LoopTopLabel insnloop:
-# define Case(x) case x
-# define Continue goto insnloop
-# define Dispatch switch (BCO_INSTR_8) {
-# define EndDispatch }
-# endif
-
- register StgWord8* bciPtr; /* instruction pointer */
- register StgBCO* bco = (StgBCO*)obj;
- StgWord wantToGC;
-
- /* Don't need to SSS ... LLL around doYouWantToGC */
- wantToGC = doYouWantToGC();
- if (wantToGC) {
- xPushCPtr((StgClosure*)bco); /* code to restart with */
- RETURN(HeapOverflow);
- }
-
- bciPtr = &(bcoInstr(bco,0));
-
- LoopTopLabel
-
- ASSERT((StgWord)(PC) < bco->n_instrs);
- IF_DEBUG(evaluator,
- fprintf(stderr,"Sp = %p\tSu = %p\tpc = %d\t", xSp, xSu, PC);
- SSS;
- disInstr(bco,PC);
- if (0) { int i;
- fprintf(stderr,"\n");
- for (i = 8; i >= 0; i--)
- fprintf(stderr, "%d %p\n", i, (StgPtr)(*(gSp+i)));
- }
- fprintf(stderr,"\n");
- LLL;
- );
-
- Dispatch
-
- Case(i_INTERNAL_ERROR):
- barf("INTERNAL_ERROR at %p:%d",bco,PC-1);
- Case(i_PANIC):
- barf("PANIC at %p:%d",bco,PC-1);
- Case(i_STK_CHECK):
- {
- int n = BCO_INSTR_8;
- if (xSp - n < xSpLim) {
- xPushCPtr((StgClosure*)bco); /* code to restart with */
- RETURN(StackOverflow);
- }
- Continue;
- }
- Case(i_STK_CHECK_big):
- {
- int n = BCO_INSTR_16;
- if (xSp - n < xSpLim) {
- xPushCPtr((StgClosure*)bco); /* code to restart with */
- RETURN(StackOverflow);
- }
- Continue;
- }
- Case(i_ARG_CHECK):
- {
- nat n = BCO_INSTR_8;
- if ((StgPtr*)(xSp + n) > (StgPtr*)xSu) {
- StgWord words = (P_)xSu - xSp;
-
- /* first build a PAP */
- ASSERT((P_)xSu >= xSp); /* was (words >= 0) but that's always true */
- if (words == 0) { /* optimisation */
- /* Skip building the PAP and update with an indirection. */
- } else {
- /* Build the PAP. */
- /* In the evaluator, we avoid the need to do
- * a heap check here by including the size of
- * the PAP in the heap check we performed
- * when we entered the BCO.
- */
- StgInt i;
- StgPAP* pap;
- SSS; pap = (StgPAP*)grabHpNonUpd(PAP_sizeW(words)); LLL;
- SET_HDR(pap,&PAP_info,CC_pap);
- pap->n_args = words;
- pap->fun = obj;
- for (i = 0; i < (I_)words; ++i) {
- payloadWord(pap,i) = xSp[i];
- }
- xSp += words;
- obj = stgCast(StgClosure*,pap);
- }
-
- /* now deal with "update frame" */
- /* as an optimisation, we process all on top of stack */
- /* instead of just the top one */
- ASSERT(xSp==(P_)xSu);
- do {
- switch (get_itbl(xSu)->type) {
- case CATCH_FRAME:
- /* Hit a catch frame during an arg satisfaction check,
- * so the thing returning (1) has not thrown an
- * exception, and (2) is of functional type. Just
- * zap the catch frame and carry on down the stack
- * (looking for more arguments, basically).
- */
- SSS; PopCatchFrame(); LLL;
- break;
- case UPDATE_FRAME:
- xPopUpdateFrame(obj);
- break;
- case STOP_FRAME:
- barf("STOP frame during pap update");
-#if 0
- cap->rCurrentTSO->what_next = ThreadComplete;
- SSS; PopStopFrame(obj); LLL;
- RETURN(ThreadFinished);
-#endif
- case SEQ_FRAME:
- SSS; PopSeqFrame(); LLL;
- ASSERT(xSp != (P_)xSu);
- /* Hit a SEQ frame during an arg satisfaction check.
- * So now return to bco_info which is under the
- * SEQ frame. The following code is copied from a
- * case RET_BCO further down. (The reason why we're
- * here is that something of functional type has
- * been seq-d on, and we're now returning to the
- * algebraic-case-continuation which forced the
- * evaluation in the first place.)
- */
- {
- StgClosure* ret;
- (void)xPopPtr();
- ret = xPopCPtr();
- xPushPtr((P_)obj);
- obj = ret;
- goto enterLoop;
- }
- break;
- default:
- barf("Invalid update frame during argcheck");
- }
- } while (xSp==(P_)xSu);
- goto enterLoop;
- }
- Continue;
- }
- Case(i_ALLOC_AP):
- {
- StgPtr p;
- int words = BCO_INSTR_8;
- SSS; p = grabHpUpd(AP_sizeW(words)); LLL;
- xPushPtr(p);
- Continue;
- }
- Case(i_ALLOC_CONSTR):
- {
- StgPtr p;
- StgInfoTable* info = bcoConstAddr(bco,BCO_INSTR_8);
- SSS; p = grabHpNonUpd(sizeW_fromITBL(info)); LLL;
- SET_HDR((StgClosure*)p,info,??);
- xPushPtr(p);
- Continue;
- }
- Case(i_ALLOC_CONSTR_big):
- {
- StgPtr p;
- int x = BCO_INSTR_16;
- StgInfoTable* info = bcoConstAddr(bco,x);
- SSS; p = grabHpNonUpd(sizeW_fromITBL(info)); LLL;
- SET_HDR((StgClosure*)p,info,??);
- xPushPtr(p);
- Continue;
- }
- Case(i_MKAP):
- {
- int x = BCO_INSTR_8; /* ToDo: Word not Int! */
- int y = BCO_INSTR_8;
- StgAP_UPD* o = stgCast(StgAP_UPD*,xStackPtr(x));
- SET_HDR(o,&AP_UPD_info,??);
- o->n_args = y;
- o->fun = stgCast(StgClosure*,xPopPtr());
- for(x=0; x < y; ++x) {
- payloadWord(o,x) = xPopWord();
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- Continue;
- }
- Case(i_MKAP_big):
- {
- int x, y;
- StgAP_UPD* o;
- x = BCO_INSTR_16;
- y = BCO_INSTR_16;
- o = stgCast(StgAP_UPD*,xStackPtr(x));
- SET_HDR(o,&AP_UPD_info,??);
- o->n_args = y;
- o->fun = stgCast(StgClosure*,xPopPtr());
- for(x=0; x < y; ++x) {
- payloadWord(o,x) = xPopWord();
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- Continue;
- }
- Case(i_MKPAP):
- {
- int x = BCO_INSTR_8;
- int y = BCO_INSTR_8;
- StgPAP* o = stgCast(StgPAP*,xStackPtr(x));
- SET_HDR(o,&PAP_info,??);
- o->n_args = y;
- o->fun = stgCast(StgClosure*,xPopPtr());
- for(x=0; x < y; ++x) {
- payloadWord(o,x) = xPopWord();
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- Continue;
- }
- Case(i_PACK):
- {
- int offset = BCO_INSTR_8;
- StgClosure* o = stgCast(StgClosure*,xStackPtr(offset));
- const StgInfoTable* info = get_itbl(o);
- nat p = info->layout.payload.ptrs;
- nat np = info->layout.payload.nptrs;
- nat i;
- for(i=0; i < p; ++i) {
- o->payload[i] = xPopCPtr();
- }
- for(i=0; i < np; ++i) {
- payloadWord(o,p+i) = 0xdeadbeef;
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- Continue;
- }
- Case(i_PACK_big):
- {
- int offset = BCO_INSTR_16;
- StgClosure* o = stgCast(StgClosure*,xStackPtr(offset));
- const StgInfoTable* info = get_itbl(o);
- nat p = info->layout.payload.ptrs;
- nat np = info->layout.payload.nptrs;
- nat i;
- for(i=0; i < p; ++i) {
- o->payload[i] = xPopCPtr();
- }
- for(i=0; i < np; ++i) {
- payloadWord(o,p+i) = 0xdeadbeef;
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- Continue;
- }
- Case(i_SLIDE):
- {
- int x = BCO_INSTR_8;
- int y = BCO_INSTR_8;
- ASSERT(xSp+x+y <= stgCast(StgPtr,xSu));
- /* a_1, .. a_x, b_1, .. b_y, s => a_1, .. a_x, s */
- while(--x >= 0) {
- xSetStackWord(x+y,xStackWord(x));
- }
- xSp += y;
- Continue;
- }
- Case(i_SLIDE_big):
- {
- int x, y;
- x = BCO_INSTR_16;
- y = BCO_INSTR_16;
- ASSERT(xSp+x+y <= stgCast(StgPtr,xSu));
- /* a_1, .. a_x, b_1, .. b_y, s => a_1, .. a_x, s */
- while(--x >= 0) {
- xSetStackWord(x+y,xStackWord(x));
- }
- xSp += y;
- Continue;
- }
- Case(i_ENTER):
- {
- obj = xPopCPtr();
- goto enterLoop;
- }
- Case(i_RETADDR):
- {
- xPushPtr(bcoConstPtr(bco,BCO_INSTR_8));
- xPushPtr(stgCast(StgPtr,&ret_bco_info));
- Continue;
- }
- Case(i_TEST):
- {
- int tag = BCO_INSTR_8;
- StgWord offset = BCO_INSTR_16;
- if (constrTag( (StgClosure*)xStackPtr(0) ) != tag) {
- bciPtr += offset;
- }
- Continue;
- }
- Case(i_UNPACK):
- {
- StgClosure* o = stgCast(StgClosure*,xStackPtr(0));
- const StgInfoTable* itbl = get_itbl(o);
- int i = itbl->layout.payload.ptrs;
- ASSERT( itbl->type == CONSTR
- || itbl->type == CONSTR_STATIC
- || itbl->type == CONSTR_NOCAF_STATIC
- || itbl->type == CONSTR_1_0
- || itbl->type == CONSTR_0_1
- || itbl->type == CONSTR_2_0
- || itbl->type == CONSTR_1_1
- || itbl->type == CONSTR_0_2
- );
- while (--i>=0) {
- xPushCPtr(o->payload[i]);
- }
- Continue;
- }
- Case(i_VAR_big):
- {
- int n = BCO_INSTR_16;
- StgPtr p = xStackPtr(n);
- xPushPtr(p);
- Continue;
- }
- Case(i_VAR):
- {
- StgPtr p = xStackPtr(BCO_INSTR_8);
- xPushPtr(p);
- Continue;
- }
- Case(i_CONST):
- {
- xPushPtr(stgCast(StgPtr,bcoConstPtr(bco,BCO_INSTR_8)));
- Continue;
- }
- Case(i_CONST_big):
- {
- int n = BCO_INSTR_16;
- xPushPtr(stgCast(StgPtr,bcoConstPtr(bco,n)));
- Continue;
- }
-#ifdef XMLAMBDA
- /* allocate rows, implemented on top of (frozen) Arrays */
- Case(i_ALLOC_ROW):
- {
- StgMutArrPtrs* p;
- StgWord n = BCO_INSTR_8;
- SSS; p = stgCast(StgMutArrPtrs*,grabHpNonUpd(sizeofW(StgMutArrPtrs) + n)); LLL;
- SET_HDR(p,&MUT_ARR_PTRS_FROZEN_info,CCCS);
- p->ptrs = n;
- xPushPtr(p);
- Continue;
- }
- Case(i_ALLOC_ROW_big):
- {
- StgMutArrPtrs* p;
- StgWord n = BCO_INSTR_16;
- SSS; p = stgCast(StgMutArrPtrs*,grabHpNonUpd(sizeofW(StgMutArrPtrs) + n)); LLL;
- SET_HDR(p,&MUT_ARR_PTRS_FROZEN_info,CCCS);
- p->ptrs = n;
- xPushPtr(p);
- Continue;
- }
-
- /* pack values into a row. */
- Case(i_PACK_ROW):
- {
- StgWord offset = BCO_INSTR_8;
- StgMutArrPtrs* p = stgCast(StgMutArrPtrs*,xStackPtr(offset));
- StgWord n = p->ptrs;
- StgWord i;
-
- for (i=0; i<n; ++i)
- {
- p->payload[i] = xPopCPtr();
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,p));
- LLL;
- );
- Continue;
- }
- Case(i_PACK_ROW_big):
- {
- StgWord offset = BCO_INSTR_16;
- StgMutArrPtrs* p = stgCast(StgMutArrPtrs*,xStackPtr(offset));
- StgWord n = p->ptrs;
- StgWord i;
-
- for (i=0; i<n; ++i)
- {
- p->payload[i] = xPopCPtr();
- }
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,p));
- LLL;
- );
- Continue;
- }
-
- /* extract all fields of a row */
- Case(i_UNPACK_ROW):
- {
- StgMutArrPtrs* p = stgCast(StgMutArrPtrs*,xStackPtr(0));
- nat i = p->ptrs;
- while (i > 0)
- {
- i--;
- xPushCPtr(p->payload[i]);
- }
- Continue;
- }
-
- /* Trivial row (unit) */
- Case(i_CONST_ROW_TRIV):
- {
- StgMutArrPtrs* p;
- SSS; p = stgCast(StgMutArrPtrs*,grabHpNonUpd(sizeofW(StgMutArrPtrs) + 0)); LLL;
- SET_HDR(p,&MUT_ARR_PTRS_FROZEN_info,CCCS);
- p->ptrs = 0;
- xPushPtr(p);
- Continue;
- }
-
- /* pack values into an Inj */
- Case(i_PACK_INJ_VAR):
- {
- const int size = CONSTR_sizeW(sizeofW(StgPtr),sizeofW(StgWord));
- StgWord offset = BCO_INSTR_8;
-
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(size); LLL;
- SET_HDR(o,Inj_con_info,??);
-
- payloadWord(o,sizeofW(StgPtr)) = xTaggedStackWord(offset);
- payloadPtr(o,0) = xPopPtr();
-
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_PACK_INJ_VAR_big):
- {
- const int size = CONSTR_sizeW(sizeofW(StgPtr),sizeofW(StgWord));
- StgWord offset = BCO_INSTR_16;
-
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(size); LLL;
- SET_HDR(o,Inj_con_info,??);
-
- payloadWord(o,sizeofW(StgPtr)) = xTaggedStackWord(offset);
- payloadPtr(o,0) = xPopPtr();
-
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_PACK_INJ_CONST_8):
- {
- const int size = CONSTR_sizeW(sizeofW(StgPtr),sizeofW(StgWord));
- StgWord witness = BCO_INSTR_8;
-
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(size); LLL;
- SET_HDR(o,Inj_con_info,??);
-
- payloadWord(o,sizeofW(StgPtr)) = witness;
- payloadPtr(o,0) = xPopPtr();
-
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_PACK_INJ_REL_8):
- {
- const int size = CONSTR_sizeW(sizeofW(StgPtr),sizeofW(StgWord));
- StgWord offset = BCO_INSTR_8;
- StgWord cwitness = BCO_INSTR_8;
-
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(size); LLL;
- SET_HDR(o,Inj_con_info,??);
-
- payloadWord(o,sizeofW(StgPtr)) = xTaggedStackWord(offset) + cwitness;
- payloadPtr(o,0) = xPopPtr();
-
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_PACK_INJ):
- {
- const int size = CONSTR_sizeW(sizeofW(StgPtr),sizeofW(StgWord));
-
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(size); LLL;
- SET_HDR(o,Inj_con_info,??);
-
- payloadWord(o,sizeofW(StgPtr)) = xPopTaggedWord();
- payloadPtr(o,0) = xPopPtr();
-
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
-
- /* Test Inj witnesses. */
- Case(i_TEST_INJ_VAR):
- {
- StgWord offset = BCO_INSTR_8;
- StgWord jump = BCO_INSTR_16;
-
- StgWord index = payloadWord( (StgClosure*)xStackPtr(0), sizeofW(StgPtr) );
- if (index != xTaggedStackWord(offset) )
- {
- bciPtr += jump;
- }
- Continue;
- }
- Case(i_TEST_INJ_VAR_big):
- {
- StgWord offset = BCO_INSTR_16;
- StgWord jump = BCO_INSTR_16;
-
- StgWord index = payloadWord( (StgClosure*)xStackPtr(0), sizeofW(StgPtr) );
- if (index != xTaggedStackWord(offset) )
- {
- bciPtr += jump;
- }
- Continue;
- }
- Case(i_TEST_INJ_CONST_8):
- {
- StgWord cwitness = BCO_INSTR_8;
- StgWord jump = BCO_INSTR_16;
-
- StgWord witness = payloadWord( (StgClosure*)xStackPtr(0), sizeofW(StgPtr) );
- if (witness != cwitness )
- {
- bciPtr += jump;
- }
- Continue;
- }
- Case(i_TEST_INJ_REL_8):
- {
- StgWord offset = BCO_INSTR_8;
- StgWord cwitness = BCO_INSTR_8;
- StgWord jump = BCO_INSTR_16;
-
- StgWord witness = payloadWord( (StgClosure*)xStackPtr(0), sizeofW(StgPtr) );
- if (witness != xTaggedStackWord(offset) + cwitness )
- {
- bciPtr += jump;
- }
- Continue;
- }
- Case(i_TEST_INJ):
- {
- StgWord jump = BCO_INSTR_16;
- StgWord cwitness = xPopTaggedWord();
-
- StgWord witness = payloadWord( (StgClosure*)xStackPtr(0), sizeofW(StgPtr) );
- if (witness != cwitness )
- {
- bciPtr += jump;
- }
- Continue;
- }
-
- /* extract the value of an INJ */
- Case(i_UNPACK_INJ):
- {
- StgClosure* con = stgCast(StgClosure*,xStackPtr(0));
-
- ASSERT(get_itbl(con) == Inj_con_info);
-
- xPushPtr(payloadPtr(con,0));
- Continue;
- }
-
- /* optimized witness (word) operations */
- Case(i_CONST_WORD_8):
- {
- xPushTaggedWord(BCO_INSTR_8);
- Continue;
- }
- Case(i_ADD_WORD_VAR):
- {
- StgWord offset = BCO_INSTR_8;
- StgWord witness = xTaggedStackWord(offset);
- witness += xPopTaggedWord();
- xPushTaggedWord(witness);
- Continue;
- }
- Case(i_ADD_WORD_VAR_big):
- {
- StgWord offset = BCO_INSTR_16;
- StgWord witness = xTaggedStackWord(offset);
- witness += xPopTaggedWord();
- xPushTaggedWord(witness);
- Continue;
- }
- Case(i_ADD_WORD_VAR_8):
- {
- StgWord offset = BCO_INSTR_8;
- StgWord inc = BCO_INSTR_8;
- StgWord witness = xTaggedStackWord(offset);
- xPushTaggedWord(witness + inc);
- Continue;
- }
-#endif /* XMLAMBA */
-
- Case(i_VOID):
- {
- SSS; PushTaggedRealWorld(); LLL;
- Continue;
- }
- Case(i_VAR_INT):
- {
- StgInt i = xTaggedStackInt(BCO_INSTR_8);
- xPushTaggedInt(i);
- Continue;
- }
- Case(i_CONST_INT):
- {
- xPushTaggedInt(bcoConstInt(bco,BCO_INSTR_8));
- Continue;
- }
- Case(i_CONST_INT_big):
- {
- int n = BCO_INSTR_16;
- xPushTaggedInt(bcoConstInt(bco,n));
- Continue;
- }
- Case(i_PACK_INT):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Izh_sizeW); LLL;
- SET_HDR(o,Izh_con_info,??);
- payloadWord(o,0) = xPopTaggedInt();
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_UNPACK_INT):
- {
- StgClosure* con = stgCast(StgClosure*,xStackPtr(0));
- /* ASSERT(isIntLike(con)); */
- xPushTaggedInt(payloadWord(con,0));
- Continue;
- }
- Case(i_TEST_INT):
- {
- StgWord offset = BCO_INSTR_16;
- StgInt x = xPopTaggedInt();
- StgInt y = xPopTaggedInt();
- if (x != y) {
- bciPtr += offset;
- }
- Continue;
- }
- Case(i_CONST_INTEGER):
- {
- StgPtr p;
- int n;
- char* s = bcoConstAddr(bco,BCO_INSTR_8);
- SSS;
- n = size_fromStr(s);
- p = CreateByteArrayToHoldInteger(n);
- do_fromStr ( s, n, IntegerInsideByteArray(p));
- SloppifyIntegerEnd(p);
- LLL;
- xPushPtr(p);
- Continue;
- }
- Case(i_VAR_WORD):
- {
- StgWord w = xTaggedStackWord(BCO_INSTR_8);
- xPushTaggedWord(w);
- Continue;
- }
- Case(i_CONST_WORD):
- {
- xPushTaggedWord(bcoConstWord(bco,BCO_INSTR_8));
- Continue;
- }
- Case(i_CONST_WORD_big):
- {
- StgWord n = BCO_INSTR_16;
- xPushTaggedWord(bcoConstWord(bco,n));
- Continue;
- }
- Case(i_PACK_WORD):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Wzh_sizeW); LLL;
- SET_HDR(o,Wzh_con_info,??);
- payloadWord(o,0) = xPopTaggedWord();
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_UNPACK_WORD):
- {
- StgClosure* con = stgCast(StgClosure*,xStackPtr(0));
- /* ASSERT(isWordLike(con)); */
- xPushTaggedWord(payloadWord(con,0));
- Continue;
- }
- Case(i_VAR_ADDR):
- {
- StgAddr a = xTaggedStackAddr(BCO_INSTR_8);
- xPushTaggedAddr(a);
- Continue;
- }
- Case(i_CONST_ADDR):
- {
- xPushTaggedAddr(bcoConstAddr(bco,BCO_INSTR_8));
- Continue;
- }
- Case(i_CONST_ADDR_big):
- {
- int n = BCO_INSTR_16;
- xPushTaggedAddr(bcoConstAddr(bco,n));
- Continue;
- }
- Case(i_PACK_ADDR):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Azh_sizeW); LLL;
- SET_HDR(o,Azh_con_info,??);
- payloadPtr(o,0) = xPopTaggedAddr();
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_UNPACK_ADDR):
- {
- StgClosure* con = (StgClosure*)xStackPtr(0);
- /* ASSERT(isAddrLike(con)); */
- xPushTaggedAddr(payloadPtr(con,0));
- Continue;
- }
- Case(i_VAR_CHAR):
- {
- StgChar c = xTaggedStackChar(BCO_INSTR_8);
- xPushTaggedChar(c);
- Continue;
- }
- Case(i_CONST_CHAR):
- {
- xPushTaggedChar(bcoConstChar(bco,BCO_INSTR_8));
- Continue;
- }
- Case(i_PACK_CHAR):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Czh_sizeW); LLL;
- SET_HDR(o,Czh_con_info,??);
- payloadWord(o,0) = xPopTaggedChar();
- xPushPtr(stgCast(StgPtr,o));
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- Continue;
- }
- Case(i_UNPACK_CHAR):
- {
- StgClosure* con = stgCast(StgClosure*,xStackPtr(0));
- /* ASSERT(isCharLike(con)); */
- xPushTaggedChar(payloadWord(con,0));
- Continue;
- }
- Case(i_VAR_FLOAT):
- {
- StgFloat f = xTaggedStackFloat(BCO_INSTR_8);
- xPushTaggedFloat(f);
- Continue;
- }
- Case(i_CONST_FLOAT):
- {
- xPushTaggedFloat(bcoConstFloat(bco,BCO_INSTR_8));
- Continue;
- }
- Case(i_PACK_FLOAT):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Fzh_sizeW); LLL;
- SET_HDR(o,Fzh_con_info,??);
- ASSIGN_FLT(&payloadWord(o,0),xPopTaggedFloat());
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_UNPACK_FLOAT):
- {
- StgClosure* con = stgCast(StgClosure*,xStackPtr(0));
- /* ASSERT(isFloatLike(con)); */
- xPushTaggedFloat(PK_FLT(&payloadWord(con,0)));
- Continue;
- }
- Case(i_VAR_DOUBLE):
- {
- StgDouble d = xTaggedStackDouble(BCO_INSTR_8);
- xPushTaggedDouble(d);
- Continue;
- }
- Case(i_CONST_DOUBLE):
- {
- xPushTaggedDouble(bcoConstDouble(bco,BCO_INSTR_8));
- Continue;
- }
- Case(i_CONST_DOUBLE_big):
- {
- int n = BCO_INSTR_16;
- xPushTaggedDouble(bcoConstDouble(bco,n));
- Continue;
- }
- Case(i_PACK_DOUBLE):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Dzh_sizeW); LLL;
- SET_HDR(o,Dzh_con_info,??);
- ASSIGN_DBL(&payloadWord(o,0),xPopTaggedDouble());
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- printObj(stgCast(StgClosure*,o));
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_UNPACK_DOUBLE):
- {
- StgClosure* con = stgCast(StgClosure*,xStackPtr(0));
- /* ASSERT(isDoubleLike(con)); */
- xPushTaggedDouble(PK_DBL(&payloadWord(con,0)));
- Continue;
- }
- Case(i_VAR_STABLE):
- {
- StgStablePtr s = xTaggedStackStable(BCO_INSTR_8);
- xPushTaggedStable(s);
- Continue;
- }
- Case(i_PACK_STABLE):
- {
- StgClosure* o;
- SSS; o = (StgClosure*)grabHpNonUpd(Stablezh_sizeW); LLL;
- SET_HDR(o,StablePtr_con_info,??);
- payloadWord(o,0) = (W_)xPopTaggedStable();
- IF_DEBUG(evaluator,
- fprintf(stderr,"\tBuilt ");
- SSS;
- printObj(stgCast(StgClosure*,o));
- LLL;
- );
- xPushPtr(stgCast(StgPtr,o));
- Continue;
- }
- Case(i_UNPACK_STABLE):
- {
- StgClosure* con = (StgClosure*)xStackPtr(0);
- /* ASSERT(isStableLike(con)); */
- xPushTaggedStable(payloadWord(con,0));
- Continue;
- }
- Case(i_PRIMOP1):
- {
- int i;
- void* p;
- i = BCO_INSTR_8;
- SSS; p = enterBCO_primop1 ( i ); LLL;
- if (p) { obj = p; goto enterLoop; };
- Continue;
- }
- Case(i_PRIMOP2):
- {
- int i, trc, pc_saved;
- void* p;
- StgBCO* bco_tmp;
- trc = 12345678; /* Assume != any StgThreadReturnCode */
- i = BCO_INSTR_8;
- pc_saved = PC;
- bco_tmp = bco;
- SSS;
- p = enterBCO_primop2 ( i, &trc, &bco_tmp, cap,
- &hugsBlock );
- LLL;
- bco = bco_tmp;
- bciPtr = &(bcoInstr(bco,pc_saved));
- if (p) {
- if (trc == 12345678) {
- /* we want to enter p */
- obj = p; goto enterLoop;
- } else {
- /* trc is the the StgThreadReturnCode for
- * this thread */
- RETURN((StgThreadReturnCode)trc);
- };
- }
- Continue;
- }
-
- /* combined insns, created by peephole opt */
- Case(i_SE):
- {
- int x = BCO_INSTR_8;
- int y = BCO_INSTR_8;
- ASSERT(xSp+x+y <= stgCast(StgPtr,xSu));
- /* a_1, .. a_x, b_1, .. b_y, s => a_1, .. a_x, s */
- if (x == 1) {
- obj = xPopCPtr();
- xSp += y;
- goto enterLoop;
- } else {
- while(--x >= 0) {
- xSetStackWord(x+y,xStackWord(x));
- }
- xSp += y;
- obj = xPopCPtr();
- }
- goto enterLoop;
- }
- Case(i_VV):
- {
- StgPtr p;
- p = xStackPtr(BCO_INSTR_8);
- xPushPtr(p);
- p = xStackPtr(BCO_INSTR_8);
- xPushPtr(p);
- Continue;
- }
- Case(i_RV):
- {
- StgPtr p;
- xPushPtr(bcoConstPtr(bco,BCO_INSTR_8));
- xPushPtr(stgCast(StgPtr,&ret_bco_info));
- p = xStackPtr(BCO_INSTR_8);
- xPushPtr(p);
- Continue;
- }
- Case(i_RVE):
- {
- StgPtr retaddr = bcoConstPtr(bco,BCO_INSTR_8);
- StgPtr ptr = xStackPtr(BCO_INSTR_8);
-
- /* A shortcut. We're going to push the address of a
- return continuation, and then enter a variable, so
- that when the var is evaluated, we return to the
- continuation. The shortcut is: if the var is a
- constructor, don't bother to enter it. Instead,
- push the variable on the stack (since this is what
- the continuation expects) and jump directly to the
- continuation.
- */
- if (get_itbl((StgClosure*)ptr)->type == CONSTR) {
- xPushPtr(ptr);
- obj = (StgClosure*)retaddr;
- IF_DEBUG(evaluator,
- fprintf(stderr, "object to enter is a constructor -- "
- "jumping directly to return continuation\n" );
- );
- goto bco_entry;
- }
-
- /* This is the normal, non-short-cut route */
- xPushPtr(retaddr);
- xPushPtr(stgCast(StgPtr,&ret_bco_info));
- obj = (StgClosure*)ptr;
- goto enterLoop;
- }
-
-
- Case(i_VAR_DOUBLE_big):
- Case(i_CONST_FLOAT_big):
- Case(i_VAR_FLOAT_big):
- Case(i_CONST_CHAR_big):
- Case(i_VAR_CHAR_big):
- Case(i_VAR_ADDR_big):
- Case(i_VAR_STABLE_big):
- Case(i_CONST_INTEGER_big):
- Case(i_VAR_INT_big):
- Case(i_VAR_WORD_big):
- Case(i_RETADDR_big):
- Case(i_ALLOC_PAP):
-#ifndef XMLAMBDA
- Case(i_UNPACK_INJ):
- Case(i_UNPACK_ROW):
- Case(i_TEST_INJ_CONST):
- Case(i_TEST_INJ_big):
- Case(i_TEST_INJ):
- Case(i_PACK_INJ_CONST):
- Case(i_PACK_INJ_big):
- Case(i_PACK_INJ):
- Case(i_PACK_ROW_big):
- Case(i_PACK_ROW):
- Case(i_ALLOC_ROW_big):
- Case(i_ALLOC_ROW):
-#endif
- bciPtr--;
- printf ( "\n\n" );
- disInstr ( bco, PC );
- barf("\nUnrecognised instruction");
-
- EndDispatch
-
- barf("enterBCO: ran off end of loop");
- break;
- }
-
-# undef LoopTopLabel
-# undef Case
-# undef Continue
-# undef Dispatch
-# undef EndDispatch
-
- /* ---------------------------------------------------- */
- /* End of the bytecode evaluator */
- /* ---------------------------------------------------- */
-
- case CAF_UNENTERED:
- {
- StgBlockingQueue* bh;
- StgCAF* caf = (StgCAF*)obj;
- if (xSp - sizeofW(StgUpdateFrame) < xSpLim) {
- xPushCPtr(obj); /* code to restart with */
- RETURN(StackOverflow);
- }
- SSS; bh = (StgBlockingQueue*)grabHpUpd(BLACKHOLE_sizeW()); LLL;
- SET_INFO(bh,&CAF_BLACKHOLE_info);
- bh->blocking_queue = EndTSOQueue;
- IF_DEBUG(gccafs,
- fprintf(stderr,"Created CAF_BLACKHOLE %p for CAF %p"
- " in evaluator\n",bh,caf));
- SET_INFO(caf,&CAF_ENTERED_info);
- caf->value = (StgClosure*)bh;
-
- SSS; newCAF_made_by_Hugs(caf); LLL;
-
- xPushUpdateFrame(bh,0);
- xSp -= sizeofW(StgUpdateFrame);
- obj = caf->body;
- goto enterLoop;
- }
- case CAF_ENTERED:
- {
- StgCAF* caf = (StgCAF*)obj;
- obj = caf->value; /* it's just a fancy indirection */
- goto enterLoop;
- }
- case BLACKHOLE:
- case SE_BLACKHOLE:
- case CAF_BLACKHOLE:
- case SE_CAF_BLACKHOLE:
- {
- /* Let the scheduler figure out what to do :-) */
- cap->rCurrentTSO->what_next = ThreadEnterGHC;
- xPushCPtr(obj);
- RETURN(ThreadYielding);
- }
- case AP_UPD:
- {
- StgAP_UPD* ap = stgCast(StgAP_UPD*,obj);
- int i = ap->n_args;
- if (xSp - (i + sizeofW(StgUpdateFrame)) < xSpLim) {
- xPushCPtr(obj); /* code to restart with */
- RETURN(StackOverflow);
- }
- /* ToDo: look for xSp==xSu && stackInt(0) == UPD_FRAME
- and insert an indirection immediately */
- xPushUpdateFrame(ap,0);
- xSp -= sizeofW(StgUpdateFrame);
- while (--i >= 0) {
- xPushWord(payloadWord(ap,i));
- }
- obj = ap->fun;
-#ifdef EAGER_BLACKHOLING
-#warn LAZY_BLACKHOLING is default for StgHugs
-#error Dont know if EAGER_BLACKHOLING works in StgHugs
- {
- /* superfluous - but makes debugging easier */
- StgBlackHole* bh = stgCast(StgBlackHole*,ap);
- SET_INFO(bh,&BLACKHOLE_info);
- bh->blocking_queue = EndTSOQueue;
- IF_DEBUG(gccafs,
- fprintf(stderr,"Eagerly blackholed AP_UPD %p in evaluator\n",bh));
- /* printObj(bh); */
- }
-#endif /* EAGER_BLACKHOLING */
- goto enterLoop;
- }
- case PAP:
- {
- StgPAP* pap = stgCast(StgPAP*,obj);
- int i = pap->n_args; /* ToDo: stack check */
- /* ToDo: if PAP is in whnf, we can update any update frames
- * on top of stack.
- */
- while (--i >= 0) {
- xPushWord(payloadWord(pap,i));
- }
- obj = pap->fun;
- goto enterLoop;
- }
- case IND:
- {
- obj = stgCast(StgInd*,obj)->indirectee;
- goto enterLoop;
- }
- case IND_OLDGEN:
- {
- obj = stgCast(StgIndOldGen*,obj)->indirectee;
- goto enterLoop;
- }
- case CONSTR:
- case CONSTR_1_0:
- case CONSTR_0_1:
- case CONSTR_2_0:
- case CONSTR_1_1:
- case CONSTR_0_2:
- case CONSTR_INTLIKE:
- case CONSTR_CHARLIKE:
- case CONSTR_STATIC:
- case CONSTR_NOCAF_STATIC:
-#ifdef XMLAMBDA
-/* rows are mutarrays and should be treated as constructors. */
- case MUT_ARR_PTRS_FROZEN:
-#endif
- {
- while (1) {
- switch (get_itbl(stgCast(StgClosure*,xSp))->type) {
- case CATCH_FRAME:
- SSS; PopCatchFrame(); LLL;
- break;
- case UPDATE_FRAME:
- xPopUpdateFrame(obj);
- break;
- case SEQ_FRAME:
- SSS; PopSeqFrame(); LLL;
- break;
- case STOP_FRAME:
- {
- ASSERT(xSp==(P_)xSu);
- IF_DEBUG(evaluator,
- SSS;
- fprintf(stderr, "hit a STOP_FRAME\n");
- printObj(obj);
- fprintf(stderr,"xSp = %p\txSu = %p\n", xSp, xSu);
- printStack(xSp,cap->rCurrentTSO->stack
- + cap->rCurrentTSO->stack_size,xSu);
- LLL;
- );
- cap->rCurrentTSO->what_next = ThreadComplete;
- SSS; PopStopFrame(obj); LLL;
- xPushPtr((P_)obj);
- RETURN(ThreadFinished);
- }
- case RET_BCO:
- {
- StgClosure* ret;
- (void)xPopPtr();
- ret = xPopCPtr();
- xPushPtr((P_)obj);
- obj = ret;
- goto bco_entry;
- /* was: goto enterLoop;
- But we know that obj must be a bco now, so jump directly.
- */
- }
- case RET_SMALL: /* return to GHC */
- case RET_VEC_SMALL:
- case RET_BIG:
- case RET_VEC_BIG:
- cap->rCurrentTSO->what_next = ThreadEnterGHC;
- xPushCPtr(obj);
- RETURN(ThreadYielding);
- default:
- belch("entered CONSTR with invalid continuation on stack");
- IF_DEBUG(evaluator,
- SSS;
- printObj(stgCast(StgClosure*,xSp));
- LLL;
- );
- barf("bailing out");
- }
- }
- }
- default:
- {
- //SSS;
- //fprintf(stderr, "enterCountI = %d\n", enterCountI);
- //fprintf(stderr, "entering unknown closure -- yielding to sched\n");
- //printObj(obj);
- //LLL;
- cap->rCurrentTSO->what_next = ThreadEnterGHC;
- xPushCPtr(obj); /* code to restart with */
- RETURN(ThreadYielding);
- }
- }
- barf("Ran off the end of enter - yoiks");
- ASSERT(0);
-}
-
-#undef RETURN
-#undef BCO_INSTR_8
-#undef BCO_INSTR_16
-#undef SSS
-#undef LLL
-#undef PC
-#undef xPushPtr
-#undef xPopPtr
-#undef xPushCPtr
-#undef xPopCPtr
-#undef xPopWord
-#undef xStackPtr
-#undef xStackWord
-#undef xSetStackWord
-#undef xPushTag
-#undef xPopTag
-#undef xPushTaggedInt
-#undef xPopTaggedInt
-#undef xTaggedStackInt
-#undef xPushTaggedWord
-#undef xPopTaggedWord
-#undef xTaggedStackWord
-#undef xPushTaggedAddr
-#undef xTaggedStackAddr
-#undef xPopTaggedAddr
-#undef xPushTaggedStable
-#undef xTaggedStackStable
-#undef xPopTaggedStable
-#undef xPushTaggedChar
-#undef xTaggedStackChar
-#undef xPopTaggedChar
-#undef xPushTaggedFloat
-#undef xTaggedStackFloat
-#undef xPopTaggedFloat
-#undef xPushTaggedDouble
-#undef xTaggedStackDouble
-#undef xPopTaggedDouble
-#undef xPopUpdateFrame
-#undef xPushUpdateFrame
-
-
-/* --------------------------------------------------------------------------
- * Supporting routines for primops
- * ------------------------------------------------------------------------*/
-
-static inline void PushTag ( StackTag t )
- { *(--gSp) = t; }
- inline void PushPtr ( StgPtr x )
- { *(--stgCast(StgPtr*,gSp)) = x; }
-static inline void PushCPtr ( StgClosure* x )
- { *(--stgCast(StgClosure**,gSp)) = x; }
-static inline void PushInt ( StgInt x )
- { *(--stgCast(StgInt*,gSp)) = x; }
-static inline void PushWord ( StgWord x )
- { *(--stgCast(StgWord*,gSp)) = x; }
-
-
-static inline void checkTag ( StackTag t1, StackTag t2 )
- { ASSERT(t1 == t2);}
-static inline void PopTag ( StackTag t )
- { checkTag(t,*(gSp++)); }
- inline StgPtr PopPtr ( void )
- { return *stgCast(StgPtr*,gSp)++; }
-static inline StgClosure* PopCPtr ( void )
- { return *stgCast(StgClosure**,gSp)++; }
-static inline StgInt PopInt ( void )
- { return *stgCast(StgInt*,gSp)++; }
-static inline StgWord PopWord ( void )
- { return *stgCast(StgWord*,gSp)++; }
-
-static inline StgPtr stackPtr ( StgStackOffset i )
- { return *stgCast(StgPtr*, gSp+i); }
-static inline StgInt stackInt ( StgStackOffset i )
- { return *stgCast(StgInt*, gSp+i); }
-static inline StgWord stackWord ( StgStackOffset i )
- { return *stgCast(StgWord*,gSp+i); }
-
-static inline void setStackWord ( StgStackOffset i, StgWord w )
- { gSp[i] = w; }
-
-#ifdef XMLAMBDA
-static inline void setStackPtr ( StgStackOffset i, StgPtr p )
- { *(stgCast(StgPtr*, gSp+i)) = p; }
-#endif
-
-static inline void PushTaggedRealWorld( void )
- { PushTag(REALWORLD_TAG); }
- inline void PushTaggedInt ( StgInt x )
- { gSp -= sizeofW(StgInt); *gSp = x; PushTag(INT_TAG); }
- inline void PushTaggedWord ( StgWord x )
- { gSp -= sizeofW(StgWord); *gSp = x; PushTag(WORD_TAG); }
- inline void PushTaggedAddr ( StgAddr x )
- { gSp -= sizeofW(StgAddr); *gSp = (W_)x; PushTag(ADDR_TAG); }
- inline void PushTaggedChar ( StgChar x )
- { gSp -= sizeofW(StgChar); *gSp = stgCast(StgWord,x); PushTag(CHAR_TAG); }
- inline void PushTaggedFloat ( StgFloat x )
- { gSp -= sizeofW(StgFloat); ASSIGN_FLT(gSp,x); PushTag(FLOAT_TAG); }
- inline void PushTaggedDouble ( StgDouble x )
- { gSp -= sizeofW(StgDouble); ASSIGN_DBL(gSp,x); PushTag(DOUBLE_TAG); }
- inline void PushTaggedStablePtr ( StgStablePtr x )
- { gSp -= sizeofW(StgStablePtr); *gSp = (W_)x; PushTag(STABLE_TAG); }
-static inline void PushTaggedBool ( int x )
- { PushTaggedInt(x); }
-
-
-
-static inline void PopTaggedRealWorld ( void )
- { PopTag(REALWORLD_TAG); }
- inline StgInt PopTaggedInt ( void )
- { StgInt r; PopTag(INT_TAG); r = *stgCast(StgInt*, gSp);
- gSp += sizeofW(StgInt); return r;}
- inline StgWord PopTaggedWord ( void )
- { StgWord r; PopTag(WORD_TAG); r = *stgCast(StgWord*, gSp);
- gSp += sizeofW(StgWord); return r;}
- inline StgAddr PopTaggedAddr ( void )
- { StgAddr r; PopTag(ADDR_TAG); r = *stgCast(StgAddr*, gSp);
- gSp += sizeofW(StgAddr); return r;}
- inline StgChar PopTaggedChar ( void )
- { StgChar r; PopTag(CHAR_TAG); r = stgCast(StgChar, *gSp);
- gSp += sizeofW(StgChar); return r;}
- inline StgFloat PopTaggedFloat ( void )
- { StgFloat r; PopTag(FLOAT_TAG); r = PK_FLT(gSp);
- gSp += sizeofW(StgFloat); return r;}
- inline StgDouble PopTaggedDouble ( void )
- { StgDouble r; PopTag(DOUBLE_TAG); r = PK_DBL(gSp);
- gSp += sizeofW(StgDouble); return r;}
- inline StgStablePtr PopTaggedStablePtr ( void )
- { StgStablePtr r; PopTag(STABLE_TAG); r = *stgCast(StgStablePtr*, gSp);
- gSp += sizeofW(StgStablePtr); return r;}
-
-
-
-static inline StgInt taggedStackInt ( StgStackOffset i )
- { checkTag(INT_TAG,gSp[i]); return *stgCast(StgInt*, gSp+1+i); }
-static inline StgWord taggedStackWord ( StgStackOffset i )
- { checkTag(WORD_TAG,gSp[i]); return *stgCast(StgWord*, gSp+1+i); }
-static inline StgAddr taggedStackAddr ( StgStackOffset i )
- { checkTag(ADDR_TAG,gSp[i]); return *stgCast(StgAddr*, gSp+1+i); }
-static inline StgChar taggedStackChar ( StgStackOffset i )
- { checkTag(CHAR_TAG,gSp[i]); return stgCast(StgChar, *(gSp+1+i)) ; }
-static inline StgFloat taggedStackFloat ( StgStackOffset i )
- { checkTag(FLOAT_TAG,gSp[i]); return PK_FLT(gSp+1+i); }
-static inline StgDouble taggedStackDouble ( StgStackOffset i )
- { checkTag(DOUBLE_TAG,gSp[i]); return PK_DBL(gSp+1+i); }
-static inline StgStablePtr taggedStackStable ( StgStackOffset i )
- { checkTag(STABLE_TAG,gSp[i]); return *stgCast(StgStablePtr*, gSp+1+i); }
-
-
-/* --------------------------------------------------------------------------
- * Heap allocation
- *
- * Should we allocate from a nursery or use the
- * doYouWantToGC/allocate interface? We'd already implemented a
- * nursery-style scheme when the doYouWantToGC/allocate interface
- * was implemented.
- * One reason to prefer the doYouWantToGC/allocate interface is to
- * support operations which allocate an unknown amount in the heap
- * (array ops, gmp ops, etc)
- * ------------------------------------------------------------------------*/
-
-static inline StgPtr grabHpUpd( nat size )
-{
- ASSERT( size >= MIN_UPD_SIZE + sizeofW(StgHeader) );
- return allocate(size);
-}
-
-static inline StgPtr grabHpNonUpd( nat size )
-{
- ASSERT( size >= MIN_NONUPD_SIZE + sizeofW(StgHeader) );
- return allocate(size);
-}
-
-/* --------------------------------------------------------------------------
- * Manipulate "update frame" list:
- * o Update frames (based on stg_do_update and friends in Updates.hc)
- * o Error handling/catching (based on catchzh_fast and friends in Prims.hc)
- * o Seq frames (based on seq_frame_entry in Prims.hc)
- * o Stop frames
- * ------------------------------------------------------------------------*/
-
-static inline void PopUpdateFrame ( StgClosure* obj )
-{
- /* NB: doesn't assume that gSp == gSu */
- IF_DEBUG(evaluator,
- fprintf(stderr, "Updating ");
- printPtr(stgCast(StgPtr,gSu->updatee));
- fprintf(stderr, " with ");
- printObj(obj);
- fprintf(stderr,"gSp = %p\tgSu = %p\n\n", gSp, gSu);
- );
-#ifdef EAGER_BLACKHOLING
-#warn LAZY_BLACKHOLING is default for StgHugs
-#error Dont know if EAGER_BLACKHOLING works in StgHugs
- ASSERT(get_itbl(gSu->updatee)->type == BLACKHOLE
- || get_itbl(gSu->updatee)->type == SE_BLACKHOLE
- || get_itbl(gSu->updatee)->type == CAF_BLACKHOLE
- || get_itbl(gSu->updatee)->type == SE_CAF_BLACKHOLE
- );
-#endif /* EAGER_BLACKHOLING */
- UPD_IND(gSu->updatee,obj);
- gSp = stgCast(StgStackPtr,gSu) + sizeofW(StgUpdateFrame);
- gSu = gSu->link;
-}
-
-static inline void PopStopFrame ( StgClosure* obj )
-{
- /* Move gSu just off the end of the stack, we're about to gSpam the
- * STOP_FRAME with the return value.
- */
- gSu = stgCast(StgUpdateFrame*,gSp+1);
- *stgCast(StgClosure**,gSp) = obj;
-}
-
-static inline void PushCatchFrame ( StgClosure* handler )
-{
- StgCatchFrame* fp;
- /* ToDo: stack check! */
- gSp -= sizeofW(StgCatchFrame);
- fp = stgCast(StgCatchFrame*,gSp);
- SET_HDR(fp,(StgInfoTable*)&catch_frame_info,CCCS);
- fp->handler = handler;
- fp->link = gSu;
- gSu = stgCast(StgUpdateFrame*,fp);
-}
-
-static inline void PopCatchFrame ( void )
-{
- /* NB: doesn't assume that gSp == gSu */
- /* fprintf(stderr,"Popping catch frame\n"); */
- gSp = stgCast(StgStackPtr,gSu) + sizeofW(StgCatchFrame);
- gSu = stgCast(StgCatchFrame*,gSu)->link;
-}