/* modules/debugger */ DAO_DLL void Dao_AboutVar( DaoProcess *proc, DaoType *type, DaoValue *var, DString *str ) { DaoType *abtp = DaoNamespace_GetType( proc->activeNamespace, var ); char buf[50]; if( abtp ){ if( var->type == DAO_ROUTINE ){ DString_Append( str, var->xRoutine.routName ); DString_AppendChars( str, "{" ); DString_Append( str, abtp->name ); DString_AppendChars( str, "}" ); }else{ DString_Append( str, abtp->name ); } sprintf( buf, "[%p]", var ); DString_AppendChars( str, buf ); if( var->type == DAO_CDATA ){ sprintf( buf, "(%p)", var->xCdata.data ); DString_AppendChars( str, buf ); } }else{ DString_AppendChars( str, "none[0x0]" ); } if( type ){ DString_AppendChars( str, ":" ); DString_Append( str, type->name ); } }
static void DMap_SortMethods( DMap *hash, DList *methods ) { DMap *map = DMap_New( DAO_DATA_STRING, 0 ); DString *name = DString_New(); DNode *it; daoint i, n; for(it=DMap_First(hash); it; it=DMap_Next(hash,it)){ if( it->value.pRoutine->overloads ){ DRoutines *one = it->value.pRoutine->overloads; for(i=0,n=one->routines->size; i<n; i++){ DaoRoutine *rout = one->routines->items.pRoutine[i]; DString_Assign( name, rout->routName ); DString_AppendChars( name, " " ); DString_Append( name, rout->routType->name ); DMap_Insert( map, name, (void*)rout ); } }else{ DaoRoutine *rout = it->value.pRoutine; DString_Assign( name, rout->routName ); DString_AppendChars( name, " " ); DString_Append( name, rout->routType->name ); DMap_Insert( map, name, (void*)rout ); } } DList_Clear( methods ); for(it=DMap_First(map); it; it=DMap_Next(map,it)) DList_Append( methods, it->value.pVoid ); DMap_Delete( map ); DString_Delete( name ); }
DaoCinType* DaoCinType_New( DaoInterface *inter, DaoType *target ) { DaoCinType *self = (DaoCinType*) dao_calloc( 1, sizeof(DaoCinType) ); DaoValue_Init( self, DAO_CINTYPE ); self->trait |= DAO_VALUE_DELAYGC; self->derived = 0; self->supers = DList_New( DAO_DATA_VALUE ); self->methods = DHash_New( DAO_DATA_STRING, DAO_DATA_VALUE ); self->citype = DaoType_New( "interface<", DAO_CINTYPE, (DaoValue*)self, NULL ); self->vatype = DaoType_New( inter->abtype->name->chars, DAO_CINVALUE, (DaoValue*)self, NULL ); self->abstract = inter; self->target = target; GC_IncRC( self->citype ); GC_IncRC( self->vatype ); GC_IncRC( self->abstract ); GC_IncRC( self->target ); self->citype->nested = DList_New( DAO_DATA_VALUE ); self->vatype->nested = DList_New( DAO_DATA_VALUE ); DList_Append( self->citype->nested, target ); DList_Append( self->vatype->nested, target ); DString_AppendChar( self->vatype->name, '<' ); DString_Append( self->vatype->name, target->name ); DString_AppendChar( self->vatype->name, '>' ); DString_Append( self->citype->name, self->vatype->name ); DString_AppendChar( self->citype->name, '>' ); #ifdef DAO_USE_GC_LOGGER DaoObjectLogger_LogNew( (DaoValue*) self ); #endif return self; }
void DaoClass_SetName( DaoClass *self, DString *name, DaoNamespace *ns ) { DaoRoutine *rout; DString *str; if( self->classRoutine ) return; self->inter = DaoInterface_New( ns, name->mbs ); DString_SetMBS( self->inter->abtype->name, "interface<" ); DString_Append( self->inter->abtype->name, name ); DString_AppendChar( self->inter->abtype->name, '>' ); DaoClass_AddReference( self, self->inter ); self->objType = DaoType_New( name->mbs, DAO_OBJECT, (DaoValue*)self, NULL ); self->clsType = DaoType_New( name->mbs, DAO_CLASS, (DaoValue*) self, NULL ); GC_IncRC( self->clsType ); DString_InsertMBS( self->clsType->name, "class<", 0, 0, 0 ); DString_AppendChar( self->clsType->name, '>' ); str = DString_New(1); DString_SetMBS( str, "self" ); DaoClass_AddObjectVar( self, str, NULL, self->objType, DAO_DATA_PRIVATE ); DString_Assign( self->className, name ); DaoClass_AddType( self, name, self->objType ); rout = DaoRoutine_New( ns, self->objType, 1 ); DString_Assign( rout->routName, name ); DString_AppendMBS( rout->routName, "::" ); DString_Append( rout->routName, name ); self->classRoutine = rout; /* XXX class<name> */ GC_IncRC( rout ); rout->routType = DaoType_New( "routine<=>", DAO_ROUTINE, (DaoValue*)self->objType, NULL ); DString_Append( rout->routType->name, name ); DString_AppendMBS( rout->routType->name, ">" ); GC_IncRC( rout->routType ); rout->attribs |= DAO_ROUT_INITOR; DaoClass_AddConst( self, name, (DaoValue*) self, DAO_DATA_PUBLIC ); self->classRoutines = DaoRoutines_New( ns, self->objType, NULL ); DString_Assign( self->classRoutines->routName, name ); DaoClass_AddConst( self, rout->routName, (DaoValue*)self->classRoutines, DAO_DATA_PUBLIC ); self->objType->value = (DaoValue*) DaoObject_Allocate( self, 0 ); self->objType->value->xObject.trait |= DAO_VALUE_CONST|DAO_VALUE_NOCOPY; self->objType->value->xObject.isDefault = 1; GC_IncRC( self->objType->value ); DString_SetMBS( str, "default" ); DaoClass_AddConst( self, str, self->objType->value, DAO_DATA_PUBLIC ); DString_Delete( str ); }
int DaoRegex_ChangeExt( DaoRegex *self, DString *input, DString *output, DString *target, int index, daoint *start2, daoint *end2 ) { daoint start = start2 ? (daoint) *start2 : 0; daoint end = end2 ? (daoint) *end2 : 0; daoint i, n=0, p1=start, p2=end, p3, last; DaoValue *value = NULL; DaoString matched = {DAO_STRING,0,0,0,0,NULL}; DList *array = DList_New( DAO_DATA_VALUE ); DString *tmp = DString_New(); DString *tmp2 = DString_New(); DString_Reset( output, 0 ); if( self == NULL || input->size == 0 ) goto DoNothing; matched.value = tmp; Dao_ParseTarget( target, array, (DaoValue*) & matched ); if( end == 0 ) end = p2 = DString_Size( input ); n = last = 0; while( DaoRegex_Match( self, input, & p1, & p2 ) ){ n += 1; if( index ==0 || n == index ){ DString_SubString( input, tmp2, last, p1 - last ); DString_Append( output, tmp2 ); DString_Clear( tmp ); for(i=0; i<array->size; i++){ value = array->items.pValue[i]; if( value->type == DAO_INTEGER ){ if( DaoRegex_SubMatch( self, value->xInteger.value, & p1, & p3 ) ){ DString_SubString( input, tmp2, p1, p3 - p1 ); DString_Append( tmp, tmp2 ); } }else{ DString_Append( tmp, value->xString.value ); } } DString_Append( output, tmp ); last = p2; } if( start2 ) *start2 = p1; if( end2 ) *end2 = p2; p1 = p2; p2 = end; if( index && n == index ) break; } DString_SubString( input, tmp2, last, end - last ); DString_Append( output, tmp2 ); DoNothing: DString_Delete( tmp ); DString_Delete( tmp2 ); DList_Delete( array ); return n; }
void DaoRoutine_MakeName( DaoRoutine *self, DString *name, int max1, int max2, int max3 ) { DString *hostName = self->routHost ? self->routHost->name : NULL; DaoType *routType = self->routType; int M = (routType->attrib & DAO_TYPE_SELF) != 0; int N = routType->nested->size; int i; DString_Reset( name, 0 ); /* For builtin containers, whose methods may have no routHost set: */ if( hostName == NULL && M ) hostName = routType->nested->items.pType[0]->aux->xType.name; /* // Mixin classes have methods converted from constructors of component classes. // These methods still have the DAO_ROUT_INITOR flag. So checking the names is // the better way to use here. */ if( hostName && ! DString_EQ( self->routName, hostName ) ){ if( hostName->size + self->routName->size < (max1-2) ){ DString_Append( name, hostName ); DString_AppendChars( name, "::" ); DString_Append( name, self->routName ); }else{ DString_PartialAppend( name, hostName, max1/2-1 ); DString_AppendChars( name, "::" ); DString_PartialAppend( name, self->routName, max1/2-1 ); } }else{ DString_PartialAppend( name, self->routName, max1 ); } if( max3 == 0 ){ DString_AppendChars( name, "()" ); return; } DString_AppendChars( name, "( " ); if( N == M+1 ){ DaoType *type = routType->nested->items.pType[M]; DString_PartialAppend( name, type->name, 2*max2 ); }else{ for(i=M; i<N; ++i){ DaoType *type = routType->nested->items.pType[i]; if( i > M ) DString_AppendChars( name, ", " ); if( i < M + max3 ){ DString_PartialAppend( name, type->name, max2 ); }else{ DString_AppendChars( name, "~~" ); break; } } } DString_AppendChars( name, " )" ); }
static int DaoObject_DoSetField( DaoValue *self, DaoString *name, DaoValue *value, DaoProcess *proc ) { DaoObject *object = (DaoObject*) self; DaoObject *host = proc->activeObject; DaoClass *hostClass = host ? host->defClass : NULL; int ec = DaoObject_SetData( object, name->value, value, host ); if( ec != DAO_OK ){ DString *field = proc->string; DaoRoutine *rout; DString_SetChars( field, "." ); DString_Append( field, name->value ); DString_AppendChars( field, "=" ); rout = DaoClass_FindMethod( object->defClass, field->chars, hostClass ); if( rout != NULL ){ ec = DaoProcess_PushCall( proc, rout, self, & value, 1 ); }else{ DaoValue *args[2]; args[0] = (DaoValue*) name; args[1] = value; rout = DaoClass_FindMethod( object->defClass, ".=", hostClass ); if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT; ec = DaoProcess_PushCall( proc, rout, self, args, 2 ); } if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT; } if( ec ) DaoProcess_RaiseError( proc, daoExceptionNames[ec], name->value->chars ); return ec; }
static DaoValue* DaoObject_DoGetField( DaoValue *self, DaoString *name, DaoProcess *proc ) { DaoObject *object = (DaoObject*) self; DaoObject *host = proc->activeObject; DaoClass *hostClass = host ? host->defClass : NULL; DaoValue *value = NULL; int rc = DaoObject_GetData( object, name->value, & value, host ); if( rc ){ DaoRoutine *rout; DString *field = proc->string; DString_SetChars( field, "." ); DString_Append( field, name->value ); rout = DaoClass_FindMethod( object->defClass, field->chars, hostClass ); if( rout != NULL ){ rc = DaoProcess_PushCall( proc, rout, self, NULL, 0 ); }else{ DaoValue *arg = (DaoValue*) name; rout = DaoClass_FindMethod( object->defClass, ".", hostClass ); if( rout != NULL ) rc = DaoProcess_PushCall( proc, rout, self, & arg, 1 ); } if( rout == NULL ) return NULL; }else{ DaoProcess_PutValue( proc, value ); } if( rc ) DaoProcess_RaiseError( proc, daoExceptionNames[rc], name->value->chars ); return NULL; }
void DaoxDataFrame_AddLabels( DaoxDataFrame *self, int dim, DMap *labels ) { DString *lab; DNode *it; if( labels->keytype != D_STRING && labels->keytype != D_VALUE ) return; if( labels->valtype != 0 && labels->valtype != D_VALUE ) return; lab = DString_New(1); DaoxDataFrame_AddLabelGroup( self, dim ); for(it=DMap_First(labels); it; it=DMap_Next(labels,it)){ DString *lab2 = it->key.pString; daoint idx = it->value.pInt; if( labels->keytype == D_VALUE ){ if( it->key.pValue->type != DAO_STRING ) continue; lab2 = it->key.pValue->xString.data; } if( labels->valtype == D_VALUE ){ if( it->value.pValue->type != DAO_INTEGER ) continue; idx = it->value.pValue->xInteger.value; } if( idx < 0 ) continue; DString_Reset( lab, 0 ); DString_Append( lab, lab2 ); DaoxDataFrame_AddLabel( self, dim, lab->mbs, idx ); } DString_Delete( lab ); }
static int DaoStringStream_Read( DaoStream *stream, DString *data, int count ) { DaoStringStream *self = (DaoStringStream*) stream; DString_Reset( data, 0 ); if( self->offset >= self->base.buffer->size ) return -1; if( count >= 0 ){ DString_SubString( self->base.buffer, data, self->offset, count ); self->offset += data->size; }else if( count == -1 ){ int delim = '\n'; daoint pos = DString_FindChar( self->base.buffer, delim, self->offset ); if( self->offset == 0 && (pos == DAO_NULLPOS || pos == self->base.buffer->size-1) ){ DString_Append( data, self->base.buffer ); self->offset = self->base.buffer->size; }else if( pos == DAO_NULLPOS ){ DString_SubString( self->base.buffer, data, pos, -1 ); self->offset = self->base.buffer->size; }else{ DString_SubString( self->base.buffer, data, pos, pos - self->offset + 1 ); self->offset = pos + 1; } if( self->base.mode & DAO_STREAM_AUTOCONV ) DString_ToUTF8( data ); return self->offset < self->base.buffer->size; }else{ if( self->offset == 0 ){ DString_Assign( data, self->base.buffer ); }else{ DString_SubString( self->base.buffer, data, self->offset, -1 ); } self->offset += data->size; } return data->size; }
DaoValue* DaoCinValue_DoConversion( DaoValue *self, DaoType *type, int copy, DaoProcess *proc ) { DaoCinType *cintype = self->xCinValue.cintype; DaoTypeCore *core; DaoRoutine *rout; DString *buffer; if( cintype->target == type ){ if( copy ) return DaoValue_Convert( self->xCinValue.value, type, copy, proc ); return self->xCinValue.value; }else if( DaoType_MatchTo( cintype->target, type, NULL ) >= DAO_MT_EQ ){ if( copy ) return DaoValue_Convert( self->xCinValue.value, type, copy, proc ); return self->xCinValue.value; } buffer = DString_NewChars( "(" ); DString_Append( buffer, type->name ); DString_AppendChars( buffer, ")" ); rout = DaoType_FindFunction( cintype->vatype, buffer ); DString_Delete( buffer ); if( rout != NULL ){ int rc = DaoProcess_PushCall( proc, rout, self, (DaoValue**) & type, 1 ); if( rc == 0 ) return NULL; } return DaoValue_Convert( self->xCinValue.value, type, copy, proc ); }
int DaoValue_CheckSetField( DaoType *self, DaoString *name, DaoType *value ) { DString *buffer = DString_NewChars( "." ); DaoRoutine *rout; DaoType *args[2]; DString_Append( buffer, name->value ); DString_AppendChars( buffer, "=" ); rout = DaoType_FindFunction( self, buffer ); DString_Delete( buffer ); if( rout != NULL ){ rout = DaoRoutine_MatchByType( rout, self, & value, 1, DVM_CALL ); if( rout == NULL ) return DAO_ERROR_VALUE; }else{ rout = DaoType_FindFunctionChars( self, ".=" ); if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT; args[0] = rout->nameSpace->vmSpace->typeString; args[1] = value; rout = DaoRoutine_MatchByType( rout, self, args, 2, DVM_CALL ); if( rout == NULL ) return DAO_ERROR_VALUE; } return DAO_OK; }
DaoType* DaoCinValue_CheckConversion( DaoType *self, DaoType *type, DaoRoutine *ctx ) { DaoCinType *cintype = (DaoCinType*) self->aux; DaoTypeCore *core; DaoRoutine *rout; DString *buffer; if( cintype->target == type ){ return type; }else if( DaoType_MatchTo( cintype->target, type, NULL ) >= DAO_MT_EQ ){ return type; } buffer = DString_NewChars( "(" ); DString_Append( buffer, type->name ); DString_AppendChars( buffer, ")" ); rout = DaoType_FindFunction( cintype->vatype, buffer ); DString_Delete( buffer ); if( rout != NULL ){ DaoType *ttype = DaoNamespace_GetType( ctx->nameSpace, (DaoValue*) type ); rout = DaoRoutine_MatchByType( rout, self, & ttype, 1, DVM_CALL ); if( rout ) return type; } core = cintype->target->core; if( core != NULL && core->CheckConversion ){ return core->CheckConversion( cintype->target, type, ctx ); } return NULL; }
static void DString_PartialAppend( DString *self, DString *other, int max ) { if( other->size > max ){ DString_AppendBytes( self, other->chars, max-1-!isalnum(other->chars[max-2]) ); DString_AppendChar( self, '~' ); }else{ DString_Append( self, other ); } }
DaoCinType* DaoCinType_New( DaoInterface *inter, DaoType *target ) { DaoCinType *self = (DaoCinType*) dao_calloc( 1, sizeof(DaoCinType) ); DaoNamespace *ns = inter->nameSpace; DString *name = inter->abtype->name; DaoValue_Init( self, DAO_CINTYPE ); self->trait |= DAO_VALUE_DELAYGC; self->derived = 0; self->bases = DList_New( DAO_DATA_VALUE ); self->methods = DHash_New( DAO_DATA_STRING, DAO_DATA_VALUE ); self->citype = DaoType_New( ns, "interface<", DAO_CINTYPE, (DaoValue*)self, NULL ); self->vatype = DaoType_New( ns, name->chars, DAO_CINVALUE, (DaoValue*)self, NULL ); self->abstract = inter; self->target = target; self->citype->core = & daoCinTypeCore; self->vatype->core = & daoCinValueCore; GC_IncRC( self->citype ); GC_IncRC( self->vatype ); GC_IncRC( self->abstract ); GC_IncRC( self->target ); self->vatype->kernel = DaoTypeKernel_New( NULL ); self->vatype->kernel->abtype = self->vatype; GC_IncRC( self->vatype->kernel ); GC_IncRC( self->vatype ); self->citype->args = DList_New( DAO_DATA_VALUE ); self->vatype->args = DList_New( DAO_DATA_VALUE ); DList_Append( self->citype->args, target ); DList_Append( self->vatype->args, target ); DString_AppendChar( self->vatype->name, '<' ); DString_Append( self->vatype->name, target->name ); DString_AppendChar( self->vatype->name, '>' ); DString_Append( self->citype->name, self->vatype->name ); DString_AppendChar( self->citype->name, '>' ); #ifdef DAO_USE_GC_LOGGER DaoObjectLogger_LogNew( (DaoValue*) self ); #endif return self; }
void DaoxDataFrame_GetLabel( DaoxDataFrame *self, int dim, int group, daoint i, DString *lab ) { DMap *labels = self->labels[dim]->items.pMap[group]; DNode *it; DString_Reset( lab, 0 ); for(it=DMap_First(labels); it; it=DMap_Next(labels,it)){ if( it->value.pInt == i ){ DString_Append( lab, it->key.pString ); break; } } }
static void Dao_AboutVar( DaoNamespace *ns, DaoValue *var, DString *str ) { DaoType *abtp = DaoNamespace_GetType( ns, var ); char buf[50]; if( abtp ){ if( var->type == DAO_ROUTINE ){ DString_Append( str, var->xRoutine.routName ); DString_AppendMBS( str, "{" ); DString_Append( str, abtp->name ); DString_AppendMBS( str, "}" ); }else{ DString_Append( str, abtp->name ); } sprintf( buf, "[%p]", var ); DString_AppendMBS( str, buf ); if( var->type == DAO_CDATA ){ sprintf( buf, "(%p)", var->xCdata.data ); DString_AppendMBS( str, buf ); } }else{ DString_AppendMBS( str, "NULL" ); } }
int DaoXmlParser_ParseFormatedChar( DaoXmlParser *self, DString *string ) { DNode *it; if( *self->source != '&' ){ DString_AppendChar( string, *self->source ); self->source += 1; return 0; } if( DaoXmlParser_ParseEscapedChar( self, self->escape ) ) return 1; it = DMap_Find( self->escapes, self->escape ); if( it == NULL ) return 1; DString_Append( string, it->value.pString ); return 0; }
static void DString_Serialize( DString *self, DString *serial, DString *buf ) { int i; unsigned char *mbs; DString_Clear( buf ); DString_ToMBS( buf ); DString_Append( buf, self ); mbs = (unsigned char*) buf->mbs; DString_AppendChar( serial, self->mbs ? '\'' : '\"' ); for(i=0; i<buf->size; i++){ DString_AppendChar( serial, hex_digits[ mbs[i] / 16 ] ); DString_AppendChar( serial, hex_digits[ mbs[i] % 16 ] ); } DString_AppendChar( serial, self->mbs ? '\'' : '\"' ); }
static DaoType* DaoInterface_CheckConversion( DaoType *self, DaoType *type, DaoRoutine *ctx ) { DaoRoutine *rout; DString *buffer = DString_NewChars( "(" ); DString_Append( buffer, type->name ); DString_AppendChars( buffer, ")" ); rout = DaoType_FindFunction( self, buffer ); DString_Delete( buffer ); if( rout != NULL ){ DaoType *ttype = DaoNamespace_GetType( ctx->nameSpace, (DaoValue*) type ); rout = DaoRoutine_MatchByType( rout, self, & ttype, 1, DVM_CALL ); if( rout ) return type; } return NULL; }
static void CHANNEL_New( DaoProcess *proc, DaoValue *par[], int N ) { DaoType *retype = DaoProcess_GetReturnType( proc ); DaoChannel *self = DaoChannel_New( retype, 0 ); CHANNEL_SetCap( self, par[0], proc ); if( DaoType_CheckPrimitiveType( retype->nested->items.pType[0] ) == 0 ){ DString *s = DString_New(); DString_AppendChars( s, "data type " ); DString_Append( s, retype->nested->items.pType[0]->name ); DString_AppendChars( s, " is not supported for channel" ); DaoProcess_RaiseError( proc, NULL, s->chars ); DString_Delete( s ); } DaoProcess_PutValue( proc, (DaoValue*) self ); DaoCallServer_TryInit( mainVmSpace ); }
static void DaoClass_GetField( DaoValue *self0, DaoProcess *proc, DString *name ) { int tid = proc->activeRoutine->routHost ? proc->activeRoutine->routHost->tid : 0; DaoType *type = proc->activeRoutine->routHost; DaoClass *host = tid == DAO_OBJECT ? & type->aux->xClass : NULL; DaoClass *self = & self0->xClass; DString *mbs = DString_New(1); DaoValue *value = NULL; int rc = DaoClass_GetData( self, name, & value, host ); if( rc ){ DString_SetMBS( mbs, DString_GetMBS( self->className ) ); DString_AppendMBS( mbs, "." ); DString_Append( mbs, name ); DaoProcess_RaiseException( proc, rc, mbs->mbs ); }else{ DaoProcess_PutReference( proc, value ); } DString_Delete( mbs ); }
static int addStringFromMap( DaoValue *self, DString *S, DaoMap *sym, const char *key, int id ) { DNode *node; if( S==NULL || sym==NULL ) return 0; DString_SetMBS( self->xString.data, key ); node = DMap_Find( sym->items, & self ); if( node ){ DaoList *list = & node->value.pValue->xList; if( list->type == DAO_LIST && list->items.size > id ){ DaoValue *p = list->items.items.pValue[ id ]; if( p->type == DAO_STRING ){ DString_Append( S, p->xString.data ); return 1; } } } return 0; }
static int DaoObject_CheckSetField( DaoType *self, DaoString *name, DaoType *value, DaoRoutine *ctx ) { DaoClass *klass = (DaoClass*) self->aux; DaoType *type = ctx->routHost; DaoClass *host = type != NULL && type->tid == DAO_OBJECT ? (DaoClass*) type->aux : NULL; DaoValue *data = DaoClass_GetData( klass, name->value, host ); DaoRoutine *rout; int error = DAO_OK; error = 0; if( strcmp( name->value->chars, "self" ) ==0 ) return DAO_ERROR_FIELD_HIDDEN; if( data == NULL ){ error = DAO_ERROR_FIELD_ABSENT; }else if( data->type == DAO_NONE ){ error = DAO_ERROR_FIELD_HIDDEN; }else if( data->xBase.subtype == DAO_CLASS_CONSTANT ){ error = DAO_ERROR_FIELD_HIDDEN; // XXX }else{ /* data->xBase.subtype == DAO_CLASS_VARIABLE || DAO_OBJECT_VARIABLE */ if( DaoType_MatchTo( value, data->xVar.dtype, NULL ) == 0 ) return DAO_ERROR_VALUE; } if( error ){ DString *field = DString_NewChars( "." ); DString_Append( field, name->value ); DString_AppendChars( field, "=" ); rout = DaoClass_FindMethod( klass, field->chars, host ); DString_Delete( field ); if( rout != NULL ){ rout = DaoRoutine_MatchByType( rout, self, & value, 1, DVM_CALL ); }else{ DaoType *args[2]; args[0] = dao_type_string; args[1] = value; rout = DaoClass_FindMethod( klass, ".=", host ); if( rout == NULL ) return error; rout = DaoRoutine_MatchByType( rout, self, args, 2, DVM_CALL ); } if( rout == NULL ) return error; } return DAO_OK; }
DaoValue* DaoValue_DoGetField( DaoValue *self, DaoType *type, DaoString *name, DaoProcess *proc ) { DaoValue *value = DaoType_FindValue( type, name->value ); DaoRoutine *rout; if( value != NULL ) return value; DString_SetChars( proc->string, "." ); DString_Append( proc->string, name->value ); rout = DaoType_FindFunction( type, proc->string ); if( rout != NULL ){ DaoProcess_PushCall( proc, rout, self, NULL, 0 ); }else{ DaoValue *arg = (DaoValue*) name; rout = DaoType_FindFunctionChars( type, "." ); if( rout == NULL ) return NULL; DaoProcess_PushCall( proc, rout, self, & arg, 1 ); } return NULL; }
int DaoValue_DoSetField( DaoValue *self, DaoType *type, DaoString *name, DaoValue *value, DaoProcess *proc ) { DaoRoutine *rout; DString_SetChars( proc->string, "." ); DString_Append( proc->string, name->value ); DString_AppendChars( proc->string, "=" ); rout = DaoType_FindFunction( type, proc->string ); if( rout != NULL ){ return DaoProcess_PushCall( proc, rout, self, & value, 1 ); }else{ DaoValue *args[2]; args[0] = (DaoValue*) name; args[1] = value; rout = DaoType_FindFunctionChars( type, ".=" ); if( rout == NULL ) return DAO_ERROR_FIELD_ABSENT; return DaoProcess_PushCall( proc, rout, self, args, 2 ); } return DAO_ERROR_FIELD_ABSENT; }
static DaoValue* DaoObject_DoConversion( DaoValue *self, DaoType *type, int copy, DaoProcess *proc ) { DaoObject *object = (DaoObject*) self; DaoClass *host = proc->activeObject ? proc->activeObject->defClass : NULL; DaoValue *base = DaoObject_CastToBase( object->rootObject, type ); DaoRoutine *rout; DString *buffer; if( base ) return base; buffer = DString_NewChars( "(" ); DString_Append( buffer, type->name ); DString_AppendChars( buffer, ")" ); rout = DaoClass_FindMethod( object->defClass, buffer->chars, host ); DString_Delete( buffer ); if( rout != NULL ){ int rc = DaoProcess_PushCall( proc, rout, self, (DaoValue**) & type, 1 ); if( rc ) return NULL; } return NULL; }
static DaoType* DaoObject_CheckConversion( DaoType *self, DaoType *type, DaoRoutine *ctx ) { DString *buffer; DaoRoutine *rout; DaoType *hostype = ctx->routHost; DaoClass *host = hostype != NULL && hostype->tid == DAO_OBJECT ? (DaoClass*) hostype->aux : NULL; if( DaoType_ChildOf( self, type ) ) return type; if( DaoType_ChildOf( type, self ) ) return type; buffer = DString_NewChars( "(" ); DString_Append( buffer, type->name ); DString_AppendChars( buffer, ")" ); rout = DaoClass_FindMethod( (DaoClass*) self->aux, buffer->chars, host ); DString_Delete( buffer ); if( rout != NULL ){ DaoType *ttype = DaoNamespace_GetType( ctx->nameSpace, (DaoValue*) type ); rout = DaoRoutine_MatchByType( rout, self, & ttype, 1, DVM_CALL ); } if( rout != NULL ) return type; return NULL; }
static void DaoObject_Core_GetField( DaoValue *self0, DaoProcess *proc, DString *name ) { DaoObject *self = & self0->xObject; DaoValue *value = NULL; int rc = DaoObject_GetData( self, name, & value, proc->activeObject ); if( rc ){ DString *field = proc->string; DString_SetChars( field, "." ); DString_Append( field, name ); rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, field, NULL,0,0,0 ); if( rc == DAO_ERROR_FIELD_NOTEXIST ){ DaoString str = {DAO_STRING,0,0,0,1,NULL}; DaoValue *pars = (DaoValue*) & str; str.value = name; DString_SetChars( field, "." ); rc = DaoObject_InvokeMethod( self, proc->activeObject, proc, field, &pars,1,0,0 ); } }else{ DaoProcess_PutValue( proc, value ); } if( rc ) DaoProcess_RaiseException( proc, daoExceptionNames[rc], name->chars, NULL ); }
static void DaoArray_Serialize( DaoArray *self, DString *serial, DString *buf ) { DaoInteger intmp = {DAO_INTEGER,0,0,0,0,0}; DaoValue *value = (DaoValue*) & intmp; int i; DString_AppendChar( serial, '[' ); for(i=0; i<self->ndim; i++){ value->xInteger.value = self->dims[i]; if( i ) DString_AppendChar( serial, ',' ); DaoValue_GetString( value, buf ); DString_Append( serial, buf ); } DString_AppendChar( serial, ']' ); for(i=0; i<self->size; i++){ if( i ) DString_AppendChar( serial, ',' ); switch( self->etype ){ case DAO_INTEGER : DaoSerializeInteger( self->data.i[i], serial ); break; case DAO_FLOAT : DaoSerializeDouble( self->data.f[i], serial ); break; case DAO_DOUBLE : DaoSerializeDouble( self->data.d[i], serial ); break; case DAO_COMPLEX : DaoSerializeComplex( self->data.c[i], serial ); break; } } }