Example #1
0
 virtual std::streamsize
 xsputn (const char *s, std::streamsize n)
 {
     if ( prio() <= m_loglevel) {
         return m_out->sputn(s,n);
     }
     return n;
 }
Example #2
0
// Change table size. Size is given as bytes.
void ttSetSize(Engine_t self, size_t size)
{
        // Needed for lockless hashing, and a sanity check for proper bitfield packing.
        assert(sizeof(struct ttSlot) == 2 * sizeof(uint64_t));

        // Calculate largest new size (and mask) not exceeding the requested size
        size_t newSize = bucketLen * sizeof(struct ttSlot);
        size = max(size, newSize); // but allow no smaller than this
        size_t newMask = 0;
        for (; newSize<=size-newSize; newSize+=newSize)
                newMask = (newMask << 1) + bucketLen;

        // Shrink table contents
        if (newSize < self->tt.size)
                for (size_t i=0; i<self->tt.mask+bucketLen; i++)
                        if (prio(self, i & (newMask+bucketLen-1)) < prio(self, i))
                                self->tt.slots[i&(newMask+bucketLen-1)] = self->tt.slots[i];

        // (Re-)allocate memory, retry with smaller sizes until success
        struct ttSlot *newSlots = realloc(self->tt.slots, newSize);
        while (!newSlots && newMask > 0) {
                newSize >>= 1;
                newMask = (newMask & ~bucketLen) >> 1;
                newSlots = realloc(self->tt.slots, newSize);
        }
        if (!newSlots)
                xAbort(errno, "realloc");

        if (!self->tt.slots) // initial allocation is uninitialized
                memset(newSlots, 0, bucketLen * sizeof newSlots[0]);

        // Expand table contents
        if (newSize > self->tt.size)
                for (size_t i=0; i<newMask+bucketLen; i++)
                        newSlots[i] = newSlots[i&(self->tt.mask+bucketLen-1)];

        // Update
        self->tt.slots = newSlots;
        self->tt.size = newSize;
        self->tt.mask = newMask;
}
Example #3
0
        virtual int_type
        overflow (int_type c)
        {
            int p = prio();
            if (c == '\n')
                m_priority = -1;

            if ( p <= m_loglevel)
               return m_out->sputc(static_cast<char_type>(c));

            return c;
        }
Example #4
0
 int sync()
 {
     if (prio() <= m_loglevel)
         return m_out->pubsync();
     return 0;
 }
