static void STD_Load( DaoProcess *proc, DaoValue *p[], int N ) { DString *name = p[0]->xString.data; int import = p[1]->xInteger.value; int runim = p[2]->xInteger.value; int safe = p[3]->xInteger.value; int wasProt = 0; int res = 0; DaoVmSpace *vms = proc->vmSpace; DaoNamespace *ns; DString_ToMBS( name ); if( safe ) vms->options |= DAO_OPTION_SAFE; if( vms->options & DAO_OPTION_SAFE ) wasProt = 1; DArray_PushFront( vms->pathLoading, proc->activeNamespace->path ); ns = DaoVmSpace_LoadEx( vms, DString_GetMBS( name ), runim ); DaoProcess_PutValue( proc, (DaoValue*) ns ); if( ! wasProt ) vms->options &= ~DAO_OPTION_SAFE; if( ns ){ /* in the case that it is cancelled from console */ DArray_PushFront( vms->pathLoading, ns->path ); res = DaoProcess_Call( proc, ns->mainRoutine, NULL, NULL, 0 ); if( proc->stopit | vms->stopit ){ DaoProcess_RaiseException( proc, DAO_ERROR, "loading cancelled" ); }else if( res ){ DaoProcess_RaiseException( proc, res, "loading failed" ); } DArray_PopFront( vms->pathLoading ); }else{ DaoProcess_RaiseException( proc, DAO_ERROR, "loading failed" ); } DArray_PopFront( vms->pathLoading ); if( import && ns ) DaoNamespace_AddParent( proc->activeNamespace, ns ); }
static void TEST_Run( DaoProcess *proc, DaoValue* p[], int N ) { DString *prefix = p[0]->xString.value; DList *funcs = proc->activeNamespace->definedRoutines; DaoStream *out = DaoVmSpace_StdioStream( proc->vmSpace ); daoint i; char buf[100]; for ( i = 0; i < funcs->size; ++i ){ DaoRoutine *rout = funcs->items.pRoutine[i]; // find global routines matching prefix if ( strncmp( rout->routName->chars, prefix->chars, prefix->size ) == 0 ){ // ignore 'main()' if ( strcmp( rout->routName->chars, "main" ) == 0 ) continue; // run if ( !( rout->attribs & DAO_ROUT_DECORATOR ) && rout->parCount == 0 ){ if ( DaoProcess_Call( proc, rout, NULL, NULL, 0 ) == DAO_ERROR ){ // failed char buf[512]; snprintf( buf, sizeof(buf), "unexpected error running '%s'", rout->routName->chars ); DaoProcess_RaiseError( proc, "Error::Test", buf ); return; } } } } DMutex_Lock( &test_mtx ); snprintf( buf, sizeof(buf), "Summary: %i tests, %i passed, %i failed, %i skipped\n", test_count, pass_count, fail_count, skip_count ); DaoStream_WriteChars( out, buf ); test_count = pass_count = fail_count = skip_count = 0; DMutex_Unlock( &test_mtx ); }
static otto DaoPF10002( int *_cs, DaoMethod *_ro, DaoObject *_ob, const otto& value ) { DaoValue *_dp[1] = { NULL }; DaoValue *_res; DaoCdata *_cd; DaoProcess *_vmp; otto _test = 0; if( _ro == NULL ) goto EndCall; _dp[0] = DaoValue_WrapCdata( dao_otto_Typer, (void*) &value ); _ro = DaoMethod_Resolve( _ro, (DaoValue*)_ob, _dp, 1 ); if( DaoValue_CastRoutine( (DaoValue*)_ro ) == NULL ) goto EndCall; _vmp = DaoVmSpace_AcquireProcess( __daoVmSpace ); if( (*_cs = DaoProcess_Call( _vmp, _ro, (DaoValue*)_ob, _dp, 1 )) ==0 ) goto EndCall; _res = DaoProcess_GetReturned( _vmp ); DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp ); if( DaoValue_CastObject(_res) ) _res = (DaoValue*)DaoObject_MapCdata( (DaoObject*)_res, dao_otto_Typer ); if( DaoValue_CastCdata(_res) && DaoCdata_IsType( (DaoCdata*)_res, dao_otto_Typer ) ){ _test = *(otto*) DaoValue_TryCastCdata( _res, dao_otto_Typer ); } EndCall: DaoValue_ClearAll( _dp, 1 ); return _test; }
void DaoObject_Print( DaoValue *self, DaoStream *stream, DMap *cycmap, DaoProcess *proc ) { int ec = 0; char buf[50]; DMap *inmap = cycmap; DaoObject *object = (DaoObject*) self; DaoValue *params[2]; DaoRoutine *meth; sprintf( buf, "[%p]", object ); if( self == object->defClass->objType->value ){ DaoStream_WriteString( stream, object->defClass->className ); DaoStream_WriteChars( stream, "[null]" ); return; } if( cycmap != NULL && DMap_Find( cycmap, object ) != NULL ){ DaoStream_WriteString( stream, object->defClass->className ); DaoStream_WriteChars( stream, buf ); return; } if( cycmap == NULL ) cycmap = DHash_New(0,0); DMap_Insert( cycmap, self, self ); DaoValue_Clear( & proc->stackValues[0] ); params[0] = (DaoValue*) dao_type_string; params[1] = (DaoValue*) stream; meth = DaoClass_FindMethod( object->defClass, "(string)", NULL ); if( meth ){ ec = DaoProcess_Call( proc, meth, self, params, 2 ); if( ec ) ec = DaoProcess_Call( proc, meth, self, params, 1 ); }else{ meth = DaoClass_FindMethod( object->defClass, "serialize", NULL ); if( meth ) ec = DaoProcess_Call( proc, meth, self, NULL, 0 ); } if( ec ){ DaoProcess_RaiseException( proc, daoExceptionNames[ec], proc->string->chars, NULL ); }else if( meth && proc->stackValues[0] ){ DaoValue_Print( proc->stackValues[0], stream, cycmap, proc ); }else{ DaoStream_WriteString( stream, object->defClass->className ); DaoStream_WriteChars( stream, buf ); } if( inmap == NULL ) DMap_Delete( cycmap ); }
static void DaoPF10001( int *_cs, DaoMethod *_ro, DaoObject *_ob ) { if( _ro == NULL ) return; _ro = DaoMethod_Resolve( _ro, (DaoValue*)_ob, NULL, 0 ); if( DaoValue_CastRoutine( (DaoValue*)_ro ) == NULL ) return; DaoProcess *_vmp = DaoVmSpace_AcquireProcess( __daoVmSpace ); *_cs = DaoProcess_Call( _vmp, _ro, (DaoValue*)_ob, NULL, 0 ); DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp ); }
static int DaoCdata_Serialize( DaoCdata *self, DString *serial, DaoNamespace *ns, DaoProcess *proc, DString *buf, DMap *omap ) { DaoType *type; DaoRoutine *meth = DaoType_FindFunctionMBS( self->ctype, "serialize" ); if( meth == NULL ) return 0; if( DaoProcess_Call( proc, meth, (DaoValue*)self, NULL, 0 ) ) return 0; type = DaoNamespace_GetType( ns, proc->stackValues[0] ); DaoValue_Serialize2( proc->stackValues[0], serial, ns, proc, type, buf, omap ); return 1; }
static void DaoObject_Print( DaoValue *self0, DaoProcess *proc, DaoStream *stream, DMap *cycData ) { int ec = 0; char buf[50]; DaoObject *self = & self0->xObject; DaoValue *params[2]; DaoRoutine *meth; sprintf( buf, "[%p]", self ); if( self0 == self->defClass->objType->value ){ DaoStream_WriteString( stream, self->defClass->className ); DaoStream_WriteChars( stream, "[null]" ); return; } if( cycData != NULL && DMap_Find( cycData, self ) != NULL ){ DaoStream_WriteString( stream, self->defClass->className ); DaoStream_WriteChars( stream, buf ); return; } if( cycData ) MAP_Insert( cycData, self, self ); DaoValue_Clear( & proc->stackValues[0] ); params[0] = (DaoValue*) dao_type_string; params[1] = (DaoValue*) stream; meth = DaoClass_FindMethod( self->defClass, "(string)", NULL ); if( meth ){ ec = DaoProcess_Call( proc, meth, self0, params, 2 ); if( ec ) ec = DaoProcess_Call( proc, meth, self0, params, 1 ); }else{ meth = DaoClass_FindMethod( self->defClass, "serialize", NULL ); if( meth ) ec = DaoProcess_Call( proc, meth, self0, NULL, 0 ); } if( ec ){ DaoProcess_RaiseException( proc, daoExceptionNames[ec], proc->string->chars, NULL ); }else if( meth && proc->stackValues[0] ){ DaoValue_Print( proc->stackValues[0], proc, stream, cycData ); }else{ DaoStream_WriteString( stream, self->defClass->className ); DaoStream_WriteChars( stream, buf ); } }
void DaoCxxVirt_otto::vtest( int &_cs ) { DaoObject *_obj = NULL; DaoMethod *_ro = Dao_Get_Object_Method( cdata, & _obj, "vtest" ); if( _ro == NULL || _obj == NULL ) return; _ro = DaoMethod_Resolve( _ro, (DaoValue*)_obj, NULL, 0 ); if( DaoValue_CastRoutine( (DaoValue*)_ro ) == NULL ) return; DaoProcess *_vmp = DaoVmSpace_AcquireProcess( __daoVmSpace ); DaoProcess_Call( _vmp, _ro, (DaoValue*)_obj, NULL, 0 ); DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp ); }
static void DaoCinValue_Print( DaoValue *self, DaoStream *stream, DMap *cycmap, DaoProcess *proc ) { int ec = 0; char buf[50]; DaoRoutine *meth; DaoValue *args[2]; DaoType *type = self->xCinValue.cintype->vatype; DMap *inmap = cycmap; if( cycmap != NULL && DMap_Find( cycmap, self ) != NULL ){ sprintf( buf, "[%p]", self ); DaoStream_WriteString( stream, type->name ); DaoStream_WriteChars( stream, buf ); return; } if( cycmap == NULL ) cycmap = DHash_New(0,0); DMap_Insert( cycmap, self, self ); args[0] = (DaoValue*) proc->vmSpace->typeString; args[1] = (DaoValue*) stream; meth = DaoType_FindFunctionChars( type, "(string)" ); if( meth ){ ec = DaoProcess_Call( proc, meth, self, args, 2 ); if( ec ) ec = DaoProcess_Call( proc, meth, self, args, 1 ); }else{ meth = DaoType_FindFunctionChars( type, "serialize" ); if( meth ) ec = DaoProcess_Call( proc, meth, self, NULL, 0 ); } if( meth == NULL ){ DaoValue_Print( self->xCinValue.value, stream, cycmap, proc ); }else if( ec ){ DaoProcess_RaiseException( proc, daoExceptionNames[ec], proc->string->chars, NULL ); }else if( meth && proc->stackValues[0] ){ DaoValue_Print( proc->stackValues[0], stream, cycmap, proc ); }else{ DaoStream_WriteString( stream, type->name ); DaoStream_WriteChars( stream, buf ); } if( inmap == NULL ) DMap_Delete( cycmap ); }
static int DaoObject_Serialize( DaoObject *self, DString *serial, DaoNamespace *ns, DaoProcess *proc, DString *buf, DMap *omap ) { DaoType *type; DaoValue *value = NULL; DaoValue *selfpar = (DaoValue*) self; DString name = DString_WrapMBS( "serialize" ); int errcode = DaoObject_GetData( self, & name, & value, NULL ); if( errcode || value == NULL || value->type != DAO_ROUTINE ) return 0; if( DaoProcess_Call( proc, (DaoRoutine*)value, selfpar, NULL, 0 ) ) return 0; type = DaoNamespace_GetType( ns, proc->stackValues[0] ); DaoValue_Serialize2( proc->stackValues[0], serial, ns, proc, type, buf, omap ); return 1; }
static void DaoPF10004( int *_cs, DaoMethod *_ro, DaoObject *_ob, const Greeting& g ) { DaoValue *_dp[1] = { NULL }; if( _ro == NULL ) return; _dp[0] = DaoValue_WrapCdata( dao_Greeting_Typer, (void*) &g ); _ro = DaoMethod_Resolve( _ro, (DaoValue*)_ob, _dp, 1 ); if( DaoValue_CastRoutine( (DaoValue*)_ro ) == NULL ) return; DaoProcess *_vmp = DaoVmSpace_AcquireProcess( __daoVmSpace ); *_cs = DaoProcess_Call( _vmp, _ro, (DaoValue*)_ob, _dp, 1 ); DaoVmSpace_ReleaseProcess( __daoVmSpace, _vmp ); DaoValue_ClearAll( _dp, 1 ); }
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 ); }
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; }
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; }
static int DaoPF10293( int *_cs, DaoRoutine *_ro, DaoObject *_ob, double t, const double* y, double* dydt, DaoValue *params ) { DaoProcess *_proc = DaoVmSpace_AcquireProcess( __daoVmSpace ); DaoValue *_res, **_dp; DaoCdata *_cd; int X = (int) 0; if( _ro == NULL ) goto EndCall; DaoProcess_NewFloat( _proc, (dao_float) t ); DaoProcess_NewVectorFloat64( _proc, (double*) y, 0 ); DaoProcess_NewVectorFloat64( _proc, (double*) dydt, 0 ); DaoProcess_CacheValue( _proc, params ); _dp = DaoProcess_GetLastValues( _proc, 4 ); _ro = DaoRoutine_ResolveByValue( _ro, (DaoValue*) _ob, _dp, 4 ); if( _ro == NULL || DaoRoutine_IsWrapper( _ro ) ) goto EndCall; if( (*_cs = DaoProcess_Call( _proc, _ro, (DaoValue*)_ob, _dp, 4 )) ) goto EndCall; _res = DaoProcess_GetReturned( _proc ); if(DaoValue_CastInteger(_res)) X=(int)DaoValue_TryGetInteger(_res); EndCall: DaoVmSpace_ReleaseProcess( __daoVmSpace, _proc ); return X; }