Пример #1
0
static void ParseKeyValueStringArray( DaoProcess *proc, DaoMap *map, char **p )
{
    int nc = 0;
    char buffer[ LOCAL_BUF_SIZE + 1 ];

    DaoValue *vk = (DaoValue*) DaoProcess_NewString( proc, NULL, 0 );
    DaoValue *vv = (DaoValue*) DaoProcess_NewString( proc, NULL, 0 );
    DString *key = DaoString_Get( DaoValue_CastString( vk ) );
    DString *value = DaoString_Get( DaoValue_CastString( vv ) );
    while( *p != NULL ) {
        char *c = *p;
        nc = 0;
        while( *c != '=' ) {
            if( nc >= LOCAL_BUF_SIZE ) {
                buffer[ nc ] = 0;
                DString_AppendChars( key, buffer );
                nc = 0;
            }
            buffer[ nc ] = *c;
            nc ++;
            c ++;
        }
        buffer[ nc ] = 0;
        DString_AppendChars( key, buffer );
        c ++;
        DString_AppendChars( value, c );
        DaoMap_Insert( map, vk, vv );
        DString_Clear( key );
        DString_Clear( value );
        p ++;
    }
}
Пример #2
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 );
}
Пример #3
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 );
}
Пример #4
0
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;
}
Пример #5
0
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 );
}
Пример #6
0
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;
}
Пример #7
0
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;
}
Пример #8
0
static void Dao_AboutVars( DaoProcess *proc, DaoValue *par[], int N, DString *str )
{
	DaoVmCode *vmc = proc->activeCode;
	DaoType **types = proc->activeTypes + vmc->a + 1;
	int i;
	DString_Clear( str );
	if( vmc->code == DVM_MCALL ) types += 1;
	for( i=0; i<N; i++ ){
		Dao_AboutVar( proc, types[i], par[i], str );
		if( i+1<N ) DString_AppendChars( str, " " );
	}
}
Пример #9
0
/* 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 );
	}
}
Пример #10
0
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, " )" );
}
Пример #11
0
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;
}
Пример #12
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;
}
Пример #13
0
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;
}
Пример #14
0
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;
}
Пример #15
0
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;
}
Пример #16
0
static void DaoObject_Core_SetField( DaoValue *self0, DaoProcess *proc, DString *name, DaoValue *value )
{
	DaoObject *self = & self0->xObject;
	int ec = DaoObject_SetData( self, name, value, proc->activeObject );
	int ec2 = ec;
	if( ec != DAO_ERROR ){
		DString *mbs = proc->string;
		DString_SetChars( mbs, "." );
		DString_Append( mbs, name );
		DString_AppendChars( mbs, "=" );
		ec = DaoObject_InvokeMethod( self, proc->activeObject, proc, mbs, & value, 1,1,0 );
		if( ec == DAO_ERROR_FIELD_NOTEXIST ){
			DaoString str = {DAO_STRING,0,0,0,1,NULL};
			DaoValue *pars[2];
			pars[0] = (DaoValue*) & str;
			pars[1] = value;
			str.value = name;
			DString_SetChars( mbs, ".=" );
			ec = DaoObject_InvokeMethod( self, proc->activeObject, proc, mbs, pars,2,1,0 );
		}
		if( ec == DAO_ERROR_FIELD_NOTEXIST ) ec = ec2;
	}
	if( ec ) DaoProcess_RaiseException( proc, daoExceptionNames[ec], name->chars, NULL );
}
Пример #17
0
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;
}
Пример #18
0
int main( int argc, char **argv )
{
	int restart = 0;
	int i, k, idsrc, vmods = 0;
	DString *opts = NULL, *args = NULL;

	/*mtrace(); */

	for(i=1; i<argc; i++){
		if( strcmp( argv[i], "-r" ) ==0 || strcmp( argv[i], "--restart" ) ==0 ){
			restart = i;
			break;
		}
	}
	if( restart ) DaoRestartRun( argv, argc, restart );

	vmSpace = DaoInit( argv[0] );

	idsrc = -1;
	for(i=1; i<argc; i++){
		if( strcmp( argv[i], "-e" ) ==0 || strcmp( argv[i], "--eval" ) ==0 ) break;
		/* also allows execution of script files without suffix .dao */
		if( argv[i][0] != '-' ){
			idsrc = i;
			break;
		}
	}

#ifdef DAO_WITH_STATIC_MODULES
	/*
	// For single file deployment.
	// Identify the script argument, such that the arguments before the script
	// can be passed in as virtual machine arguments.
	// Example: ./script --restart script.dao ...
	*/
	args = DString_Copy( vmSpace->daoBinFile );
	DString_Erase( args, 0, vmSpace->daoBinPath->size );
	DString_AppendChars( args, ".dao" );
	idsrc = 1;
	for(i=1; i<argc; i++){
		if( strcmp( argv[i], args->chars ) == 0 ){
			idsrc = i;
			break;
		}
	}
	vmods = DaoVmSpace_AddVirtualModules( vmSpace, dao_virtual_modules );
	DString_Reset( args, 0 );
