DaoString* DaoProcess_NewMBString( DaoProcess *self, const char *s, daoint n ) { DaoString *res = DaoString_New(1); if( s ) DString_SetDataMBS( res->data, s, n ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoString* DaoProcess_NewWCString( DaoProcess *self, const wchar_t *s, daoint n ) { DaoString *res = DaoString_New(0); if( s ) DString_SetDataWCS( res->data, s, n ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewVectorF( DaoProcess *self, float *s, daoint n ) { DaoArray *res = DaoArray_New( DAO_FLOAT ); if( s ) DaoArray_SetVectorF( res, s, n ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewVectorI( DaoProcess *self, daoint *s, daoint n ) { DaoArray *res = DaoArray_New( DAO_INTEGER ); if( s ) DaoArray_SetVectorI( res, s, n ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewMatrixI( DaoProcess *self, daoint **s, daoint n, daoint m ) { DaoArray *res = DaoArray_New( DAO_INTEGER ); if( s ) DaoArray_SetMatrixI( res, s, n, m ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewVectorD( DaoProcess *self, double *s, daoint n ) { DaoArray *res = DaoArray_New( DAO_DOUBLE ); if( s ) DaoArray_SetVectorD( res, s, n ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewMatrixD( DaoProcess *self, double **s, daoint n, daoint m ) { DaoArray *res = DaoArray_New( DAO_DOUBLE ); if( s ) DaoArray_SetMatrixD( res, s, n, m ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewMatrixF( DaoProcess *self, float **s, daoint n, daoint m ) { DaoArray *res = DaoArray_New( DAO_FLOAT ); if( s ) DaoArray_SetMatrixF( res, s, n, m ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewBuffer( DaoProcess *self, void *p, daoint n ) { DaoArray *res = DaoArray_New(0); DaoArray_SetBuffer( res, p, n ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoStream* DaoProcess_NewStream( DaoProcess *self, FILE *f ) { DaoStream *res = DaoStream_New(); DaoStream_SetFile( res, f ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
/* // Note: reference count is not handled for "self"! // But it is cached in the DaoProcess object, so no need to handle it by user! */ int DaoValue_Deserialize( DaoValue **self, DString *serial, DaoNamespace *ns, DaoProcess *proc ) { DaoParser *parser = DaoParser_New(); DArray *types = DArray_New(0); DMap *omap = DMap_New(0,0); int rc; *self = NULL; parser->nameSpace = ns; parser->vmSpace = ns->vmSpace; DaoParser_LexCode( parser, DString_GetMBS( serial ), 0 ); if( parser->tokens->size == 0 ) goto Failed; DArray_PushFront( types, NULL ); rc = DaoParser_Deserialize( parser, 0, parser->tokens->size-1, self, types, ns, proc, omap ); if( *self ) DaoProcess_CacheValue( proc, *self ); DaoParser_Delete( parser ); DArray_Delete( types ); DMap_Delete( omap ); return rc; Failed: DaoParser_Delete( parser ); DArray_Delete( types ); DMap_Delete( omap ); return 0; }
DaoStream* DaoProcess_NewStream( DaoProcess *self, FILE *file ) { DaoFileStream *stream = DaoFileStream_New(); stream->file = file; stream->base.mode |= DAO_STREAM_WRITABLE | DAO_STREAM_READABLE; DaoFileStream_InitCallbacks( stream ); DaoProcess_CacheValue( self, (DaoValue*) stream ); return (DaoStream*) stream; }
static DaoObject* DaoClass_MakeObject( DaoClass *self, DaoValue *param, DaoProcess *proc ) { DaoObject *object = DaoObject_New( self ); DaoProcess_CacheValue( proc, (DaoValue*) object ); if( DaoProcess_PushCallable( proc, self->classRoutines, (DaoValue*)object, & param, 1 ) ==0 ){ GC_ShiftRC( object, proc->topFrame->object ); proc->topFrame->object = object; proc->topFrame->returning = -1; if( DaoProcess_Execute( proc ) ) return object; } return NULL; }
DaoTuple* DaoProcess_NewTuple( DaoProcess *self, int count ) { int i, N = abs( count ); int M = self->factory->size; DaoValue **values = self->factory->items.pValue; DaoTuple *res = NULL; if( count < 0 ){ if( M < N ) return NULL; res = DaoTuple_New( N ); for(i=0; i<N; i++) DaoTuple_SetItem( res, values[M-N+i], i ); } if( res == NULL ) res = DaoTuple_New( N ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
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; }
DaoValue* DaoValue_Convert( DaoValue *self, DaoType *type, int copy, DaoProcess *proc ) { DaoTypeCore *core = DaoValue_GetTypeCore( self ); DaoValue *value = self; DaoType *at; if( type->tid & DAO_ANY ){ if( copy == 0 ) return value; at = DaoValue_GetType( value, proc->vmSpace ); at = DaoType_GetBaseType( at ); if( at == NULL ) return NULL; if( DaoType_IsImmutable( at ) ) return value; if( value->type >= DAO_ARRAY && value->type <= DAO_TUPLE ){ at = DaoNamespace_MakeInvarSliceType( proc->activeNamespace, at ); return DaoValue_CopyContainer( value, at ); }else if( core != NULL && core->Copy != NULL ){ return core->Copy( value, NULL ); } return NULL; }else if( type->tid == DAO_CINVALUE ){ DaoCinType *cintype = (DaoCinType*) type->aux; if( value->type == DAO_CINVALUE && value->xCinValue.cintype == cintype ) return value; if( value->type == DAO_CINVALUE && DaoType_MatchValue( type, value, NULL ) ) return value; at = DaoNamespace_GetType( proc->activeNamespace, value ); if( cintype->target == at || DaoType_MatchTo( cintype->target, at, NULL ) >= DAO_MT_CIV ){ proc->cinvalue.cintype = cintype; proc->cinvalue.value = value; return (DaoValue*) & proc->cinvalue; } return NULL; }else if( type->tid == DAO_INTERFACE ){ DaoInterface *inter = (DaoInterface*) type->aux; DaoRoutine *incompatible; if( type->aux == NULL ){ /* type "interface": */ if( value->type != DAO_INTERFACE ) return NULL; return value; } if( value->type == DAO_CINVALUE && DaoType_MatchValue( type, value, NULL ) ) return value; at = DaoNamespace_GetType( proc->activeNamespace, value ); if( inter->concretes ){ DaoCinType *cintype = DaoInterface_GetConcrete( inter, at ); if( cintype ){ proc->cinvalue.cintype = cintype; proc->cinvalue.value = value; return (DaoValue*) & proc->cinvalue; } } switch( value->type ){ case DAO_OBJECT : value = (DaoValue*) value->xObject.rootObject; at = value->xObject.defClass->objType; break; case DAO_CSTRUCT : case DAO_CDATA : if( value->xCstruct.object ){ value = (DaoValue*) value->xCstruct.object->rootObject; at = value->xObject.defClass->objType; } break; } /* Automatic binding when casted to an interface: */ incompatible = DaoInterface_BindTo( inter, at, NULL ); if( incompatible != NULL ){ DString *buffer = DString_New(); DString_AppendChars( buffer, "Interface method " ); DString_Append( buffer, inter->abtype->name ); DString_AppendChars( buffer, "::" ); DString_Append( buffer, incompatible->routName ); DString_AppendChars( buffer, "() is not available in the source type;" ); DaoProcess_DeferException( proc, "Error::Type", buffer->chars ); DString_Delete( buffer ); return NULL; } return value; }else if( type->tid == DAO_VARIANT ){ DaoType *best = NULL; int i, n, max = DAO_MT_NOT; for(i=0,n=type->args->size; i<n; i++){ DaoType *itype = type->args->items.pType[i]; int mt = DaoType_MatchValue( itype, self, NULL ); if( mt > max ){ best = itype; max = mt; } } if( best == NULL ) return NULL; return DaoValue_Convert( self, best, copy, proc ); } if( core == NULL || core->DoConversion == NULL ) return NULL; value = core->DoConversion( self, type, copy, proc ); if( value == NULL || value->type <= DAO_ENUM || copy == 0 ) return value; if( value == self /*|| DaoValue_ChildOf( value, self ) || DaoValue_ChildOf( self, value )*/ ){ // No way to determine inheritance relationship between wrapped C++ objects; if( value->type >= DAO_ARRAY && value->type <= DAO_TUPLE ){ DaoType *type = DaoValue_GetType( value, proc->vmSpace ); if( type == NULL ) return NULL; type = DaoNamespace_MakeInvarSliceType( proc->activeNamespace, type ); return DaoValue_CopyContainer( value, type ); } if( core == NULL || core->Copy == NULL ) return NULL; value = core->Copy( value, NULL ); /* Copy invariable value; */ if( value == NULL ) return NULL; DaoProcess_CacheValue( proc, value ); } return value; }
DaoCdata* DaoProcess_NewCdata( DaoProcess *self, DaoType *type, void *data, int owned ) { DaoCdata *res = owned ? DaoCdata_New( type, data ) : DaoCdata_Wrap( type, data ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoInteger* DaoProcess_NewInteger( DaoProcess *self, daoint v ) { DaoInteger *res = DaoInteger_New( v ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoNone* DaoProcess_NewNone( DaoProcess *self ) { DaoNone *res = DaoNone_New(); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoDouble* DaoProcess_NewDouble( DaoProcess *self, double v ) { DaoDouble *res = DaoDouble_New( v ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoFloat* DaoProcess_NewFloat( DaoProcess *self, float v ) { DaoFloat *res = DaoFloat_New( v ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoLong* DaoProcess_NewLong( DaoProcess *self ) { DaoLong *res = DaoLong_New(); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoComplex* DaoProcess_NewComplex( DaoProcess *self, complex16 v ) { DaoComplex *res = DaoComplex_New( v ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoString* DaoProcess_NewString( DaoProcess *self, int mbs ) { DaoString *res = DaoString_New( mbs ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoArray* DaoProcess_NewArray( DaoProcess *self, int type ) { DaoArray *res = DaoArray_New( type ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoMap* DaoProcess_NewMap( DaoProcess *self, unsigned int hashing ) { DaoMap *res = DaoMap_New( hashing ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoList* DaoProcess_NewList( DaoProcess *self ) { DaoList *res = DaoList_New(); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }
DaoEnum* DaoProcess_NewEnum( DaoProcess *self, DaoType *type, int value ) { DaoEnum *res = DaoEnum_New( type, value ); DaoProcess_CacheValue( self, (DaoValue*) res ); return res; }