Example #5
0
void
prf(struct trenod *t)
{
	sigchk();

	if (t)
	{
		int	type;

		type = t->tretyp & COMMSK;

		switch(type)
		{
			case TFND:
			{
				struct fndnod *f = (struct fndnod *)t;

				prs_buff(f->fndnam);
				prs_buff("(){");
				prbgnlst();
				prf(f->fndval);
				prbgnlst();
				prs_buff("}");
				break;
			}

			case TCOM:
				if (comptr(t)->comset) {
					prarg(comptr(t)->comset);
					prc_buff(SPACE);
				}
				prarg(comptr(t)->comarg);
				prio(comptr(t)->comio);
				break;

			case TFORK:
				prf(forkptr(t)->forktre);
				prio(forkptr(t)->forkio);
				if (forkptr(t)->forktyp & FAMP)
					prs_buff(" &");
				break;

			case TPAR:
				prs_buff("(");
				prf(parptr(t)->partre);
				prs_buff(")");
				break;

			case TFIL:
				prf(lstptr(t)->lstlef);
				prs_buff(" | ");
				prf(lstptr(t)->lstrit);
				break;

			case TLST:
				prf(lstptr(t)->lstlef);
				prendlst();
				prf(lstptr(t)->lstrit);
				break;

			case TAND:
				prf(lstptr(t)->lstlef);
				prs_buff(" && ");
				prf(lstptr(t)->lstrit);
				break;

			case TORF:
				prf(lstptr(t)->lstlef);
				prs_buff(" || ");
				prf(lstptr(t)->lstrit);
				break;

			case TFOR:
				{
					struct argnod	*arg;
					struct fornod 	*f = (struct fornod *)t;

					prs_buff("for ");
					prs_buff(f->fornam);

					if (f->forlst)
					{
						arg = f->forlst->comarg;
						prs_buff(" in");

						while(arg != ENDARGS)
						{
							prc_buff(SPACE);
							prs_buff(arg->argval);
							arg = arg->argnxt;
						}
					}

					prendlst();
					prs_buff("do");
					prbgnlst();
					prf(f->fortre);
					prendlst();
					prs_buff("done");
				}
				break;

			case TWH:
			case TUN:
				if (type == TWH)
					prs_buff("while ");
				else
					prs_buff("until ");
				prf(whptr(t)->whtre);
				prendlst();
				prs_buff("do");
				prbgnlst();
				prf(whptr(t)->dotre);
				prendlst();
				prs_buff("done");
				break;

			case TIF:
			{
				struct ifnod *f = (struct ifnod *)t;

				prs_buff("if ");
				prf(f->iftre);
				prendlst();
				prs_buff("then");
				prendlst();
				prf(f->thtre);

				if (f->eltre)
				{
					prendlst();
					prs_buff("else");
					prendlst();
					prf(f->eltre);
				}

				prendlst();
				prs_buff("fi");
				break;
			}

			case TSW:
				{
					struct regnod 	*swl;

					prs_buff("case ");
					prs_buff(swptr(t)->swarg);

					swl = swptr(t)->swlst;
					while(swl)
					{
						struct argnod	*arg = swl->regptr;

						if (arg)
						{
							prs_buff(arg->argval);
							arg = arg->argnxt;
						}

						while(arg)
						{
							prs_buff(" | ");
							prs_buff(arg->argval);
							arg = arg->argnxt;
						}

						prs_buff(")");
						prf(swl->regcom);
						prs_buff(";;");
						swl = swl->regnxt;
					}
				}
				break;
			} 
		} 

	sigchk();
}
Example #6
0
int __expr_sy()
{
    int type;
    while (ptoken->type != TOKEN_INVALID) {
        DEBUG("get type: %d \n", ptoken->type);
        switch(ptoken->type) {
            case (TOKEN_INTEGER):
                memcpy(&sy_token_pool[sindex], ptoken, sizeof(struct __token__));
                sindex++;
                break;
            case (TOKEN_PLUS):
            case (TOKEN_MINUS):
            case (TOKEN_MUL):
            case (TOKEN_DIV):
                DEBUG("\n");
                type = __pop();

                if (type == -1) {
                    __push(ptoken->type);
                    break;
                }

                if (prio(type) >= prio(ptoken->type)) {
                    while (type >= ptoken->type) {
                        sy_token_pool[sindex].type = type;
                        type = __pop();
                        sindex++;
                    }
                    if (type != -1) {
                        __push(type);
                    }
                } else {
                    __push(type);
                    __push(ptoken->type);
                }

                break;
            case (TOKEN_LPAREN):
                __push(ptoken->type);
                break;
            case (TOKEN_RPAREN):
                type = __pop();
                while (type != TOKEN_LPAREN) {
                    sy_token_pool[sindex].type = type;
                    sindex++;
                    type = __pop();
                }
                break;

        }
        ptoken = get_next_token();
    }
    DEBUG("\n");
    type = __pop();
    while (type != -1) {
        sy_token_pool[sindex].type = type;
        type = __pop();
        sindex++;
    }

    return 0;
}
Example #7
0
File: ps.c Project: vocho/openqnx
char *format_N()    { return prio(ps.max_priority, ps.sched_algorithm); }
Example #8
0
File: ps.c Project: vocho/openqnx
char *format_n()    { return prio(ps.priority, ps.sched_algorithm); }
Example #9
0
int main()
{
	char a[100],b[100];
	int i, indexb=0,len;
	printf("Enter the expression: ");
	scanf("%s",a);
	len=strlen(a);
	for(i=0;i<100;i++)
	{
		stack[i]=0;
	}
	for(i=0;i<len;i++)
	{
		if(isdigit(a[i]))
		{
			b[indexb++]=a[i];
		}
		else
		{
			switch (a[i])
			{
				case '(':
							push(a[i]);
							break;
				case ')':
							while(stack[top]!='(')
							{
								b[indexb++]=pop();
							}
							top--;
							break;
				case '+':
				case '-':
							
							//printf("%d %d",prio(stack[top-1]),prio(a[i]));
							if(prio(stack[top-1])<=prio(a[i]))
							{
								b[indexb++]=pop();
								push(a[i]);
								
							}
							else
							{
								push(a[i]);
							}
							break;
				case '*':
				case '/':
							push(a[i]);
							break;
			}
			
		}
	}
	
	while(top >= 0)
	{
		b[indexb++]=pop();
	}
	b[indexb] = '\0';
	//printf("%s\n ",stack);
	printf("%s\n ",b);
	return 0;
}
bool expression_calc::is_operator( const std::string& s ) 
{
	return prio( s ) < strlen( operators() );
}
Example #11
0
int ttWrite(Engine_t self, struct ttSlot slot, int depth, int score, int alpha, int beta)
{
        /*
         *  In some cases, let the older result prevail to avoid information loss
         */

        if (slot.isHardBound)
                if ((slot.isLowerBound && score <= slot.score)
                 || (slot.isUpperBound && score >= slot.score))
                        return slot.score;

        /*
         *  Set fields
         */

        slot.score = score;
        slot.depth = depth;
        slot.date = self->tt.now;
        slot.isUpperBound = score <= alpha;
        slot.isLowerBound = score >= beta;
        slot.isHardBound = false;
        slot.isWinLossScore = false;

        /*
         *  Apply corrections for DTZ and mate scores
         */

        if (score > maxEval) {
                if (score > maxEval + 1) {
                        /*
                         *  Don't store DTZ values when halfmoveClock is 0, because such
                         *  entries wreck progress later in the game (after zeroing).
                         */
                        if (board(self)->halfmoveClock == 0 && score <= maxDtz)
                                return score;
                        slot.score += ply(self);
                        slot.isWinLossScore = 1;
                        assert(slot.score < maxMate); // maxMate not in chess
                }
                slot.isHardBound = slot.isLowerBound;
        }

        if (score < minEval) {
                if (score < minEval - 1) {
                        if (board(self)->halfmoveClock == 0 && score >= minDtz)
                                return score;
                        slot.score -= ply(self);
                        slot.isWinLossScore = 1;
                        assert(slot.score >= minMate);
                }
                slot.isHardBound = slot.isUpperBound;
        }

        /*
         *  Find best slot `bucket+i' to store the search result in, either
         *   - the slot with the lowest (-age, depth)-priority, or
         *   - the last used slot, if still present.
         */

        size_t bucket = slot.key & self->tt.mask;
        int i = -1, iPrio = maxInt;
        for (int j=0; j<bucketLen; j++) {
                struct ttSlot local = self->tt.slots[bucket+j];
                if ((local.key ^ local.data) == slot.key) {
                        i = j;
                        break;
                }
                int jPrio = prio(self, bucket + j);
                if (jPrio < iPrio)
                        i = j, iPrio = jPrio;
        }
        assert(i >= 0);

        /*
         *  Write into table
         */

        slot.key ^= slot.data;
        self->tt.slots[bucket+i] = slot;

        return score;
}