Esempio n. 1
0
void DaoxGraphData_Init( DaoxGraphData *self, DaoType *type )
{
	DaoCstruct_Init( (DaoCstruct*) self, type );
	self->graph = NULL;
	self->edgeData = DString_New();
	self->nodeData = DString_New();
	DString_SetSharing( self->nodeData, 0 );
	DString_SetSharing( self->edgeData, 0 );
}
Esempio n. 2
0
DaoStream* DaoStream_New()
{
	DaoStream *self = (DaoStream*) dao_calloc( 1, sizeof(DaoStream) );
	DaoCstruct_Init( (DaoCstruct*) self, dao_type_stream );
	self->type = DAO_CSTRUCT; /* dao_type_stream may still be null in DaoVmSpace_New(); */
	self->streamString = DString_New(1);
	self->fname = DString_New(1);
	self->mode = DAO_IO_READ | DAO_IO_WRITE;
	return self;
}
Esempio n. 3
0
DaoXmlNode* DaoXmlNode_New()
{
	DaoXmlNode *self = (DaoXmlNode*) dao_calloc( 1, sizeof(DaoXmlNode) );
	self->parent = NULL;
	self->children = DList_New(0);
	self->name = DString_New();
	self->content = DString_New();
	self->attributes = DHash_New( DAO_DATA_STRING, DAO_DATA_STRING );
	return self;
}
Esempio n. 4
0
void DaoStream_WriteString( DaoStream *self, DString *val )
{
	int i;
	if( val->mbs ){
		const char *data = val->mbs;
		if( self->redirect && self->redirect->StdioWrite ){
			DString *mbs = DString_New(1);
			DString_SetDataMBS( mbs, data, val->size );
			self->redirect->StdioWrite( self->redirect, mbs );
			DString_Delete( mbs );
		}else if( self->file ){
			if( self->format ){
				fprintf( self->file, self->format, data );
			}else{
				DaoFile_WriteString( self->file, val );
			}
		}else if( self->attribs & DAO_IO_STRING ){
			DString_AppendDataMBS( self->streamString, data, val->size );
		}else{
			if( self->format ){
				printf( self->format, data );
			}else{
				DaoFile_WriteString( stdout, val );
			}
		}
	}else{
		const wchar_t *data = val->wcs;
		if( self->redirect && self->redirect->StdioWrite ){
			DString *mbs = DString_New(1);
			DString_SetWords( mbs, data, val->size );
			self->redirect->StdioWrite( self->redirect, mbs );
			DString_Delete( mbs );
		}else if( self->file ){
			if( self->format ){
				fprintf( self->file, self->format, data );
			}else{
				DaoFile_WriteString( self->file, val );
			}
		}else if( self->attribs & DAO_IO_STRING ){
			DString *wcs = self->streamString;
			int size = 0;
			DString_ToWCS( self->streamString );
			size = wcs->size;
			DString_Resize( self->streamString, wcs->size + val->size );
			memcpy( wcs->wcs + size, val->wcs, val->size * sizeof(wchar_t) );
		}else{
			if( self->format ){
				printf( self->format, data );
			}else{
				DaoFile_WriteString( stdout, val );
			}
		}
	}
}
Esempio n. 5
0
void DaoValue_Print( DaoValue *self, DaoProcess *proc, DaoStream *stream, DMap *cycData )
{
	DString *name;
	DaoTypeBase *typer;
	DMap *cd = cycData;
	if( self == NULL ){
		DaoStream_WriteMBS( stream, "none[0x0]" );
		return;
	}
	if( cycData == NULL ) cycData = DMap_New(0,0);
	switch( self->type ){
	case DAO_INTEGER :
		DaoStream_WriteInt( stream, self->xInteger.value ); break;
	case DAO_FLOAT   :
		DaoStream_WriteFloat( stream, self->xFloat.value ); break;
	case DAO_DOUBLE  :
		DaoStream_WriteFloat( stream, self->xDouble.value ); break;
	case DAO_COMPLEX :
		DaoStream_WriteFloat( stream, self->xComplex.value.real );
		if( self->xComplex.value.imag >= -0.0 ) DaoStream_WriteMBS( stream, "+" );
		DaoStream_WriteFloat( stream, self->xComplex.value.imag );
		DaoStream_WriteMBS( stream, "C" );
		break;
#ifdef DAO_WITH_LONGINT
	case DAO_LONG :
		name = DString_New(1);
		DLong_Print( self->xLong.value, name );
		DaoStream_WriteString( stream, name );
		DString_Delete( name );
		break;
#endif
	case DAO_ENUM  :
		name = DString_New(1);
		DaoEnum_MakeName( & self->xEnum, name );
		DaoStream_WriteMBS( stream, name->mbs );
		DaoStream_WriteMBS( stream, "(" );
		DaoStream_WriteInt( stream, self->xEnum.value );
		DaoStream_WriteMBS( stream, ")" );
		DString_Delete( name );
		break;
	case DAO_STRING  :
		DaoStream_WriteString( stream, self->xString.data ); break;
	default :
		typer = DaoVmSpace_GetTyper( self->type );
		if( typer->core->Print == DaoValue_Print ){
			DaoValue_BasicPrint( self, proc, stream, cycData );
			break;
		}
		typer->core->Print( self, proc, stream, cycData );
		break;
	}
	if( cycData != cd ) DMap_Delete( cycData );
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
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 );
}
Esempio n. 8
0
DaoClass* DaoClass_New()
{
	DaoClass *self = (DaoClass*) dao_calloc( 1, sizeof(DaoClass) );
	DaoValue_Init( self, DAO_CLASS );
	self->trait |= DAO_VALUE_DELAYGC;
	self->className = DString_New(1);

	self->lookupTable = DHash_New(D_STRING,0);
	self->ovldRoutMap = DHash_New(D_STRING,0);
	self->abstypes    = DMap_New(D_STRING,D_VALUE);
	self->constants   = DArray_New(D_VALUE);
	self->variables   = DArray_New(D_VALUE);
	self->instvars    = DArray_New(D_VALUE);
	self->objDataName = DArray_New(D_STRING);
	self->cstDataName = DArray_New(D_STRING);
	self->glbDataName = DArray_New(D_STRING);
	self->parent = NULL;
	self->mixinBases = DArray_New(0);  /* refcount handled in ::allBases; */
	self->allBases   = DArray_New(D_VALUE);
	self->mixins  = DArray_New(0);
	self->ranges  = DVector_New(sizeof(ushort_t));
	self->offsets = DVector_New(sizeof(ushort_t));
	self->references  = DArray_New(D_VALUE);
	self->inter = NULL;

	self->cstMixinStart = self->cstMixinEnd = self->cstMixinEnd2 = 0;
	self->glbMixinStart = self->glbMixinEnd = self->glbMixinEnd2 = 0;
	self->objMixinStart = self->objMixinEnd = self->objMixinEnd2 = 0;
	self->cstParentStart = self->cstParentEnd = 0;
	self->glbParentStart = self->glbParentEnd = 0;
	return self;
}
Esempio n. 9
0
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 );
}
Esempio n. 10
0
void DaoStream_WriteFloat( DaoStream *self, double val )
{
	const char *format = self->format;
	const char *iconvs = "diouxXcC";
	char buffer[100];
	if( format && strchr( iconvs, format[ strlen(format)-1 ] ) && val ==(long)val ){
		DaoStream_WriteInt( self, (daoint)val );
		return;
	}
	if( format == NULL ) format = "%f";
	if( self->redirect && self->redirect->StdioWrite ){
		DString *mbs = DString_New(1);
		sprintf( buffer, format, val );
		DString_SetMBS( mbs, buffer );
		self->redirect->StdioWrite( self->redirect, mbs );
		DString_Delete( mbs );
	}else if( self->file ){
		fprintf( self->file, format, val );
	}else if( self->attribs & DAO_IO_STRING ){
		sprintf( buffer, format, val );
		DString_AppendMBS( self->streamString, buffer );
	}else{
		printf( format, val );
	}
}
Esempio n. 11
0
/* assumed to be called after parsing class body */
void DaoClass_DeriveObjectData( DaoClass *self )
{
	DaoType *type;
	DaoValue *value;
	DArray *parents, *offsets;
	DString *mbs;
	DNode *search;
	daoint i, id, perm, index, offset = 0;

	self->objDefCount = self->objDataName->size;
	offset = self->objDataName->size;
	mbs = DString_New(1);

	parents = DArray_New(0);
	offsets = DArray_New(0);
	DaoClass_Parents( self, parents, offsets );
	for( i=0; i<self->superClass->size; i++){
		if( self->superClass->items.pValue[i]->type == DAO_CLASS ){
			DaoClass *klass = self->superClass->items.pClass[i];

			/* for properly arrangement object data: */
			for( id=0; id<klass->objDataName->size; id ++ ){
				DString *name = klass->objDataName->items.pString[id];
				DaoVariable *var = klass->instvars->items.pVar[id];
				var = DaoVariable_New( var->value, var->dtype );
				DArray_Append( self->objDataName, name );
				DArray_Append( self->instvars, var );
				DaoValue_MarkConst( (DaoValue*) var->value );
			}
			offset += klass->objDataName->size;
		}
	}
	for(i=1; i<parents->size; i++){
		DaoClass *klass = parents->items.pClass[i];
		offset = offsets->items.pInt[i]; /* plus self */
		if( klass->type == DAO_CLASS ){
			/* For object data: */
			for( id=0; id<klass->objDataName->size; id ++ ){
				DString *name = klass->objDataName->items.pString[id];
				search = MAP_Find( klass->lookupTable, name );
				perm = LOOKUP_PM( search->value.pInt );
				/* NO deriving private member: */
				if( perm <= DAO_DATA_PRIVATE ) continue;
				search = MAP_Find( self->lookupTable, name );
				if( search == NULL ){ /* To not overide data and routine: */
					index = LOOKUP_BIND( DAO_OBJECT_VARIABLE, perm, i, (offset+id) );
					MAP_Insert( self->lookupTable, name, index );
				}
			}
		}
	}
	self->derived = 1;
	DString_Delete( mbs );
	DArray_Delete( parents );
	DArray_Delete( offsets );
	DaoObject_Init( & self->objType->value->xObject, NULL, 0 );
	self->objType->value->xObject.trait &= ~DAO_VALUE_CONST;
	DaoValue_MarkConst( self->objType->value );
	DaoValue_MarkConst( self->constants->items.pConst[1]->value ); /* ::default */
}
Esempio n. 12
0
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;
}
Esempio n. 13
0
void DaoStream_SetStringMode( DaoStream *self )
{
	if( self->buffer == NULL ) self->buffer = DString_New();
	self->Write = DaoStream_WriteBuffer;
	self->Read = NULL;
	self->Flush = NULL;
	self->SetColor = NULL;
}
Esempio n. 14
0
DaoxFont* DaoxFont_New()
{
	DaoxFont *self = (DaoxFont*) dao_calloc( 1, sizeof(DaoxFont) );
	DaoCstruct_Init( (DaoCstruct*)self, daox_type_font );
	self->buffer = DString_New();
	self->glyphs = DMap_New(0,DAO_DATA_VALUE);
	return self;
}
Esempio n. 15
0
/* Real copying, no implicit sharing here. For thread safty. */
DString* DString_DeepCopy( DString *self )
{
	int share = self->sharing;
	DString *copy = DString_New();
	DString_SetSharing( copy, share );
	DString_Resize( copy, self->size );
	memcpy( copy->chars, self->chars, self->size *sizeof(char) );
	return copy;
}
Esempio n. 16
0
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 );
}
Esempio n. 17
0
DaoStringStream* DaoStringStream_New()
{
	DaoStringStream *self = (DaoStringStream*) dao_calloc( 1, sizeof(DaoStringStream) );
	DaoCstruct_Init( (DaoCstruct*) self, dao_type_string_stream );
	self->base.buffer = DString_New();
	self->base.Read = DaoStringStream_Read;
	self->base.Write = DaoStringStream_Write;
	self->base.AtEnd = DaoStringStream_AtEnd;
	self->base.Flush = NULL;
	self->base.SetColor = NULL;
	return self;
}
Esempio n. 18
0
int main( int argc, char *argv[] )
{
  DString *src;
  DaoVmSpace *vms;
  DaoNameSpace *ns;
  DaoVmProcess *vmp;

  // Search and load the Dao library.
  // DaoInitLibrary() can take a parameter which is the path
  // to the dynamic loading file of the Dao library.
  // If the parameter is NULL, the current path is searched,
  // then the path defined by environment variable DAO_DIR,
  // then $(HOME)/dao, and then the default system path:
  // /usr/local/dao/ or C:\dao\.
  //
  // With direct APIs, the example must be linked against the Dao library.
  // So if direct APIs are used, the following call is not necessary.
#ifndef DAO_DIRECT_API
  if( DaoInitLibrary( NULL ) ==0 ) return 1;
#endif

  // Initialize Dao library, and get the default DaoVmSpace object.
  // DaoVmSpace is responsible for handling interpreter settings,
  // paths and module loading etc. It is need to create several
  // other types of objects.
  vms = DaoInit();

  // Get the main namespace of an DaoVmSpace object.
  // You can also call DaoNameSpace_New( vms ) to create one.
  ns  = DaoVmSpace_MainNameSpace( vms );

  // Get the main virtual machine process of an DaoVmSpace object.
  // You can also call DaoVmProcess_New( vms ) to create one.
  vmp = DaoVmSpace_MainVmProcess( vms );

  // Prepare the Dao source codes:
  src = DString_New(1);
  DString_SetMBS( src, dao_source );

  // Wrap and setup a C/C++ type:
  DaoNameSpace_WrapType( ns, dao_FakeList_Typer );

  // Execute the Dao scripts:
  // Since the wrapped functions and types are imported into
  // namespace ns, it is need to access the wrapped functions and types
  // in the Dao scripts when it is executed:
  DaoVmProcess_Eval( vmp, ns, src, 1 );

  DString_Delete( src );
  DaoQuit(); // Finalizing
  return 0;
}
Esempio n. 19
0
int DaoValue_Serialize( DaoValue *self, DString *serial, DaoNamespace *ns, DaoProcess *proc )
{
	DaoType *type = DaoNamespace_GetType( ns, self );
	DString *buf = DString_New(1);
	DMap *omap = DMap_New(0,0);
	int rc;
	DString_Clear( serial );
	DString_ToMBS( serial );
	rc = DaoValue_Serialize2( self, serial, ns, proc, type, buf, omap );
	DString_Delete( buf );
	DMap_Delete( omap );
	return rc;
}
Esempio n. 20
0
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;
}
Esempio n. 21
0
static void NS_Backup( DaoNamespace *self, DaoProcess *proc, FILE *fout, int limit, int store )
{
	DNode *node = DMap_First( self->lookupTable );
	DString *prefix = DString_New(1);
	DString *serial = DString_New(1);
	DaoValue *value = NULL;
	size_t max = limit * 1000; /* limit per object in KB */
	int id, pm, up, st;

	for( ; node !=NULL; node = DMap_Next( self->lookupTable, node ) ){
		DString *name = node->key.pString;
		id = node->value.pInt;
		up = LOOKUP_UP( id );
		st = LOOKUP_ST( id );
		pm = LOOKUP_PM( id );
		if( up ) continue;
		if( st != store ) continue;
		if( st == DAO_GLOBAL_CONSTANT ) value = DaoNamespace_GetConst( self, id );
		if( st == DAO_GLOBAL_VARIABLE ) value = DaoNamespace_GetVariable( self, id );
		if( value == NULL ) continue;
		if( DaoValue_Serialize( value, serial, self, proc ) ==0 ) continue;
		prefix->size = 0;
		switch( pm ){
		case DAO_DATA_PRIVATE   : DString_AppendMBS( prefix, "private " ); break;
		case DAO_DATA_PROTECTED : DString_AppendMBS( prefix, "protected " ); break;
		case DAO_DATA_PUBLIC    : DString_AppendMBS( prefix, "public " ); break;
		}
		switch( st ){
		case DAO_GLOBAL_CONSTANT : DString_AppendMBS( prefix, "const " ); break;
		case DAO_GLOBAL_VARIABLE : DString_AppendMBS( prefix, "var " ); break;
		}
		if( max && prefix->size + name->size + serial->size + 4 > max ) continue;
		fprintf( fout, "%s%s = %s\n", prefix->mbs, name->mbs, serial->mbs );
	}
	DString_Delete( prefix );
	DString_Delete( serial );
}
Esempio n. 22
0
DaoXmlParser* DaoXmlParser_New()
{
	DaoXmlParser *self = (DaoXmlParser*) dao_calloc( 1, sizeof(DaoXmlParser) );
	self->key = DString_New();
	self->value = DString_New();
	self->escape = DString_New();
	self->escapes = DHash_New( DAO_DATA_STRING, DAO_DATA_STRING );
	DString_SetChars( self->key, "lt" );
	DString_SetChars( self->value, "<" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "gt" );
	DString_SetChars( self->value, ">" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "amp" );
	DString_SetChars( self->value, "&" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "apos" );
	DString_SetChars( self->value, "'" );
	DMap_Insert( self->escapes, self->key, self->value );
	DString_SetChars( self->key, "quot" );
	DString_SetChars( self->value, "\"" );
	DMap_Insert( self->escapes, self->key, self->value );
	return self;
}
Esempio n. 23
0
void DaoStream_WriteChar( DaoStream *self, char val )
{
	const char *format = "%c";
	if( self->redirect && self->redirect->StdioWrite ){
		DString *mbs = DString_New(1);
		DString_AppendChar( mbs, val );
		self->redirect->StdioWrite( self->redirect, mbs );
		DString_Delete( mbs );
	}else if( self->file ){
		fprintf( self->file, format, val );
	}else if( self->attribs & DAO_IO_STRING ){
		DString_AppendChar( self->streamString, val );
	}else{
		printf( format, val );
	}
}
Esempio n. 24
0
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 );
}
Esempio n. 25
0
DAO_DLL int DaoOnLoad( DaoVmSpace *vmSpace, DaoNamespace *ns )
{
	FILE *fin = fopen( "test.xml", "r" );
	DString *xml = DString_New();
	DaoXmlDOM *dom = DaoXmlDOM_New();
	DaoXmlParser *parser = DaoXmlParser_New();
	DaoFile_ReadAll( fin, xml, 1 );

	DaoXmlParser_Parse( parser, dom, xml );

	DaoXmlDOM_Traverse( dom, NULL, NULL, DaoXmlNode_TestVisit );

	DString_Delete( xml );
	DaoXmlDOM_Delete( dom );
	DaoXmlParser_Delete( parser );
	return 0;
}
Esempio n. 26
0
void DaoStream_WriteWCS( DaoStream *self, const wchar_t *val )
{
	const char *format = self->format;
	if( format == NULL ) format = "%ls";
	if( self->redirect && self->redirect->StdioWrite ){
		DString *mbs = DString_New(1);
		DString_SetWCS( mbs, val );
		self->redirect->StdioWrite( self->redirect, mbs );
		DString_Delete( mbs );
	}else if( self->file ){
		fprintf( self->file, format, val );
	}else if( self->attribs & DAO_IO_STRING ){
		DString_AppendWCS( self->streamString, val );
	}else{
		printf( format, val );
	}
}
Esempio n. 27
0
void DaoxShader_CompileShader( DaoxShader *self, int type, DArray *strings )
{
	daoint i, n = strings->size;
	uint_t shader = glCreateShader( type );
	const GLchar **sources;
	GLint length, shader_ok;

	if( shader == 0 ){
		fprintf(stderr, "Failed to create shader of type %i\n", type );
		return;
	}
	sources = (const GLchar**) malloc( n*sizeof(GLchar*) );
	for(i=0; i<n; ++i){
		sources[i] = (const GLchar*) DString_GetMBS( strings->items.pString[i] );
		if( i == 0 ) sources[i] += 2; /* skip //; */
	}

	glShaderSource( shader, n, sources, NULL );
	glCompileShader( shader );
	free( sources );

	glGetShaderiv(shader, GL_COMPILE_STATUS, &shader_ok);
	if( !shader_ok ){
		const char *log2;
		DString *log = DString_New(1);
		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length );
		DString_Resize( log, length );
		log2 = DString_GetMBS(log);
		glGetShaderInfoLog( shader, length, NULL, (char*)log2 );
		fprintf(stderr, "Failed to compile shader!\nWith error message: %s", log2 );
		glDeleteShader(shader);
		return;
	}
	switch( type ){
	case GL_VERTEX_SHADER :
		if( self->vertexShader ) glDeleteShader( self->vertexShader );
		self->vertexShader = shader;
		break;
	case GL_FRAGMENT_SHADER :
		if( self->fragmentShader ) glDeleteShader( self->fragmentShader );
		self->fragmentShader = shader;
		break;
	}
	if( shader && self->program ) glAttachShader( self->program, shader );
}
Esempio n. 28
0
void DaoStream_WriteFormatedInt( DaoStream *self, daoint val, const char *format )
{
	char buffer[100];
	if( self->redirect && self->redirect->StdioWrite ){
		DString *mbs = DString_New(1);
		sprintf( buffer, format, val );
		DString_SetMBS( mbs, buffer );
		self->redirect->StdioWrite( self->redirect, mbs );
		DString_Delete( mbs );
	}else if( self->file ){
		fprintf( self->file, format, val );
	}else if( self->attribs & DAO_IO_STRING ){
		sprintf( buffer, format, val );
		DString_AppendMBS( self->streamString, buffer );
	}else{
		printf( format, val );
	}
}
Esempio n. 29
0
void DaoClass_ResetAttributes( DaoClass *self )
{
	DNode *node;
	DString *mbs = DString_New(1);
	int i, k, id, autodef = self->classRoutines->overloads->routines->size == 0;

	DaoClass_MakeInterface( self );

	for(i=0; i<self->classRoutines->overloads->routines->size; i++){
		DaoRoutine *r2 = self->classRoutines->overloads->routines->items.pRoutine[i];
		DArray *types = r2->routType->nested;
		autodef = r2->parCount == 0;
		if( autodef ) break;
		for(k=0; k<types->size; k++){
			int tid = types->items.pType[k]->tid;
			if( tid != DAO_PAR_DEFAULT && tid != DAO_PAR_VALIST ) break;
		}
		autodef = k == types->size;
		if( autodef ) break;
	}
	if( autodef && self->parent ){
		if( self->parent->type == DAO_CLASS ){
			DaoClass *klass = (DaoClass*) self->parent;
			autodef = autodef && (klass->attribs & DAO_CLS_AUTO_DEFAULT);
		}else{
			autodef = 0;
		}
	}
#if 0
	printf( "%s %i\n", self->className->mbs, autodef );
#endif
	if( autodef ) self->attribs |= DAO_CLS_AUTO_DEFAULT;
	for(i=DVM_NOT; i<=DVM_BITRIT; i++){
		DString_SetMBS( mbs, daoBitBoolArithOpers[i-DVM_NOT] );
		node = DMap_Find( self->lookupTable, mbs );
		if( node == NULL ) continue;
		if( LOOKUP_ST( node->value.pInt ) != DAO_CLASS_CONSTANT ) continue;
		id = LOOKUP_ID( node->value.pInt );
		k = self->constants->items.pConst[id]->value->type;
		if( k != DAO_ROUTINE ) continue;
		self->attribs |= DAO_OPER_OVERLOADED | (DAO_OPER_OVERLOADED<<(i-DVM_NOT+1));
	}
	DString_Delete( mbs );
}
Esempio n. 30
0
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 );
}