Exemplo n.º 1
0
int DaoClass_UseMixinDecorators( DaoClass *self )
{
	int bl = 1;
#ifdef DAO_WITH_DECORATOR
	daoint i, j, k;
	DaoObject object = *(DaoObject*) self->objType->value;
	DaoObject *obj = & object;

	/*
	// Apply the decorators from mixins only to the methods defined in this class.
	// Two reasons for doing this:
	// 1. Mixins are only presented once in the current class, so when the mixins
	//    are composed of mixins, they are flatten in the current class.
	//    The order in which they are arranged in the current class is not obvious,
	//    if the decorators are allowed to decorate the methods from mixins, the
	//    result may be quite confusing;
	// 2. If the methods from mixins are allowed to be decorated, such decoration
	//    will not be written to bytecode file. Because when a class is written
	//    to a bytecode file, only its own data are encoded and saved (this is
	//    necessary to properly handle module loading). As a result, when a class
	//    is loaded from a bytecode file, it will obtain an un-decorated version
	//    of the methods from the mixins.
	*/
	for(j=self->cstMixinEnd-1; j>=self->cstMixinStart; --j){
		DaoRoutine *deco = (DaoRoutine*) self->constants->items.pConst[j]->value;
		DString *decoName = deco->routName;

		if( deco->type != DAO_ROUTINE || deco->body == NULL ) continue;
		if( !(deco->attribs & DAO_ROUT_DECORATOR) ) continue; /* Not a decorator; */
		if( deco->body->decoTargets == NULL || deco->body->decoTargets->size == 0 ) continue;

		for(k=self->cstParentEnd; k<self->constants->size; ++k){
			DaoValue *cst = self->constants->items.pConst[k]->value;
			DaoRoutine *rout = (DaoRoutine*) cst;
			DaoRoutine *deco2;

			if( rout->type != DAO_ROUTINE || rout->body == NULL ) continue;
			if( rout->routHost != self->objType ) continue;

			deco2 = DaoRoutine_Resolve( deco, (DaoValue*) obj, & cst, 1 );
			if( deco2 == NULL ) continue;
			if( DArray_MatchAffix( deco2->body->decoTargets, rout->routName ) == 0 ) continue;
			bl = bl && DaoRoutine_Decorate( rout, deco2, & cst, 1, 1 ) != NULL;
		}
	}
#endif
	return bl;
}
Exemplo n.º 2
0
void DaoCstruct_CallMethod( DaoCstruct *cdata, const char *method )
{
	DaoObject *obj = NULL;
	DaoRoutine *rout = Dao_Get_Object_Method( cdata, & obj, method );
	DaoValue *render = (DaoValue*) daox_current_renderer;
	DaoProcess *proc;

	if( rout == NULL || obj == NULL ) return;
	proc = DaoVmSpace_AcquireProcess( __daoVmSpace );

	rout = DaoRoutine_Resolve( rout, (DaoValue*) obj, NULL, & render, NULL, 1, 0 );
	if( rout == NULL ) goto Finalize;
	DaoProcess_Call( proc, rout, (DaoValue*) obj, & render, 1 );
Finalize:
	DaoVmSpace_ReleaseProcess( __daoVmSpace, proc );
}
Exemplo n.º 3
0
DaoCstruct* DaoxResource_CallMethod( DaoxResource *self, const char *method, DaoType *ctype )
{
	DaoValue *res = NULL;
	DaoObject *obj = NULL;
	DaoRoutine *rout = Dao_Get_Object_Method( (DaoCstruct*) self, & obj, method );
	DaoProcess *proc;

	if( rout == NULL || obj == NULL ) return NULL;
	proc = DaoVmSpace_AcquireProcess( dao_vmspace_graphics );

	rout = DaoRoutine_Resolve( rout, (DaoValue*) obj, NULL, NULL, NULL, 0, 0 );
	if( rout == NULL ) goto Finalize;
	DaoProcess_Call( proc, rout, (DaoValue*) obj, NULL, 0 );
	res = DaoProcess_GetReturned( proc );
	if( res == NULL || res->type != DAO_OBJECT ) return NULL;
	return DaoObject_CastCstruct( (DaoObject*)res, ctype );
Finalize:
	DaoVmSpace_ReleaseProcess( dao_vmspace_graphics, proc );
	return NULL;
}
Exemplo n.º 4
0
int DaoCstruct_CallKeyboardMethod( DaoCstruct *cdata, const char *method, int key, int x, int y )
{
	DaoObject *obj = NULL;
	DaoRoutine *rout = Dao_Get_Object_Method( cdata, & obj, method );
	DaoProcess *proc;
	DaoValue **params;

	if( rout == NULL || obj == NULL ) return 0;
	proc = DaoVmSpace_AcquireProcess( __daoVmSpace );

	DaoProcess_NewInteger( proc, (daoint) key );
	DaoProcess_NewInteger( proc, (daoint) x );
	DaoProcess_NewInteger( proc, (daoint) y );
	params = DaoProcess_GetLastValues( proc, 3 );
	rout = DaoRoutine_Resolve( rout, (DaoValue*) obj, NULL, params, NULL, 3, 0 );
	if( rout == NULL ) goto Finalize;
	DaoProcess_Call( proc, rout, (DaoValue*) obj, params, 3 );
Finalize:
	DaoVmSpace_ReleaseProcess( __daoVmSpace, proc );
	return rout != NULL;
}
Exemplo n.º 5
0
static void COROUT_Start( DaoProcess *proc, DaoValue *par[], int N )
{
	DaoxCoroutine *self = (DaoxCoroutine*) par[0];
	DaoValue *params[DAO_MAX_PARAM];
	DaoValue *val = par[1];
	DaoProcess *vmProc;
	DaoRoutine *rout;
	int i, passed = 0;
	if( val == NULL || val->type != DAO_ROUTINE ){
		DaoProcess_RaiseError( proc, "Type", NULL );
		return;
	}
	params[0] = par[0];
	memcpy( params + 1, par + 2, (N-2)*sizeof(DaoValue*) );
	rout = DaoRoutine_Resolve( (DaoRoutine*)val, NULL, NULL, params, NULL, N-1, DVM_CALL );
	if( rout ) rout = DaoProcess_PassParams( proc, rout, NULL, NULL, params, NULL, N-1, DVM_CALL );
	if( rout == NULL || rout->body == NULL ){
		DaoProcess_RaiseError( proc, "Param", "not matched" );
		return;
	}
	if( self->process == NULL ){
		self->process = DaoProcess_New( proc->vmSpace );
		GC_IncRC( self->process );
	}
	vmProc = self->process;
	DaoProcess_PushRoutine( vmProc, rout, NULL );
	vmProc->activeValues = vmProc->stackValues + vmProc->topFrame->stackBase;
	for(i=0; i<rout->parCount; i++){
		vmProc->activeValues[i] = proc->paramValues[i];
		GC_IncRC( vmProc->activeValues[i] );
	}
	vmProc->status = DAO_PROCESS_SUSPENDED;
	vmProc->pauseType = DAO_PAUSE_COROUTINE_YIELD;
	DaoProcess_Start( vmProc );
	DaoProcess_PutValue( proc, vmProc->stackValues[0] );
	if( vmProc->status == DAO_PROCESS_ABORTED )
		DaoProcess_RaiseError( proc, NULL, "coroutine execution is aborted." );
}