Ejemplo n.º 1
0
/// Method handling the change of role in the squad of a player
void TeamManager::putPlayerOnSquadPosition(const JSON::Dict &response, int peer_id){
	int position = 0;
	int member_id = 0;
	if (ISINT(response.get(net::MSG::PLAYER_ID)))
		member_id = INT(response.get(net::MSG::PLAYER_ID));
	if (ISINT(response.get(net::MSG::SQUAD_POSITION)))
		position = INT(response.get(net::MSG::SQUAD_POSITION));
	_users[peer_id]->getTeam().getSquad().putPlayerAtPosition(member_id, position);
	sendTeamInfos(_users[peer_id]->getTeam(), peer_id);
	MemoryAccess::save(_users[peer_id]->getTeam());
}
Ejemplo n.º 2
0
/// Method upgrading the ability of a player
void TeamManager::upgradePlayerAbility(const JSON::Dict &response, int peer_id){
	int member_id = 0;
	int ability = 0;
	if (ISINT(response.get(net::MSG::PLAYER_ID)))
		member_id = INT(response.get(net::MSG::PLAYER_ID));
	if (ISINT(response.get(net::MSG::ABILITY)))
		ability = INT(response.get(net::MSG::ABILITY));
	int decAC=_users[peer_id]->getTeam().upgradePlayerAbility(member_id,ability);
	_users[peer_id]->getTeam().loseAcPoints(decAC);
	
	sendTeamInfos(_users[peer_id]->getTeam(), peer_id);
	MemoryAccess::save(_users[peer_id]->getTeam());	
}
Ejemplo n.º 3
0
VAL idris_bigMinus(VM* vm, VAL x, VAL y) {
    if (ISINT(x) && ISINT(y)) {
        i_int vx = GETINT(x);
        i_int vy = GETINT(y);
        if ((vx <= 0 && vy <=0) || (vx >=0 && vy <=0)) {
            return INTOP(-, x, y);
        }
        i_int res = vx - vy;
        if (res >= 1<<30 || res <= -(1 << 30)) {
            return bigSub(vm, GETBIG(vm, x), GETBIG(vm, y));
        } else {
            return MKINT(res);
        }
    } else {
Ejemplo n.º 4
0
VAL GETBIG(VM * vm, VAL x) {
    idris_requireAlloc(IDRIS_MAXGMP);

    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
        idris_doneAlloc();
        bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

        mpz_init(*bigint);
        mpz_set_si(*bigint, GETINT(x));

        SETTY(cl, CT_BIGINT);
        cl -> info.ptr = (void*)bigint;

        return cl;
    } else {
        idris_doneAlloc();
        switch(GETTY(x)) {
        case CT_FWD:
            return GETBIG(vm, x->info.ptr);
        default:
            return x;
        }
    }
}
Ejemplo n.º 5
0
VAL idris_bigPlus(VM* vm, VAL x, VAL y) {
    if (ISINT(x) && ISINT(y)) {
        i_int vx = GETINT(x);
        i_int vy = GETINT(y);
        if ((vx <= 0 && vy >=0) || (vx >=0 && vy <=0)) {
            return ADD(x, y);
        }
        i_int res = vx + vy;
        if (res >= 1<<30 || res <= -(1 << 30)) {
            return bigAdd(vm, GETBIG(vm, x), GETBIG(vm, y));
        } else {
            return MKINT(res);
        }
    } else {
        return bigAdd(vm, GETBIG(vm, x), GETBIG(vm, y));
    }
}
Ejemplo n.º 6
0
Archivo: bpx.c Proyecto: edechter/PRISM
BPLONG bpx_get_integer(TERM t) {
	XDEREF(t);

	if (ISINT(t)) {
		return INTVAL(t);
	} else {
		bpx_raise("integer expected");
	}

	return 0;  /* should not be reached */
}
Ejemplo n.º 7
0
static MLvalue TO_MLvalue(mlval v)
{
  mlval *box;

  if (ISINT(v)) return((MLvalue)v);

  box = next_box();
  *box = v;
  declare_root(box, 0);

  return((MLvalue)MKPTR(box));
}
Ejemplo n.º 8
0
Archivo: bpx.c Proyecto: edechter/PRISM
double bpx_get_float(TERM t) {
	XDEREF(t);

	if (ISINT(t)) {
		return (double)(INTVAL(t));
	} else if (ISFLOAT(t)) {
		return floatval(t);
	} else {
		bpx_raise("integer or floating number expected");
	}

	return 0.0;  /* should not be reached */
}
Ejemplo n.º 9
0
static const char* set_param(cmd_parms* cmd, void* cfg,
	const char* val) {
  const char* p ;
  pgasp_config* pgasp = (pgasp_config*) ap_get_module_config(cmd->server->module_config, &pgasp_module ) ;

  switch ( (intptr_t) cmd->info ) {
  case cmd_setkey:
    pgasp->key = val;
    apr_hash_set(pgasp_pool_config, pgasp->key, APR_HASH_KEY_STRING, pgasp);
    pgasp->key_set = 1;
    break ;
  case cmd_connection:
    pgasp->connection_string = val ;
    pgasp->connection_string_set = 1;
    break ;
  case cmd_allowed:
    if (pgasp->allowed_count < MAX_ALLOWED_PAGES)
      pgasp->allowed[pgasp->allowed_count++] = val;
    break;
  case cmd_min: ISINT(val) ; pgasp->nmin = atoi(val) ;
    pgasp->nmin_set = 1;
    break ;
  case cmd_keep: ISINT(val) ; pgasp->nkeep = atoi(val) ;
    pgasp->nkeep_set = 1;
    break ;
  case cmd_max: ISINT(val) ; pgasp->nmax = atoi(val) ;
    pgasp->nmax_set = 1;
    break ;
  case cmd_exp: ISINT(val) ; pgasp->exptime = atoi(val) ;
    pgasp->exptime_set = 1;
    break ;
  case cmd_enabled:
    if (!strcasecmp(val, "on")) pgasp->is_enabled = true;
    else pgasp->is_enabled = false;
    pgasp->is_enabled_set = 1;
    break;
  }
  return NULL ;
}
Ejemplo n.º 10
0
dim_check(Namep q)
#endif
{
	register struct Dimblock *vdim = q->vdim;
	register expptr nelt;

	if(!(nelt = vdim->nelt) || !ISCONST(nelt))
		dclerr("adjustable dimension on non-argument", q);
	else if (!ONEOF(nelt->headblock.vtype, MSKINT|MSKREAL))
		bad_dimtype(q);
	else if (ISINT(nelt->headblock.vtype)
			? nelt->constblock.Const.ci <= 0
			: nelt->constblock.Const.cd[0] <= 0.)
		dclerr("nonpositive dimension", q);
	}
Ejemplo n.º 11
0
VAL GETBIG(VM * vm, VAL x) {
    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*));
        bigint = allocate(vm, sizeof(mpz_t));

        mpz_init(*bigint);
        mpz_set_si(*bigint, GETINT(x));

        cl -> ty = BIGINT;
        cl -> info.ptr = (void*)bigint;

        return cl;
    } else {
        return x;
    }
}
Ejemplo n.º 12
0
VAL GETBIG(VM * vm, VAL x) {
    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*) + 
                              sizeof(mpz_t), 0);
        bigint = (mpz_t*)(((char*)cl) + sizeof(ClosureType) + sizeof(void*));

        mpz_init(*bigint);
        mpz_set_si(*bigint, GETINT(x));

        SETTY(cl, BIGINT);
        cl -> info.ptr = (void*)bigint;

        return cl;
    } else {
        return x;
    }
}
Ejemplo n.º 13
0
imagpart(register Addrp p)
#endif
{
	register Addrp q;

	if( ISCOMPLEX(p->vtype) )
	{
		if (p->tag == TADDR && p->uname_tag == UNAM_CONST)
			return mkrealcon (p -> vtype + TYREAL - TYCOMPLEX,
				p->user.kludge.vstg1 ? p->user.Const.cds[1]
				: cds(dtos(p->user.Const.cd[1]),CNULL));
		q = (Addrp) cpexpr((expptr) p);
		q = mkfield (q, "i", p -> vtype + TYREAL - TYCOMPLEX);
		return( (expptr) q );
	}
	else

/* Cast an integer type onto a Double Real type */

		return( mkrealcon( ISINT(p->vtype) ? TYDREAL : p->vtype , "0"));
}
Ejemplo n.º 14
0
VAL GETBIG(VM * vm, VAL x) {
    if (ISINT(x)) {
        mpz_t* bigint;
        VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
        bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));

        mpz_init(*bigint);
        mpz_set_si(*bigint, GETINT(x));

        SETTY(cl, BIGINT);
        cl -> info.ptr = (void*)bigint;

        return cl;
    } else {
        switch(GETTY(x)) {
        case FWD:
            return GETBIG(vm, x->info.ptr);
        default:
            return x;
        }
    }
}
Ejemplo n.º 15
0
void
putcmgo(bigptr x, int nlab, struct labelblock *labels[])
{
	bigptr y;
	int i;

	if (!ISINT(x->vtype)) {
		execerr("computed goto index must be integer", NULL);
		return;
	}

	y = fmktemp(x->vtype, NULL);
	putexpr(mkexpr(OPASSIGN, cpexpr(y), x));
#ifdef notyet /* target-specific computed goto */
	vaxgoto(y, nlab, labels);
#else
	/*
	 * Primitive implementation, should use table here.
	 */
	for(i = 0 ; i < nlab ; ++i)
		putif(mkexpr(OPNE, cpexpr(y), MKICON(i+1)), labels[i]->labelno);
	frexpr(y);
#endif
}
Ejemplo n.º 16
0
VAL copy(VM* vm, VAL x) {
    int i, ar;
    Closure* cl = NULL;
    if (x==NULL || ISINT(x)) {
        return x;
    }
    switch(GETTY(x)) {
    case CON:
        ar = CARITY(x);
        if (ar == 0 && CTAG(x) < 256) {
            return x;
        } else {
            allocCon(cl, vm, CTAG(x), ar, 1);
            for(i = 0; i < ar; ++i) {
    //            *argptr = copy(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
                cl->info.c.args[i] = x->info.c.args[i];
            }
        }
        break;
    case FLOAT:
        cl = MKFLOATc(vm, x->info.f);
        break;
    case STRING:
        cl = MKSTRc(vm, x->info.str);
        break;
    case STROFFSET:
        cl = MKSTROFFc(vm, x->info.str_offset);
        break;
    case BUFFER:
        cl = MKBUFFERc(vm, x->info.buf);
        break;
    case BIGINT:
        cl = MKBIGMc(vm, x->info.ptr);
        break;
    case PTR:
        cl = MKPTRc(vm, x->info.ptr);
        break;
    case MANAGEDPTR:
        cl = MKMPTRc(vm, x->info.mptr->data, x->info.mptr->size);
        break;
    case BITS8:
        cl = idris_b8CopyForGC(vm, x);
        break;
    case BITS16:
        cl = idris_b16CopyForGC(vm, x);
        break;
    case BITS32:
        cl = idris_b32CopyForGC(vm, x);
        break;
    case BITS64:
        cl = idris_b64CopyForGC(vm, x);
        break;
    case FWD:
        return x->info.ptr;
    default:
        break;
    }
    SETTY(x, FWD);
    x->info.ptr = cl;
    return cl;
}
Ejemplo n.º 17
0
VAL idris_bigAnd(VM* vm, VAL x, VAL y) {
    if (ISINT(x) && ISINT(y)) {
        return INTOP(&, x, y);
    } else {
        return bigAnd(vm, GETBIG(vm, x), GETBIG(vm, y));
Ejemplo n.º 18
0
setbound(Namep v, int nd, struct Dims *dims)
#endif
{
	expptr q, q0, t;
	struct Dimblock *p;
	int i;
	extern chainp new_vars;
	char buf[256];

	if(v->vclass == CLUNKNOWN)
		v->vclass = CLVAR;
	else if(v->vclass != CLVAR)
	{
		dclerr("only variables may be arrays", v);
		return;
	}

	v->vdim = p = (struct Dimblock *)
	    ckalloc( sizeof(int) + (3+2*nd)*sizeof(expptr) );
	p->ndim = nd--;
	p->nelt = ICON(1);
	doin_setbound = 1;

	if (noextflag)
		for(i = 0; i <= nd; i++)
			if (((q = dims[i].lb) && !ISINT(q->headblock.vtype))
			 || ((q = dims[i].ub) && !ISINT(q->headblock.vtype))) {
				sprintf(buf, "dimension %d of %s is not an integer.",
					i+1, v->fvarname);
				errext(buf);
				break;
				}

	for(i = 0; i <= nd; i++) {
		if (((q = dims[i].lb) && !ISINT(q->headblock.vtype)))
			dims[i].lb = mkconv(TYINT, q);
		if (((q = dims[i].ub) && !ISINT(q->headblock.vtype)))
			dims[i].ub = mkconv(TYINT, q);
		}

	for(i = 0; i <= nd; ++i)
	{
		if( (q = dims[i].ub) == NULL)
		{
			if(i == nd)
			{
				frexpr(p->nelt);
				p->nelt = NULL;
			}
			else
				err("only last bound may be asterisk");
			p->dims[i].dimsize = ICON(1);
			p->dims[i].dimexpr = NULL;
		}
		else
		{

			if(dims[i].lb)
			{
				q = mkexpr(OPMINUS, q, cpexpr(dims[i].lb));
				q = mkexpr(OPPLUS, q, ICON(1) );
			}
			if( ISCONST(q) )
			{
				p->dims[i].dimsize = q;
				p->dims[i].dimexpr = (expptr) PNULL;
			}
			else {
				sprintf(buf, " %s_dim%d", v->fvarname, i+1);
				p->dims[i].dimsize = (expptr)
					autovar(1, tyint, EXNULL, buf);
				p->dims[i].dimexpr = q;
				if (i == nd)
					v->vlastdim = new_vars;
				v->vdimfinish = 1;
			}
			if(p->nelt)
				p->nelt = mkexpr(OPSTAR, p->nelt,
				    cpexpr(p->dims[i].dimsize) );
		}
	}

	q = dims[nd].lb;
	q0 = 0;
	if(q == NULL)
		q = q0 = ICON(1);

	for(i = nd-1 ; i>=0 ; --i)
	{
		t = dims[i].lb;
		if(t == NULL)
			t = ICON(1);
		if(p->dims[i].dimsize) {
			if (q == q0) {
				q0 = 0;
				frexpr(q);
				q = cpexpr(p->dims[i].dimsize);
				}
			else
				q = mkexpr(OPSTAR, cpexpr(p->dims[i].dimsize), q);
			q = mkexpr(OPPLUS, t, q);
			}
	}

	if( ISCONST(q) )
	{
		p->baseoffset = q;
		p->basexpr = NULL;
	}
	else
	{
		sprintf(buf, " %s_offset", v->fvarname);
		p->baseoffset = (expptr) autovar(1, tyint, EXNULL, buf);
		p->basexpr = q;
		v->vdimfinish = 1;
	}
	doin_setbound = 0;
}
Ejemplo n.º 19
0
LOCAL struct bigblock *
putcx1(bigptr qq)
{
	struct bigblock *q, *lp, *rp;
	register struct bigblock *resp;
	NODE *p;
	int opcode;
	int ltype, rtype;

	ltype = rtype = 0; /* XXX gcc */
	if(qq == NULL)
		return(NULL);

	switch(qq->tag) {
	case TCONST:
		if( ISCOMPLEX(qq->vtype) )
			qq = putconst(qq);
		return( qq );

	case TADDR:
		if( ! addressable(qq) ) {
			resp = fmktemp(tyint, NULL);
			p = putassign( cpexpr(resp), qq->b_addr.memoffset );
			sendp2(p);
			qq->b_addr.memoffset = resp;
		}
		return( qq );

	case TEXPR:
		if( ISCOMPLEX(qq->vtype) )
			break;
		resp = fmktemp(TYDREAL, NO);
		p = putassign( cpexpr(resp), qq);
		sendp2(p);
		return(resp);

	default:
		fatal1("putcx1: bad tag %d", qq->tag);
	}

	opcode = qq->b_expr.opcode;
	if(opcode==OPCALL || opcode==OPCCALL) {
		q = putcall(qq);
		sendp2(callval);
		return(q);
	} else if(opcode == OPASSIGN) {
		return( putcxeq(qq) );
	}

	resp = fmktemp(qq->vtype, NULL);
	if((lp = putcx1(qq->b_expr.leftp) ))
		ltype = lp->vtype;
	if((rp = putcx1(qq->b_expr.rightp) ))
		rtype = rp->vtype;

	switch(opcode) {
	case OPCOMMA:
		frexpr(resp);
		resp = rp;
		rp = NULL;
		break;

	case OPNEG:
		p = putassign(realpart(resp),
		    mkexpr(OPNEG, realpart(lp), NULL));
		sendp2(p);
		p = putassign(imagpart(resp),
		    mkexpr(OPNEG, imagpart(lp), NULL));
		sendp2(p);
		break;

	case OPPLUS:
	case OPMINUS:
		p = putassign( realpart(resp),
		    mkexpr(opcode, realpart(lp), realpart(rp) ));
		sendp2(p);
		if(rtype < TYCOMPLEX) {
			p = putassign(imagpart(resp), imagpart(lp) );
		} else if(ltype < TYCOMPLEX) {
			if(opcode == OPPLUS)
				p = putassign( imagpart(resp), imagpart(rp) );
			else
				p = putassign( imagpart(resp),
				    mkexpr(OPNEG, imagpart(rp), NULL) );
		} else
			p = putassign( imagpart(resp),
			    mkexpr(opcode, imagpart(lp), imagpart(rp) ));
		sendp2(p);
		break;

	case OPSTAR:
		if(ltype < TYCOMPLEX) {
			if( ISINT(ltype) )
				lp = intdouble(lp);
			p = putassign( realpart(resp),
			    mkexpr(OPSTAR, cpexpr(lp), realpart(rp) ));
			sendp2(p);
			p = putassign( imagpart(resp),
			    mkexpr(OPSTAR, cpexpr(lp), imagpart(rp) ));
		} else if(rtype < TYCOMPLEX) {
			if( ISINT(rtype) )
				rp = intdouble(rp);
			p = putassign( realpart(resp),
			    mkexpr(OPSTAR, cpexpr(rp), realpart(lp) ));
			sendp2(p);
			p = putassign( imagpart(resp),
			    mkexpr(OPSTAR, cpexpr(rp), imagpart(lp) ));
		} else {
			p = putassign( realpart(resp), mkexpr(OPMINUS,
				mkexpr(OPSTAR, realpart(lp), realpart(rp)),
				mkexpr(OPSTAR, imagpart(lp), imagpart(rp)) ));
			sendp2(p);
			p = putassign( imagpart(resp), mkexpr(OPPLUS,
				mkexpr(OPSTAR, realpart(lp), imagpart(rp)),
				mkexpr(OPSTAR, imagpart(lp), realpart(rp)) ));
		}
		sendp2(p);
		break;

	case OPSLASH:
		/* fixexpr has already replaced all divisions
		 * by a complex by a function call
		 */
		if( ISINT(rtype) )
			rp = intdouble(rp);
		p = putassign( realpart(resp),
		    mkexpr(OPSLASH, realpart(lp), cpexpr(rp)) );
		sendp2(p);
		p = putassign( imagpart(resp),
		    mkexpr(OPSLASH, imagpart(lp), cpexpr(rp)) );
		sendp2(p);
		break;

	case OPCONV:
		p = putassign( realpart(resp), realpart(lp) );
		if( ISCOMPLEX(lp->vtype) )
			q = imagpart(lp);
		else if(rp != NULL)
			q = realpart(rp);
		else
			q = mkrealcon(TYDREAL, 0.0);
		sendp2(p);
		p = putassign( imagpart(resp), q);
		sendp2(p);
		break;

	default:
		fatal1("putcx1 of invalid opcode %d", opcode);
	}

	frexpr(lp);
	frexpr(rp);
	ckfree(qq);
	return(resp);
}
Ejemplo n.º 20
0
static mlval TO_mlval(MLvalue v)
{  return( (mlval)(ISINT(v) ? v : MLVAL(v)) ); }
Ejemplo n.º 21
0
extern void free_ml_value(MLvalue val)
{
  if (ISINT(val)) return;
  release_box(UNPTR(val));
}
Ejemplo n.º 22
0
bool bpx_is_integer(TERM t)
{
    XDEREF(t);
    return ISINT(t);
}
Ejemplo n.º 23
0
VAL copy(VM* vm, VAL x) {
    int i, ar;
    Closure* cl = NULL;
    if (x==NULL || ISINT(x)) {
        return x;
    }
    switch(GETTY(x)) {
    case CT_CON:
        ar = CARITY(x);
        if (ar == 0 && CTAG(x) < 256) {
            return x;
        } else {
            allocCon(cl, vm, CTAG(x), ar, 1);
            for(i = 0; i < ar; ++i) {
                cl->info.c.args[i] = x->info.c.args[i];
            }
        }
        break;
    case CT_FLOAT:
        cl = MKFLOATc(vm, x->info.f);
        break;
    case CT_STRING:
        cl = MKSTRc(vm, x->info.str);
        break;
    case CT_STROFFSET:
        cl = MKSTROFFc(vm, x->info.str_offset);
        break;
    case CT_BIGINT:
        cl = MKBIGMc(vm, x->info.ptr);
        break;
    case CT_PTR:
        cl = MKPTRc(vm, x->info.ptr);
        break;
    case CT_MANAGEDPTR:
        cl = MKMPTRc(vm, x->info.mptr->data, x->info.mptr->size);
        break;
    case CT_BITS8:
        cl = idris_b8CopyForGC(vm, x);
        break;
    case CT_BITS16:
        cl = idris_b16CopyForGC(vm, x);
        break;
    case CT_BITS32:
        cl = idris_b32CopyForGC(vm, x);
        break;
    case CT_BITS64:
        cl = idris_b64CopyForGC(vm, x);
        break;
    case CT_FWD:
        return x->info.ptr;
    case CT_RAWDATA:
        {
            size_t size = x->info.size + sizeof(Closure);
            cl = allocate(size, 0);
            memcpy(cl, x, size);
        }
        break;
    case CT_CDATA:
        cl = MKCDATAc(vm, x->info.c_heap_item);
        c_heap_mark_item(x->info.c_heap_item);
        break;
    default:
        break;
    }
    SETTY(x, CT_FWD);
    x->info.ptr = cl;
    return cl;
}