示例#1
0
文件: bt_int.c 项目: NosicLin/Codger
static int bi_rich_cmp(Robject* x,Robject* y,int op)
{

	int type=rt_type(y);
	if(type==RT_INT)
	{
		int ret=btint_cmp(R_TO_I(x),R_TO_I(y),op);
		return ret;
	}
	if(type==RT_FLOAT)
	{
		BtFloat* c_x=btint_to_btfloat(R_TO_I(x));
		if(c_x==NULL) return -1;
		int  ret=btfloat_cmp(c_x,R_TO_F(y),op);
		robject_release(F_TO_R(c_x));
		return ret;
	}
	if(rt_type(y)==RT_LONG)
	{
		BtLong* c_x=btint_to_btlong(R_TO_I(x));
		if(c_x==NULL) return -1;
		int ret=btlong_cmp(c_x,R_TO_L(y),op);
		robject_release(L_TO_R(c_x));
		return ret;
	}
	return CMP_NOT_SUPPORT;
}
示例#2
0
文件: bt_int.c 项目: NosicLin/Codger
int bi_cmp(Robject* x,Robject* y,int op)
{
	int type=rt_type(y);
	if(type==RT_INT)
	{
		int ret=btint_cmp(R_TO_I(x),R_TO_I(y),op);
		return ret;
	}
	if(type==RT_FLOAT)
	{
		BtFloat* c_x=btint_to_btfloat(R_TO_I(x));
		if(c_x==NULL) return -1;
		int  ret=btfloat_cmp(c_x,R_TO_F(y),op);
		robject_release(F_TO_R(c_x));
		return ret;
	}
	if(rt_type(y)==RT_LONG)
	{
		BtLong* c_x=btint_to_btlong(R_TO_I(x));
		if(c_x==NULL) return -1;
		int ret=btlong_cmp(c_x,R_TO_L(y),op);
		robject_release(L_TO_R(c_x));
		return ret;
	}
	except_type_err_format(MSG_BINARY_UNSUPPORT,
					CMP_NAME(op),robject_name(x),
					robject_name(y));
	return -1;
}
示例#3
0
文件: bt_int.c 项目: NosicLin/Codger
static Robject* bi_xor(Robject* x,Robject* y)
{
	int type =rt_type(y);
	if(type==RT_INT)
	{
		BtInt* ret=btint_xor(R_TO_I(x),R_TO_I(y));
		if(ret==NULL)
		{
			return NULL;
		}
		return I_TO_R(ret);
	}
	if(rt_type(y)==RT_LONG)
	{
		BtLong* c_x=btint_to_btlong(R_TO_I(x));
		if(c_x==NULL)
		{
			return NULL;
		}
		BtLong* ret=btlong_xor(c_x,R_TO_L(y));
		robject_release(L_TO_R(c_x));
		if(ret==NULL)
		{
			return NULL;
		}
		return L_TO_R(ret);
	}
	except_type_err_format(MSG_BINARY_UNSUPPORT,
						OPER_XOR,robject_name(x),
					   	robject_name(y));
	return NULL;
	
}
示例#4
0
static Robject* ba_get_item(Robject* ro,Robject* index)
{
	int type=rt_type(index);
	int pos=0;
	BtArray* ba=R_TO_A(ro);
	if(type==RT_INT)
	{
		pos=btint_get(R_TO_I(index));
		return btarray_get_item(ba,pos);
	}
	if(type==RT_LONG)
	{
		if(btlong_over_int(R_TO_L(index)))
		{
			except_index_err_format("cannot fix long to int");
			return NULL;
		}
		pos=btlong_to_int(R_TO_L(index));
		return btarray_get_item(ba,pos);
	}

	except_index_err_format("array index must integer,not '%s'",
							robject_name(index));
	return NULL;
}
示例#5
0
static Robject* ba_plus(Robject* l,Robject* r)
{
	int type=rt_type(r);
	if(type!=RT_ARRAY)
	{
		except_type_err_format("cannot concatenate array and '%s'",
								robject_name(r));
		return NULL;
	}

	BtArray* ret= btarray_plus(R_TO_A(l),R_TO_A(r));
	return ret==NULL?NULL:A_TO_R(ret);
}
示例#6
0
文件: bt_int.c 项目: NosicLin/Codger
/* int * float=float
 * int * long=long
 * int * int =int 
 */