#endif

	k = idsrc;
	if( k < 0 ) k = argc;

	if( opts == NULL ) opts = DString_New();
	if( args == NULL ) args = DString_New();
	for(i=1; i<k; i++ ){
		DString_AppendChars( opts, argv[i] );
		DString_AppendChar( opts, '\1' );
	}
	if( idsrc >= 0 ){
#ifdef DAO_WITH_STATIC_MODULES
		idsrc += 1;
#endif
		for(i=idsrc; i<argc; i++ ){
			DString_AppendChars( args, argv[i] );
			DString_AppendChar( args, '\1' );
		}
	}
	DaoVmSpace_ParseOptions( vmSpace, DString_GetData( opts ) );

#ifdef DAO_WITH_STATIC_MODULES
	if( vmods ){
		DString_InsertChars( args, "/@/\1", 0, 0, 0 );
		DString_InsertChars( args, dao_virtual_modules[0].name, 3, 0, 0 );
		/* set the path for the virtual files: */
		DaoVmSpace_SetPath( vmSpace, "/@/" );
	}else
#endif
	if( idsrc < 0 && argc == 1 ){
		DString_AppendChar( opts, '\1' );
		DString_AppendChars( opts, "-vi" );
		DaoVmSpace_ParseOptions( vmSpace, DString_GetData( opts ) );
	}


#ifdef DAO_USE_READLINE
	DaoVmSpace_ReadLine( vmSpace, DaoReadLine );
	DaoVmSpace_AddHistory( vmSpace, (AddHistory) add_history );
	read_history( NULL );
#endif

	signal( SIGINT, DaoSignalHandler );
	signal( SIGSEGV, DaoStackTrace );

	/* Start execution. */
	k = DaoVmSpace_RunMain( vmSpace, DString_GetData( args ) );

#ifdef DAO_USE_READLINE
	write_history( NULL );
#endif

	DString_Delete( args );
	DString_Delete( opts );
	DaoQuit();
	return k;
}
Пример #19
0
int main( int argc, char **argv )
{
	int restart = 0;
	int i, k, idsrc, vmods = 0;
	DString *opts, *args;

	/*mtrace(); */

	for(i=1; i<argc; i++){
		if( strcmp( argv[i], "-r" ) ==0 || strcmp( argv[i], "--restart" ) ==0 ){
			restart = i;
			break;
		}
	}
	if( restart ) DaoRestartRun( argv, argc, restart );

	vmSpace = DaoInit( argv[0] );

	idsrc = -1;
	for(i=1; i<argc; i++){
		if( strcmp( argv[i], "-e" ) ==0 || strcmp( argv[i], "--eval" ) ==0 ) break;
		/* also allows execution of script files without suffix .dao */
		if( argv[i][0] != '-' ){
			idsrc = i;
			break;
		}
	}

#ifdef DAO_WITH_STATIC_MODULES
	idsrc = 1;
	vmods = 0;
	while( dao_virtual_modules[vmods].name ){
		DaoVmSpace_AddVirtualModule( vmSpace, & dao_virtual_modules[vmods] );
		vmods ++;
	}
#endif

	k = idsrc;
	if( k < 0 ) k = argc;

	opts = DString_New();
	args  = DString_New();
	for(i=1; i<k; i++ ){
		DString_AppendChars( opts, argv[i] );
		DString_AppendChar( opts, '\1' );
	}
	if( idsrc >= 0 ){
		for(i=idsrc; i<argc; i++ ){
			DString_AppendChars( args, argv[i] );
			DString_AppendChar( args, '\1' );
		}
	}
	DaoVmSpace_ParseOptions( vmSpace, DString_GetData( opts ) );

#ifdef DAO_WITH_STATIC_MODULES
	if( vmods ){
		DString_InsertChar( args, '\1', 0 );
		DString_InsertChars( args, dao_virtual_modules[0].name, 0, 0, 0 );
		/* set the path for the virtual files: */
		DaoVmSpace_SetPath( vmSpace, "/@/" );
	}else
#endif
	if( idsrc < 0 && argc == 1 ){
		DString_AppendChar( opts, '\1' );
		DString_AppendChars( opts, "-vi" );
		DaoVmSpace_ParseOptions( vmSpace, DString_GetData( opts ) );
	}


#ifdef DAO_USE_READLINE
	DaoVmSpace_ReadLine( vmSpace, DaoReadLine );
	DaoVmSpace_AddHistory( vmSpace, (AddHistory) add_history );
	read_history( NULL );
#endif

	signal( SIGINT, DaoSignalHandler );

	/* Start execution. */
	k = ! DaoVmSpace_RunMain( vmSpace, DString_GetData( args ) );

#ifdef DAO_USE_READLINE
	write_history( NULL );
#endif

	DString_Delete( args );
	DString_Delete( opts );
	DaoQuit();
	return k;
}