DaoLexer* DaoLexer_New() { DaoLexer *self = (DaoLexer*) dao_malloc( sizeof(DaoLexer) ); self->tokens = DArray_New(D_TOKEN); self->tokbuf = DArray_New(0); return self; }
static DaoCallServer* DaoCallServer_New( DaoVmSpace *vms ) { DaoComplex com = {DAO_COMPLEX,0,0,0,1,{0.0,0.0}}; DaoCallServer *self = (DaoCallServer*)dao_malloc( sizeof(DaoCallServer) ); DMutex_Init( & self->mutex ); DCondVar_Init( & self->condv ); DCondVar_Init( & self->condv2 ); DThread_Init( & self->timer ); self->finishing = 0; self->timing = 0; self->total = 0; self->idle = 0; self->stopped = 0; self->threads = DArray_New(0); self->functions = DArray_New(0); self->parameters = DArray_New(0); self->events = DArray_New(0); self->events2 = DArray_New(0); self->waitings = DMap_New(D_VALUE,0); self->pending = DHash_New(0,0); self->active = DHash_New(0,0); self->caches = DArray_New(0); self->vmspace = vms; self->timestamp = com; return self; }
static DaoCallServer* DaoCallServer_New( DaoVmSpace *vms ) { DaoCallServer *self = (DaoCallServer*)dao_malloc( sizeof(DaoCallServer) ); DMutex_Init( & self->mutex ); DCondVar_Init( & self->condv ); DCondVar_Init( & self->condv2 ); DThread_Init( & self->timer ); self->finishing = 0; self->timing = 0; self->total = 0; self->vacant = 0; self->idle = 0; self->stopped = 0; self->threads = DList_New(0); self->functions = DList_New(0); self->parameters = DList_New(0); self->owners = DList_New(0); self->events = DList_New(0); self->events2 = DList_New(0); self->waitings = DMap_New( DAO_DATA_COMPLEX, 0 ); self->pending = DHash_New(0,0); self->active = DHash_New(0,0); self->caches = DList_New(0); self->vmspace = vms; self->timestamp.real = 0.0; self->timestamp.imag = 0.0; return self; }
static DaoMethodFields* DaoMethodFields_New() { DaoMethodFields *self = (DaoMethodFields*) dao_malloc( sizeof(DaoMethodFields) ); self->names = DArray_New(D_STRING); self->perms = DArray_New(0); self->routines = DArray_New(0); return self; }
DMacroUnit* DMacroUnit_New() { DMacroUnit *self = (DMacroUnit*) dao_malloc( sizeof(DMacroUnit) ); self->type = DMACRO_TOK; self->stops = DArray_New(D_TOKEN); self->marker = DaoToken_New(); return self; }
Dao_Buffer* Dao_Buffer_New( size_t size ) { Dao_Buffer *self = (Dao_Buffer*) dao_malloc( sizeof(Dao_Buffer) ); DaoCstruct_Init( (DaoCstruct*)self, daox_type_buffer ); self->size = self->bufsize = 0; self->buffer.pVoid = NULL; Dao_Buffer_Resize( self, size ); return self; }
DaoRegex* DaoRegex_New( DString *src ) { DaoRegex *self = NULL; int size = DaoRegex_CheckSize( src ); self = (DaoRegex*) dao_malloc( size ); self->length = size; DaoRegex_Init( self, src ); return self; }
static DaoCallThread* DaoCallThread_New( DThreadTask func, void *param ) { DaoCallThread *self = (DaoCallThread*)dao_malloc( sizeof(DaoCallThread) ); self->thdData = NULL; self->taskFunc = func; self->taskParam = param; DThread_Init( & self->thread ); return self; }
DMacroNode* DMacroNode_New( short leaf, short level ) { DMacroNode *self = (DMacroNode*) dao_malloc( sizeof( DMacroNode ) ); self->isLeaf = leaf; self->level = level; self->nodes = DArray_New(0); self->leaves = DArray_New(D_TOKEN); self->parent = NULL; self->group = NULL; return self; }
DaoMacro* DaoMacro_New() { DaoMacro *self = (DaoMacro*) dao_malloc( sizeof(DaoMacro) ); DaoValue_Init( self, DAO_MACRO ); self->keyListApply = DArray_New(D_STRING); self->macroList = DArray_New(0); self->firstMacro = self; self->macroMatch = DMacroGroup_New(); self->macroApply = DMacroGroup_New(); DArray_Append( self->macroList, self ); return self; }
DMacroGroup* DMacroGroup_New() { DMacroGroup *self = (DMacroGroup*) dao_malloc( sizeof(DMacroGroup) ); self->type = DMACRO_GRP; self->repeat = DMACRO_ONE; self->cpos = 0; self->units = DArray_New(0); self->stops = DArray_New(D_TOKEN); self->variables = DArray_New(D_TOKEN); self->parent = NULL; return self; }
DList* DList_New( short type ) { #ifdef DAO_USE_GC_LOGGER daoCountArray ++; #endif DList *self = (DList*)dao_malloc( sizeof(DList) ); self->items.pVoid = NULL; self->size = self->bufsize = 0; self->offset = 0; self->type = type; return self; }
int DString_Match( DString *self, const char *pat, daoint *start, daoint *end ) { DString *str = DString_New(); DaoRegex *regex; int rc; DString_SetChars( str, pat ); regex = (DaoRegex*) dao_malloc( DaoRegex_CheckSize( str ) ); DaoRegex_Init( regex, str ); DString_Delete( str ); rc = DaoRegex_Match( regex, self, start, end ); dao_free( regex ); return rc; }
DArray* DArray_New( short type ) { #ifdef DAO_USE_GC_LOGGER daoCountArray ++; #endif DArray *self = (DArray*)dao_malloc( sizeof(DArray) ); self->items.pVoid = NULL; self->size = self->bufsize = 0; self->offset = 0; self->type = type; self->mutating = 0; return self; }
DaoState* DaoState_New( DaoType *type, DaoValue *state ) { DaoState *res = dao_malloc( sizeof(DaoState) ); DaoCstruct_Init( (DaoCstruct*)res, type ); DaoValue_Copy( state, &res->state ); res->lock = DaoMutex_New(); res->defmtx = DaoMutex_New(); res->demands = DaoMap_New( 0 ); DaoGC_IncRC( (DaoValue*)res->lock ); DaoGC_IncRC( (DaoValue*)res->defmtx ); DaoGC_IncRC( (DaoValue*)res->demands ); return res; }
DaoQueue* DaoQueue_New( DaoType *type, int capacity ) { DaoQueue *res = (DaoQueue*)dao_malloc( sizeof(DaoQueue) ); DaoCstruct_Init( (DaoCstruct*)res, type ); res->head = res->tail = NULL; res->size = 0; res->capacity = ( ( capacity < 0 )? 0 : capacity ); res->mtx = DaoMutex_New(); res->pushvar = DaoCondVar_New(); res->popvar = DaoCondVar_New(); DaoGC_IncRC( (DaoValue*)res->mtx ); DaoGC_IncRC( (DaoValue*)res->pushvar ); DaoGC_IncRC( (DaoValue*)res->popvar ); return res; }
int DString_Change( DString *self, const char *pat, const char *target, int index ) { DString *str = DString_New(); DString *tg = DString_New(); DaoRegex *regex; int rc; DString_SetChars( str, pat ); DString_SetChars( tg, target ); regex = (DaoRegex*) dao_malloc( DaoRegex_CheckSize( str ) ); DaoRegex_Init( regex, str ); DString_Delete( str ); rc = DaoRegex_Change( regex, self, tg, index ); DString_Delete( tg ); dao_free( regex ); return rc; }
void DString_Assign( DString *self, DString *chs ) { int *data1 = (int*)self->chars - self->sharing; int *data2 = (int*)chs->chars - chs->sharing; int assigned = 0; if( self == chs ) return; if( data1 == data2 ) return; if( data2 != dao_string ){ #ifdef DAO_WITH_THREAD DMutex_Lock( & mutex_string_sharing ); #endif if( self->aux ) self->aux->size = 0; if( self->sharing && chs->sharing ){ if( data1 != dao_string ){ data1[0] -= 1; if( data1[0] ==0 ) dao_free( data1 ); } memcpy( self, chs, sizeof(DString) - sizeof(DStringAux*) ); data2[0] += 1; assigned = 1; }else if( data1 == NULL && chs->sharing ){ memcpy( self, chs, sizeof(DString) - sizeof(DStringAux*) ); data2[0] += 1; assigned = 1; } #ifdef DAO_WITH_THREAD DMutex_Unlock( & mutex_string_sharing ); #endif if( assigned ) return; } if( self->chars == NULL ){ self->size = self->bufSize = chs->size; self->chars = (char*) dao_malloc( (chs->size + 1)*sizeof(char) ); memcpy( self->chars, chs->chars, chs->size*sizeof(char) ); self->chars[ self->size ] = 0; }else{ DString_Resize( self, chs->size ); memcpy( self->chars, chs->chars, chs->size*sizeof(char) ); } }
static void DaoQueue_Push( DaoProcess *proc, DaoValue *p[], int N ) { DaoQueue *self = (DaoQueue*)DaoValue_CastCstruct( p[0], NULL ); QueueItem *item = (QueueItem*)dao_malloc( sizeof(QueueItem) ); item->value = NULL; DaoValue_Copy( p[1], &item->value ); item->next = NULL; DaoMutex_Lock( self->mtx ); while( self->capacity && self->size == self->capacity ) DaoCondVar_Wait( self->pushvar, self->mtx ); item->previous = self->tail; if( self->tail ) self->tail->next = item; else{ self->head = item; DaoCondVar_Signal( self->popvar ); } self->tail = item; self->size++; DaoMutex_Unlock( self->mtx ); }
static void DaoQueue_TryPush( DaoProcess *proc, DaoValue *p[], int N ) { DaoQueue *self = (DaoQueue*)DaoValue_CastCstruct( p[0], NULL ); QueueItem *item = (QueueItem*)dao_malloc( sizeof(QueueItem) ); float timeout = DaoValue_TryGetFloat( p[2] ); int pushable = 0, timed = 0; item->value = NULL; DaoValue_Copy( p[1], &item->value ); item->next = NULL; DaoMutex_Lock( self->mtx ); if( timeout == 0 ) pushable = ( !self->capacity || self->size < self->capacity ); else if( timeout < 0 ){ while( self->capacity && self->size == self->capacity ) DaoCondVar_Wait( self->pushvar, self->mtx ); pushable = 1; } else{ while( !timed && self->capacity && self->size == self->capacity ) timed = DaoCondVar_TimedWait( self->pushvar, self->mtx, timeout ); pushable = !timed; } if( pushable ){ item->previous = self->tail; if( self->tail ) self->tail->next = item; else{ self->head = item; DaoCondVar_Signal( self->popvar ); } self->tail = item; self->size++; } DaoMutex_Unlock( self->mtx ); if( !pushable ){ DaoGC_DecRC( item->value ); dao_free( item ); } DaoProcess_PutInteger( proc, pushable ); }
void DString_Detach( DString *self, daoint bufsize ) { daoint size; int *data2, *data = (int*)self->chars - self->sharing; if( self->aux ) self->aux->size = 0; if( self->sharing == 0 ) return; #ifdef DAO_WITH_THREAD DMutex_Lock( & mutex_string_sharing ); #endif if( data[0] >1 || data == dao_string ){ if( bufsize < self->size ) bufsize = self->size; data[0] -= 1; self->bufSize = bufsize + 1; data2 = (int*) dao_malloc( (self->bufSize + 1)*sizeof(char) + sizeof(int) ); data2[0] = 1; memcpy( data2+1, data+1, (self->size + 1)*sizeof(char) ); self->chars = (char*)(data2 + 1); } #ifdef DAO_WITH_THREAD DMutex_Unlock( & mutex_string_sharing ); #endif }
static DaoVmCodeX* DaoVmCodeX_Copy( DaoVmCodeX *self ) { DaoVmCodeX* copy = (DaoVmCodeX*) dao_malloc( sizeof(DaoVmCodeX) ); memcpy( copy, self, sizeof(DaoVmCodeX) ); return copy; }