static Robject* bi_mul(Robject* x,Robject* y)
{

	int type=rt_type(y);
	if(type==RT_INT)
	{
		BtInt* ret=btint_mul(R_TO_I(x),R_TO_I(y));
		if(ret==NULL)
		{
			return NULL;
		}
		return I_TO_R(ret);
	}
	if(type==RT_FLOAT)
	{
		BtFloat*  c_x=btint_to_btfloat(R_TO_I(x));
		if(c_x==NULL)
		{
			return NULL;
		}
		BtFloat* ret=btfloat_mul(c_x,R_TO_F(y));
		robject_release(F_TO_R(c_x));
		if(ret==NULL)
		{
			return NULL;
		}
		return  F_TO_R(ret);
	}
	/* int*long, eg 2*333l */
	if(type==RT_LONG)
	{
		BtLong* c_x=btint_to_btlong(R_TO_I(x));
		if(c_x==NULL)
		{
			return NULL;
		}
		BtLong* ret=btlong_mul(c_x,R_TO_L(y));
		robject_release(L_TO_R(c_x));
		if(ret==NULL)
		{
			return NULL;
		}
		return L_TO_R(ret);
	}
	/* error type */
	except_type_err_format(MSG_BINARY_UNSUPPORT,
						OPER_MUL, robject_name(x),
						robject_name(y));
	return NULL;

}
示例#7
0
文件: runtime.c 项目: stonegao/mirb
rt_value rt_inspect(rt_value obj)
{
	rt_compiled_block_t inspect = rt_lookup_nothrow(obj, rt_symbol_from_cstr("inspect"));

	rt_value result = RT_NIL;

	if(inspect && (inspect != (rt_compiled_block_t)rt_object_inspect || rt_lookup_nothrow(obj, rt_symbol_from_cstr("to_s"))))
		result = inspect(obj, 0, 0, 0);

	if(rt_type(result) == C_STRING)
		return result;
	else
		return rt_object_to_s(obj, 0, 0, 0);
}
示例#8
0
文件: bt_int.c 项目: NosicLin/Codger
/* int+int=int
 * int+float=float
 * int+long=long
 */
static Robject* bi_plus(Robject* x,Robject* y)
{
	int type=rt_type(y);
	if(type==RT_INT)
	{
		BtInt* ret=btint_plus(R_TO_I(x),R_TO_I(y));
		if(ret==NULL)
		{
			return NULL;
		}
		return I_TO_R(ret);
	}
	else if(type==RT_FLOAT)
	{
		BtFloat*  c_x=btint_to_btfloat(R_TO_I(x));
		if(c_x==NULL)
		{
			return NULL;
		}
		BtFloat* ret=btfloat_plus(c_x,R_TO_F(y));
		robject_release(F_TO_R(c_x));
		if(ret==NULL)
		{
			return NULL;
		}
		return  F_TO_R(ret);
	}
	if(type==RT_LONG)
	{
		BtLong* c_x=btint_to_btlong(R_TO_I(x));
		if(c_x==NULL)
		{
			return NULL;
		}
		BtLong* ret=btlong_plus(c_x,R_TO_L(y));
		robject_release(L_TO_R(c_x));
		if(ret==NULL)
		{
			return NULL;
		}
		return L_TO_R(ret);
	}
	if(type==RT_STRING)
	{
		BtString* c_x=btint_to_btstring(R_TO_I(x));
		if(c_x==NULL)
		{
			return NULL;
		}
		BtString* ret=btstring_plus(c_x,R_TO_S(y));
		robject_release(S_TO_R(c_x));
		if(ret==NULL)
		{
			return NULL;
		}
		return S_TO_R(ret);
	}


	except_type_err_format(MSG_BINARY_UNSUPPORT,
							OPER_PLUS,robject_name(x),
							robject_name(y));
	return NULL;
}