Exemplo n.º 1
0
DaoValue* DaoCinValue_DoUnary( DaoValue *self, DaoVmCode *op, DaoProcess *proc )
{
	DaoType *type = self->xCinValue.cintype->vatype;
	DaoType *argtype = proc->activeTypes[op->a];;
	DaoRoutine *rout = NULL;
	int retc = 0;

	switch( op->code ){
	case DVM_NOT   :
	case DVM_MINUS :
	case DVM_TILDE :
	case DVM_SIZE  : break;
	default: return NULL;
	}
	rout = DaoType_FindFunctionChars( type, DaoVmCode_GetOperator( op->code ) );
	if( rout == NULL ) goto TryTarget;
	if( op->c == op->a ){
		retc = DaoProcess_PushCallWithTypes( proc, rout, self, & self, & argtype, 1 );
	}else{
		retc = DaoProcess_PushCallWithTypes( proc, rout, NULL, & self, & argtype, 1 );
	}
	// TODO: retc;
	if( retc == 0 ) return NULL;

TryTarget:
	type = DaoValue_GetType( self->xCinValue.value, proc->vmSpace );
	if( type == NULL ) type = self->xCinValue.cintype->target;
	if( type != NULL && type->core != NULL && type->core->DoUnary != NULL ){
		return type->core->DoUnary( self->xCinValue.value, op, proc );
	}
	return NULL;
}
Exemplo n.º 2
0
DaoValue* DaoCinValue_DoBinary( DaoValue *self, DaoVmCode *op, DaoValue *args[2], DaoProcess *proc )
{
	DaoRoutine *rout = NULL;
	DaoValue *selfvalue = NULL;
	DaoType *argtypes[2];
	DaoType *type;
	int retc;

	switch( op->code ){
	case DVM_ADD : case DVM_SUB :
	case DVM_MUL : case DVM_DIV :
	case DVM_MOD : case DVM_POW :
	case DVM_BITAND : case DVM_BITOR  :
	case DVM_AND : case DVM_OR :
	case DVM_LT  : case DVM_LE :
	case DVM_EQ  : case DVM_NE :
	case DVM_IN :
		break;
	default: return NULL;
	}

	type = self->xCinValue.cintype->vatype;
	argtypes[0] = proc->activeTypes[ op->a ];
	argtypes[1] = proc->activeTypes[ op->b ];

	if( op->c == op->a ){
		rout = DaoType_FindFunctionChars( type, DaoVmCode_GetCompoundOperator( op->code ) );
		if( rout != NULL ){
			DaoProcess_PushCallWithTypes( proc, rout, self, args+1, argtypes+1, 1 );
			goto TryTarget;
		}
	}

	rout = DaoType_FindFunctionChars( type, DaoVmCode_GetOperator( op->code ) );
	if( rout == NULL ) goto TryTarget;

	if( op->c == op->a && self == args[0] ) selfvalue = self;
	if( op->c == op->b && self == args[1] ) selfvalue = self;
	retc = DaoProcess_PushCallWithTypes( proc, rout, selfvalue, args, argtypes, 2 );
	// TODO: retc;
	if( retc == 0 ) return NULL;

TryTarget:
	type = DaoValue_GetType( self->xCinValue.value, proc->vmSpace );
	if( type == NULL ) type = self->xCinValue.cintype->target;
	if( type != NULL && type->core != NULL && type->core->DoBinary != NULL ){
		DaoValue *args2[2];
		args2[0] = args[0] == self ? self->xCinValue.value : args[0];
		args2[1] = args[1] == self ? self->xCinValue.value : args[1];
		return type->core->DoBinary( self->xCinValue.value, op, args2, proc );
	}
	return NULL;
}
Exemplo n.º 3
0
DaoValue* DaoObject_DoBinary( DaoValue *self, DaoVmCode *op, DaoValue *args[2], DaoProcess *proc )
{
	DaoClass *host = proc->activeObject ? proc->activeObject->defClass : NULL;
	DaoRoutine *rout = NULL;
	DaoValue *selfvalue = NULL;
	DaoType *argtypes[2];

	switch( op->code ){
	case DVM_ADD : case DVM_SUB :
	case DVM_MUL : case DVM_DIV :
	case DVM_MOD : case DVM_POW :
	case DVM_BITAND : case DVM_BITOR  : case DVM_BITXOR :
	case DVM_BITLFT : case DVM_BITRIT :
	case DVM_AND : case DVM_OR :
	case DVM_LT  : case DVM_LE :
	case DVM_EQ  : case DVM_NE :
	case DVM_IN :
		break;
	default: return NULL;
	}

	argtypes[0] = proc->activeTypes[ op->a ];
	argtypes[1] = proc->activeTypes[ op->b ];

	if( op->c == op->a ){
		const char *name = DaoVmCode_GetCompoundOperator( op->code );
		rout = DaoClass_FindMethod( self->xObject.defClass, name, host );
		if( rout != NULL ){
			DaoProcess_PushCallWithTypes( proc, rout, self, args+1, argtypes + 1, 1 );
			return NULL;
		}
	}

	rout = DaoClass_FindMethod( self->xObject.defClass, DaoVmCode_GetOperator( op->code ), host );
	if( rout == NULL ){
		switch( op->code ){
		case DVM_EQ : DaoProcess_PutBoolean( proc, args[0] == args[1] ); break;
		case DVM_NE : DaoProcess_PutBoolean( proc, args[0] != args[1] ); break;
		default: break;
		}
		return NULL;
	}

	if( op->c == op->a && self == args[0] ) selfvalue = self;
	if( op->c == op->b && self == args[1] ) selfvalue = self;
	DaoProcess_PushCallWithTypes( proc, rout, selfvalue, args, argtypes, 2 );
	// TODO: retc;
	return NULL;
}
Exemplo n.º 4
0
DaoValue* DaoObject_DoUnary( DaoValue *self, DaoVmCode *op, DaoProcess *proc )
{
	DaoClass *host = proc->activeObject ? proc->activeObject->defClass : NULL;
	DaoType *argtype = proc->activeTypes[op->a];;
	DaoRoutine *rout = NULL;
	int retc = 0;

	switch( op->code ){
	case DVM_NOT   :
	case DVM_MINUS :
	case DVM_TILDE :
	case DVM_SIZE  : break;
	default: return NULL;
	}
	rout = DaoClass_FindMethod( self->xObject.defClass, DaoVmCode_GetOperator( op->code ), host );
	if( rout == NULL ) return NULL;
	if( op->c == op->a ){
		retc = DaoProcess_PushCallWithTypes( proc, rout, self, & self, & argtype, 1 );
	}else{
		retc = DaoProcess_PushCallWithTypes( proc, rout, NULL, & self, & argtype, 1 );
	}
	// TODO: retc;
	return NULL;
}