Example #1
0
////////////////////
// Unary operator //
////////////////////
ExprNode *UniExprNode::semant( Environ *e ){
	expr=expr->semant( e );
	sem_type=expr->sem_type;
	if( sem_type!=Type::int_type && sem_type!=Type::float_type ) ex( "Illegal operator for type" );
	if( ConstNode *c=expr->constNode() ){
		ExprNode *e;
		if( sem_type==Type::int_type ){
			switch( op ){
			case '+':e=d_new IntConstNode( +c->intValue() );break;
			case '-':e=d_new IntConstNode( -c->intValue() );break;
			case ABS:e=d_new IntConstNode( c->intValue()>=0 ? c->intValue() : -c->intValue() );break;
			case SGN:e=d_new IntConstNode( c->intValue()>0 ? 1 : (c->intValue()<0 ? -1 : 0) );break;
			}
		}else{
			switch( op ){
			case '+':e=d_new FloatConstNode( +c->floatValue() );break;
			case '-':e=d_new FloatConstNode( -c->floatValue() );break;
			case ABS:e=d_new FloatConstNode( c->floatValue()>=0 ? c->floatValue() : -c->floatValue() );break;
			case SGN:e=d_new FloatConstNode( c->floatValue()>0 ? 1 : (c->floatValue()<0 ? -1 : 0) );break;
			}
		}
		delete this;
		return e;
	}
	return this;
}
Example #2
0
TEST(AIMatchTest, CanGetMove) {
    auto board = Board(9);
    auto node = IntConstNode(1);
    auto move = getBestMove(board, node, BLACK);
    EXPECT_EQ(8, move.x);
    EXPECT_EQ(8, move.y);
}
Example #3
0
/////////////////////////////////////////////////////
// boolean expression - accepts ints, returns ints //
/////////////////////////////////////////////////////
ExprNode *BinExprNode::semant( Environ *e ){
	lhs=lhs->semant(e);lhs=lhs->castTo( Type::int_type,e );
	rhs=rhs->semant(e);rhs=rhs->castTo( Type::int_type,e );
	ConstNode *lc=lhs->constNode(),*rc=rhs->constNode();
	if( lc && rc ){
		ExprNode *expr;
		switch( op ){
		case AND:expr=d_new IntConstNode( lc->intValue() & rc->intValue() );break;
		case OR: expr=d_new IntConstNode( lc->intValue() | rc->intValue() );break;
		case XOR:expr=d_new IntConstNode( lc->intValue() ^ rc->intValue() );break;
		case SHL:expr=d_new IntConstNode( lc->intValue()<< rc->intValue() );break;
		case SHR:expr=d_new IntConstNode( (unsigned)lc->intValue()>>rc->intValue() );break;
		case SAR:expr=d_new IntConstNode( lc->intValue()>> rc->intValue() );break;
		}
		delete this;
		return expr;
	}
Example #4
0
ExprNode *CastNode::semant( Environ *e ){
	if( !expr->sem_type ){
		expr=expr->semant( e );
	}

	if( ConstNode *c=expr->constNode() ){
		ExprNode *e;
		if( type==Type::int_type ) e=d_new IntConstNode( c->intValue() );
		else if( type==Type::float_type ) e=d_new FloatConstNode( c->floatValue() );
		else e=d_new StringConstNode( c->stringValue() );
		delete this;
		return e;
	}

	sem_type=type;
	return this;
}