void asCRestore::ReadDataType(asCDataType *dt) 
{
	eTokenType tokenType;
	READ_NUM(tokenType);
	asCObjectType *objType = ReadObjectType();
	bool isObjectHandle;
	READ_NUM(isObjectHandle);
	bool isReadOnly;
	READ_NUM(isReadOnly);
	bool isHandleToConst;
	READ_NUM(isHandleToConst);
	bool isReference;
	READ_NUM(isReference);

	if( tokenType == ttIdentifier )
		*dt = asCDataType::CreateObject(objType, false);
	else
		*dt = asCDataType::CreatePrimitive(tokenType, false);
	if( isObjectHandle )
	{
		dt->MakeReadOnly(isHandleToConst);
		dt->MakeHandle(true);
	}
	dt->MakeReadOnly(isReadOnly);
	dt->MakeReference(isReference);
}
Example #2
0
void asCRestore::ReadByteCode(asDWORD *bc, int length)
{
	while( length )
	{
		asDWORD c;
		READ_NUM(c);
		*bc = asDWORD(c);
		bc += 1;
		c &= 0xFF;
		if( c == BC_ALLOC || c == BC_FREE ||
			c == BC_REFCPY || c == BC_OBJTYPE )
		{
			// Translate the index to the true object type
			asDWORD tmp[MAX_DATA_SIZE];
			int n;
			for( n = 0; n < asCByteCode::SizeOfType(bcTypes[c])-1; n++ )
				READ_NUM(tmp[n]);

			*(asCObjectType**)tmp = FindObjectType(*(int*)tmp);

			for( n = 0; n < asCByteCode::SizeOfType(bcTypes[c])-1; n++ )
				*bc++ = tmp[n];
		}
		else
		{
			// Read the bc as is
			for( int n = 1; n < asCByteCode::SizeOfType(bcTypes[c]); n++ )
				READ_NUM(*bc++);
		}

		length -= asCByteCode::SizeOfType(bcTypes[c]);
	}
}
Example #3
0
void asCRestore::ReadFunctionSignature(asCScriptFunction *func)
{
	int i, count;
	asCDataType dt;
	int num;

	ReadString(&func->name);
	ReadDataType(&func->returnType);
	READ_NUM(count);
	func->parameterTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		ReadDataType(&dt);
		func->parameterTypes.PushLast(dt);
	}

	READ_NUM(count);
	func->inOutFlags.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		READ_NUM(num);
		func->inOutFlags.PushLast(static_cast<asETypeModifiers>(num));
	}

	READ_NUM(func->funcType);

	func->objectType = ReadObjectType();

	READ_NUM(func->isReadOnly);
}
void *READ_IV(FILE *inputFile){
	int i, element, vetSize = -1;
	IntVector *vet = NULL;

	READ_BEGIN(inputFile);
		
	// Read data size from disk
	READ_NUM("vetSize", vetSize);
	if(vetSize == -1)fprintf(stderr,"Error: Reading vector Size\n");

	vet = intVectorCreate(vetSize); 
		
	for(i = 0; i< vetSize; i++){
		element = -2;
		READ_NUM("element", element);
		if(element == -1){
			fprintf(stderr,"Error: Reading vector\n");
			return NULL;
		}
		intVectorAdd(vet, element);


	}
	READ_END
	return ((void *) vet);
}
Example #5
0
void *readTask(FILE *inputFile){
	Task *task = createTask();
	TaskIdList *list = NULL;
	int endedTasks=-1, metaSize=-1, taskState=-1, id=-1;
	char *metadata = NULL;

	READ_BEGIN(inputFile);

	list = (TaskIdList *)readTaskIdList(inputFile);
	setTaskDependsOnMe(task, list);
	taskIdListDestroy(list);

	list = (TaskIdList *)readTaskIdList(inputFile);
	setTaskMyDeps(task, list);
	taskIdListDestroy(list);
	
	hashIntVoidDeserialize(inputFile, task->children);

	// make the children point to its mother
	HashIntVoidIterator *it = createHashIntVoidIterator(task->children, 0);
	PosHandlerIntVoid pos = hashIntVoidIteratorNext(it, task->children);
	while (pos != NULL) {
		Task *child = posGetValue(pos);
		child->mother = task;
		
		pos = hashIntVoidIteratorNext(it, task->children);
	}
	hashIntVoidIteratorDestroy(it, task->children);

	READ_NUM("id", id);
	setTaskId(task, id);

	READ_NUM("endedTasks", endedTasks);
	setTaskEndedTasks(task, endedTasks);

	READ_NUM("metaSize", metaSize);
	if (metaSize > 0) {
		metadata = malloc(metaSize);
	} else {
		metadata = NULL;	
	}
	READ_BYTES(inputFile, metadata, metaSize);
	setTaskMetadata(task, metadata, metaSize);
	if(metadata != NULL){
		free(metadata);
	}

	READ_NUM("taskState", taskState);
	setTaskState(task, taskState);
	
	DataSpace* dataSpace = createDataSpace();	
	readDataSpace(inputFile, dataSpace);

	setTaskDataSpace(task, dataSpace);
	
	READ_END
	return (void *)task;
}
Example #6
0
void char_seq_to_iv(char *s, intval *iv, int *plen, enum base mode)
{
#define READ_NUM(test, base)             \
			do{                                \
				if(!(test))                      \
					break;                         \
				lval = base * lval + *s - '0';   \
				s++;                             \
				while(*s == '_')                 \
					s++;                           \
			}while(1)

	char *const start = s;
	long lval = 0;

	switch(mode){
		case BIN:
			READ_NUM(*s == '0' || *s == '1', 2);
			break;

		case DEC:
			READ_NUM(isdigit(*s), 10);
			break;

		case OCT:
			READ_NUM(isoct(*s), 010);
			break;

		case HEX:
		{
			int charsread = 0;
			do{
				if(isxdigit(*s)){
					lval = 0x10 * lval + (isdigit(tolower(*s)) ? *s - '0' : 10 + tolower(*s) - 'a');
					s++;
				}else{
					break;
				}
				charsread++;
				while(*s == '_')
					s++;
			}while(1);

			if(charsread < 1)
				DIE_AT(NULL, "invalid hex char (read 0 chars, at \"%s\")", s);
			break;
		}
	}

	iv->val = lval;
	*plen = s - start;
}
Example #7
0
void asCRestore::ReadUsedFunctions()
{
	asUINT count;
	READ_NUM(count);
	usedFunctions.SetLength(count);

	for( asUINT n = 0; n < usedFunctions.GetLength(); n++ )
	{
		char c;

		// Read the data to be able to uniquely identify the function

		// Is the function from the module or the application?
		READ_NUM(c);

		asCScriptFunction func(engine, c == 'm' ? module : 0, -1);
		ReadFunctionSignature(&func);

		// Find the correct function
		if( c == 'm' )
		{
			for( asUINT i = 0; i < module->scriptFunctions.GetLength(); i++ )
			{
				asCScriptFunction *f = module->scriptFunctions[i];
				if( !func.IsSignatureEqual(f) ||
					func.objectType != f->objectType ||
					func.funcType != f->funcType )
					continue;

				usedFunctions[n] = f;
				break;
			}
		}
		else
		{
			for( asUINT i = 0; i < engine->scriptFunctions.GetLength(); i++ )
			{
				asCScriptFunction *f = engine->scriptFunctions[i];
				if( f == 0 ||
					!func.IsSignatureEqual(f) ||
					func.objectType != f->objectType )
					continue;

				usedFunctions[n] = f;
				break;
			}
		}

		// Set the type to dummy so it won't try to release the id
		func.funcType = -1;
	}
}
void asCRestore::ReadUsedGlobalProps()
{
	int c;
	READ_NUM(c);

	usedGlobalProperties.SetLength(c);

	for( int n = 0; n < c; n++ )
	{
		asCString name;
		asCDataType type;
		char moduleProp;

		ReadString(&name);
		ReadDataType(&type);
		READ_NUM(moduleProp);

		// Find the real property
		void *prop = 0;
		if( moduleProp )
		{
			for( asUINT p = 0; p < module->scriptGlobals.GetLength(); p++ )
			{
				if( module->scriptGlobals[p]->name == name &&
					module->scriptGlobals[p]->type == type )
				{
					prop = module->scriptGlobals[p]->GetAddressOfValue();
					break;
				}
			}
		}
		else
		{
			for( asUINT p = 0; p < engine->registeredGlobalProps.GetLength(); p++ )
			{
				if( engine->registeredGlobalProps[p] &&
					engine->registeredGlobalProps[p]->name == name &&
					engine->registeredGlobalProps[p]->type == type )
				{
					prop = engine->registeredGlobalProps[p]->GetAddressOfValue();
					break;
				}
			}
		}

		// TODO: If the property isn't found, we must give an error
		asASSERT(prop);

		usedGlobalProperties[n] = prop;
	}
}
void asCRestore::ReadGlobalVarPointers()
{
	int c;
	READ_NUM(c);

	module->globalVarPointers.SetLength(c);

	for( int n = 0; n < c; n++ )
	{
		int idx;
		READ_NUM(idx);

		// This will later on be translated into the true pointer
		module->globalVarPointers[n] = (void*)(size_t)idx;
	}
}
Example #10
0
void asCRestore::ReadString(asCString* str) 
{
	unsigned long len;
	READ_NUM(len);
	str->SetLength(len);
	stream->Read(str->AddressOf(), len);
}
void asCRestore::ReadByteCode(asDWORD *bc, int length)
{
	while( length )
	{
		asDWORD c;
		READ_NUM(c);
		*bc = c;
		bc += 1;
		c = *(asBYTE*)&c;

		// Read the bc as is
		for( int n = 1; n < asBCTypeSize[asBCInfo[c].type]; n++ )
			READ_NUM(*bc++);

		length -= asBCTypeSize[asBCInfo[c].type];
	}
}
Example #12
0
void asCRestore::ReadGlobalVarPointers()
{
	int c;
	READ_NUM(c);

	module->globalVarPointers.SetLength(c);

	for( int n = 0; n < c; n++ )
	{
		int idx;
		READ_NUM(idx);

		if( idx < 0 ) 
			module->globalVarPointers[n] = (void*)(engine->globalPropAddresses[-idx - 1]);
		else
			module->globalVarPointers[n] = (void*)(module->globalMem.AddressOf() + idx);
	}
}
Example #13
0
asCObjectType* asCRestore::ReadObjectType() 
{
	asCObjectType *ot;
	char ch;
	READ_NUM(ch);
	if( ch == 'a' )
	{
		READ_NUM(ch);
		if( ch == 's' )
		{
			ot = ReadObjectType();
			asCDataType dt = asCDataType::CreateObject(ot, false);

			READ_NUM(ch);
			if( ch == 'h' )
				dt.MakeHandle(true);

			dt.MakeArray(engine);
			ot = dt.GetObjectType();
		}
		else
		{
			eTokenType tokenType;
			READ_NUM(tokenType);
			asCDataType dt = asCDataType::CreatePrimitive(tokenType, false);
			dt.MakeArray(engine);
			ot = dt.GetObjectType();
		}
	}
	else
	{
		// Read the object type name
		asCString typeName;
		ReadString(&typeName);

		// Find the object type
		ot = module->GetObjectType(typeName.AddressOf());
		if( !ot )
			ot = engine->GetObjectType(typeName.AddressOf());
	}

	return ot;
}
Example #14
0
void asCRestore::ReadObjectTypeDeclaration(asCObjectType *ot)
{
	// name
	ReadString(&ot->name);
	// size
	int size;
	READ_NUM(size);
	ot->size = size;
	// properties[]
	READ_NUM(size);
	ot->properties.Allocate(size,0);
	for( int n = 0; n < size; n++ )
	{
		asCProperty *prop = new asCProperty;
		ReadProperty(prop);
		ot->properties.PushLast(prop);
	}

	// Use the default script struct behaviours
	ot->beh.construct = engine->scriptTypeBehaviours.beh.construct;
	ot->beh.constructors.PushLast(ot->beh.construct);
	ot->beh.addref = engine->scriptTypeBehaviours.beh.addref;
	ot->beh.release = engine->scriptTypeBehaviours.beh.release;
	ot->beh.copy = engine->scriptTypeBehaviours.beh.copy;
	ot->beh.operators.PushLast(ttAssignment);
	ot->beh.operators.PushLast(ot->beh.copy);

	// Some implicit values
	ot->tokenType = ttIdentifier;
	ot->arrayType = 0;
	ot->flags = asOBJ_CLASS_CDA | asOBJ_SCRIPT_STRUCT;

	// TODO: The flag asOBJ_POTENTIAL_CIRCLE must be saved

	// TODO: What about the arrays? the flag must be saved as well

	// TODO:
	// methods[]
}
void asCRestore::ReadUsedTypeIds()
{
	asUINT n;
	asUINT count;
	READ_NUM(count);
	usedTypeIds.SetLength(count);
	for( n = 0; n < count; n++ )
	{
		asCDataType dt;
		ReadDataType(&dt);
		usedTypeIds[n] = engine->GetTypeIdFromDataType(dt);
	}
}
Example #16
0
void asCRestore::ReadUsedStringConstants()
{
	asCString str;

	asUINT count;
	READ_NUM(count);
	usedStringConstants.SetLength(count);
	for( asUINT i = 0; i < count; ++i ) 
	{
		ReadString(&str);
		usedStringConstants[i] = engine->AddConstantString(str.AddressOf(), str.GetLength());
	}
}
Example #17
0
void *readChildTask(FILE *inputFile){
	Task *task = createTask();
	TaskIdList *list = NULL;
	int metaSize = 0;
	char *metadata = NULL;
	int id = -1;

	READ_BEGIN(inputFile);

	list = (TaskIdList *)readTaskIdList(inputFile);
	setTaskDependsOnMe(task, list);
	taskIdListDestroy(list);

	list = (TaskIdList *)readTaskIdList(inputFile);
	setTaskMyDeps(task, list);
	taskIdListDestroy(list);

	READ_NUM("id", id);
	setTaskId(task, id);
	assert(id != -1);

	READ_NUM("metaSize", metaSize);
	if (metaSize > 0) {
		metadata = malloc(metaSize);
	} else {
		metadata = NULL;	
	}
	READ_BYTES(inputFile, metadata, metaSize);
	setTaskMetadata(task, metadata, metaSize);
	if(metadata != NULL){
		free(metadata);
	}
		
	READ_END
	return (void *)task;
}
Example #18
0
void asCRestore::ReadFunction(asCScriptFunction* func) 
{
	int i, count;
	asCDataType dt;
	int num;

	ReadString(&func->name);

	ReadDataType(&func->returnType);

	READ_NUM(count);
	func->parameterTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		ReadDataType(&dt);
		func->parameterTypes.PushLast(dt);
	}

	READ_NUM(func->id);
	
	READ_NUM(count);
	func->byteCode.Allocate(count, 0);
	ReadByteCode(func->byteCode.AddressOf(), count);
	func->byteCode.SetLength(count);

	READ_NUM(count);
	func->objVariablePos.Allocate(count, 0);
	func->objVariableTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		func->objVariableTypes.PushLast(ReadObjectType());
		READ_NUM(num);
		func->objVariablePos.PushLast(num);
	}

	READ_NUM(func->stackNeeded);

	func->objectType = ReadObjectType();

	int length;
	READ_NUM(length);
	func->lineNumbers.SetLength(length);
	for( i = 0; i < length; ++i )
		READ_NUM(func->lineNumbers[i]);
}
Example #19
0
void asCRestore::ReadUsedTypeIds()
{
	asUINT n;
	asUINT count;
	READ_NUM(count);
	usedTypeIds.SetLength(count);
	for( n = 0; n < count; n++ )
	{
		asCDataType dt;
		ReadDataType(&dt);
		usedTypeIds[n] = engine->GetTypeIdFromDataType(dt);
	}

	// Translate all the TYPEID bytecodes
	TranslateFunction(&module->initFunction);
	for( n = 0; n < module->scriptFunctions.GetLength(); n++ )
		TranslateFunction(module->scriptFunctions[n]);
}
Example #20
0
void main()
{
	int NUM,I,VALUE[50];
	int driver=DETECT,mode;

	registerbgidriver(EGAVGA_driver);
	initgraph(&driver,&mode,"");

	NUM=READ_NUM();
	for(I=1;I<=NUM;I++)
		VALUE[I]=READ_HIGHT(I);
	setcolor(WHITE);
	line(0,400,639,400);
	setcolor(YELLOW);
	setfillstyle(1,BLUE);
	for(I=1;I<=NUM;I++)
		bar3d(I*10,400-VALUE[I],(I+1)*10,400,10,1);
	getch();
	closegraph();
}
Example #21
0
asCScriptFunction *asCRestore::ReadFunction(bool addToModule, bool addToEngine) 
{
	char c;
	READ_NUM(c);

	if( c == '\0' )
	{
		// There is no function, so return a null pointer
		return 0;
	}

	if( c == 'r' )
	{
		// This is a reference to a previously saved function
		int index;
		READ_NUM(index);

		return savedFunctions[index];
	}

	// Load the new function
	asCScriptFunction *func = asNEW(asCScriptFunction)(engine,module,-1);
	savedFunctions.PushLast(func);

	int i, count;
	asCDataType dt;
	int num;

	ReadFunctionSignature(func);

	if( func->funcType == asFUNC_SCRIPT )
		engine->gc.AddScriptObjectToGC(func, &engine->functionBehaviours);

	func->id = engine->GetNextScriptFunctionId();
	
	READ_NUM(count);
	func->byteCode.Allocate(count, 0);
	ReadByteCode(func->byteCode.AddressOf(), count);
	func->byteCode.SetLength(count);

	READ_NUM(count);
	func->objVariablePos.Allocate(count, 0);
	func->objVariableTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		func->objVariableTypes.PushLast(ReadObjectType());
		READ_NUM(num);
		func->objVariablePos.PushLast(num);
	}

	READ_NUM(func->stackNeeded);

	int length;
	READ_NUM(length);
	func->lineNumbers.SetLength(length);
	for( i = 0; i < length; ++i )
		READ_NUM(func->lineNumbers[i]);

	READ_NUM(func->vfTableIdx);

	if( addToModule )
	{
		// The refCount is already 1
		module->scriptFunctions.PushLast(func);
	}
	if( addToEngine )
		engine->SetScriptFunction(func);
	if( func->objectType )
		func->ComputeSignatureId();

	ReadGlobalVarPointers(func);

	return func;
}
void asCRestore::ReadObjectTypeDeclaration(asCObjectType *ot, bool readProperties)
{
	if( !readProperties )
	{
		// name
		ReadString(&ot->name);
		// size
		int size;
		READ_NUM(size);
		ot->size = size;
		// flags
		asDWORD flags;
		READ_NUM(flags);
		ot->flags = flags;

		// Use the default script class behaviours
		ot->beh = engine->scriptTypeBehaviours.beh;
	}
	else
	{	
		if( ot->flags & asOBJ_ENUM )
		{
			int count;
			READ_NUM(count);
			ot->enumValues.Allocate(count, 0);
			for( int n = 0; n < count; n++ )
			{
				asSEnumValue *e = asNEW(asSEnumValue);
				ReadString(&e->name);
				READ_NUM(e->value);
				ot->enumValues.PushLast(e);
			}
		}
		else if( ot->flags & asOBJ_TYPEDEF )
		{
			eTokenType t;
			READ_NUM(t);
			ot->templateSubType = asCDataType::CreatePrimitive(t, false);
		}
		else
		{
			ot->derivedFrom = ReadObjectType();
			if( ot->derivedFrom )
				ot->derivedFrom->AddRef();

			// interfaces[]
			int size;
			READ_NUM(size);
			ot->interfaces.Allocate(size,0);
			int n;
			for( n = 0; n < size; n++ )
			{
				asCObjectType *intf = ReadObjectType();
				ot->interfaces.PushLast(intf);
			}

			// properties[]
			READ_NUM(size);
			ot->properties.Allocate(size,0);
			for( n = 0; n < size; n++ )
			{
				asCObjectProperty *prop = asNEW(asCObjectProperty);
				ReadObjectProperty(prop);
				ot->properties.PushLast(prop);
			}

			// behaviours
			if( !ot->IsInterface() && ot->flags != asOBJ_TYPEDEF && ot->flags != asOBJ_ENUM )
			{
				asCScriptFunction *func = ReadFunction();
				ot->beh.construct = func->id;
				ot->beh.constructors[0] = func->id;

				func = ReadFunction();
				if( func )
					ot->beh.destruct = func->id;

				func = ReadFunction();
				ot->beh.factory = func->id;
				ot->beh.factories[0] = func->id;

				READ_NUM(size);
				for( n = 0; n < size; n++ )
				{
					asCScriptFunction *func = ReadFunction();
					ot->beh.constructors.PushLast(func->id);

					func = ReadFunction();
					ot->beh.factories.PushLast(func->id);
				}
			}

			// methods[]
			READ_NUM(size);
			for( n = 0; n < size; n++ ) 
			{
				asCScriptFunction *func = ReadFunction();
				ot->methods.PushLast(func->id);
			}

			// virtualFunctionTable[]
			READ_NUM(size);
			for( n = 0; n < size; n++ )
			{
				asCScriptFunction *func = ReadFunction();
				ot->virtualFunctionTable.PushLast(func);
			}
		}
	}
}
int asCRestore::Restore() 
{
	// Before starting the load, make sure that 
	// any existing resources have been freed
	module->InternalReset();

	unsigned long i, count;

	asCScriptFunction* func;
	asCString *cstr;

	// Read enums
	READ_NUM(count);
	module->enumTypes.Allocate(count, 0);
	for( i = 0; i < count; i++ )
	{
		asCObjectType *ot = asNEW(asCObjectType)(engine);
		ReadObjectTypeDeclaration(ot, false);
		engine->classTypes.PushLast(ot);
		module->enumTypes.PushLast(ot);
		ot->AddRef();
		ReadObjectTypeDeclaration(ot, true);
	}

	// structTypes[]
	// First restore the structure names, then the properties
	READ_NUM(count);
	module->classTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		asCObjectType *ot = asNEW(asCObjectType)(engine);
		ReadObjectTypeDeclaration(ot, false);
		engine->classTypes.PushLast(ot);
		module->classTypes.PushLast(ot);
		ot->AddRef();
	}

	// Read interface methods
	for( i = 0; i < module->classTypes.GetLength(); i++ )
	{
		if( module->classTypes[i]->IsInterface() )
			ReadObjectTypeDeclaration(module->classTypes[i], true);
	}

	module->ResolveInterfaceIds();

	// Read class methods, properties, and behaviours
	for( i = 0; i < module->classTypes.GetLength(); ++i )
	{
		if( !module->classTypes[i]->IsInterface() )
			ReadObjectTypeDeclaration(module->classTypes[i], true);
	}

	// Read typedefs
	READ_NUM(count);
	module->typeDefs.Allocate(count, 0);
	for( i = 0; i < count; i++ )
	{
		asCObjectType *ot = asNEW(asCObjectType)(engine);
		ReadObjectTypeDeclaration(ot, false);
		engine->classTypes.PushLast(ot);
		module->typeDefs.PushLast(ot);
		ot->AddRef();
		ReadObjectTypeDeclaration(ot, true);
	}

	// scriptGlobals[]
	READ_NUM(count);
	module->scriptGlobals.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		ReadGlobalProperty();
	}

	// globalVarPointers[]
	ReadGlobalVarPointers();

	// scriptFunctions[]
	READ_NUM(count);
	for( i = 0; i < count; ++i ) 
	{
		func = ReadFunction();
	}

	// globalFunctions[]
	READ_NUM(count);
	for( i = 0; i < count; ++i )
	{
		func = ReadFunction(false, false);
		module->globalFunctions.PushLast(func);
	}

	// initFunction
	READ_NUM(count);
	if( count )
	{
		module->initFunction = ReadFunction(false, true);
	}

	// stringConstants[]
	READ_NUM(count);
	module->stringConstants.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		cstr = asNEW(asCString)();
		ReadString(cstr);
		module->stringConstants.PushLast(cstr);
	}
	
	// importedFunctions[] and bindInformations[]
	READ_NUM(count);
	module->importedFunctions.Allocate(count, 0);
	module->bindInformations.SetLength(count);
	for(i=0;i<count;++i)
	{
		func = ReadFunction(false, false);
		module->importedFunctions.PushLast(func);

		sBindInfo *info = asNEW(sBindInfo);
		ReadString(&info->importFromModule);
		info->importedFunction = -1;
		module->bindInformations[i] = info;
	}
	
	// usedTypes[]
	READ_NUM(count);
	usedTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		asCObjectType *ot = ReadObjectType();
		usedTypes.PushLast(ot);
	}

	// usedTypeIds[]
	ReadUsedTypeIds();

	// usedFunctions[]
	ReadUsedFunctions();

	// usedGlobalProperties[]
	ReadUsedGlobalProps();

	// TODO: global: The module won't have a globalVarPointers anymore, instead each script 
	//               function has its own array so this should be moved into TranslateFunction
	// Translate the module->globalVarPointers
	for( i = 0; i < module->globalVarPointers.GetLength(); i++ )
	{
		module->globalVarPointers[i] = usedGlobalProperties[(int)(size_t)module->globalVarPointers[i]];
	}

	if( module->initFunction ) 
		TranslateFunction(module->initFunction);
	for( i = 0; i < module->scriptFunctions.GetLength(); i++ )
		TranslateFunction(module->scriptFunctions[i]);

	// Fake building
	module->isBuildWithoutErrors = true;

	// Init system functions properly
	engine->PrepareEngine();

	// Add references for all functions
	if( module->initFunction )
		module->initFunction->AddReferences();
	for( i = 0; i < module->scriptFunctions.GetLength(); i++ )
	{
		module->scriptFunctions[i]->AddReferences();
	}

	module->CallInit();

	return 0;
}
Example #24
0
// NEXT: Must go through the bytecode and set the correct objecttype pointer where used
int asCRestore::Restore() 
{
	// Before starting the load, make sure that 
	// any existing resources have been freed
	module->Reset();

	unsigned long i, count;

	asCScriptFunction* func;
	asCProperty* prop;
	asCString *cstr;

	// structTypes[]
	READ_NUM(count);
	module->structTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		asCObjectType *ot = new asCObjectType(engine);
		ReadObjectTypeDeclaration(ot);
		engine->structTypes.PushLast(ot);
		module->structTypes.PushLast(ot);
		ot->refCount++;
	}

	// usedTypes[]
	READ_NUM(count);
	module->usedTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		asCObjectType *ot = ReadObjectType();
		module->usedTypes.PushLast(ot);
		ot->refCount++;		
	}

	// scriptGlobals[]
	READ_NUM(count);
	module->scriptGlobals.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		prop = new asCProperty;
		ReadProperty(prop);
		module->scriptGlobals.PushLast(prop);
	}

	// globalMem size
	READ_NUM(count);
	module->globalMem.SetLength(count);

	// globalVarPointers[]
	ReadGlobalVarPointers();

	// initFunction
	ReadFunction(&module->initFunction);

	// scriptFunctions[]
	READ_NUM(count);
	module->scriptFunctions.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		func = new asCScriptFunction;
		ReadFunction(func);
		module->scriptFunctions.PushLast(func);
	}

	// stringConstants[]
	READ_NUM(count);
	module->stringConstants.Allocate(count, 0);
	for(i=0;i<count;++i) 
	{
		cstr = new asCString();
		ReadString(cstr);
		module->stringConstants.PushLast(cstr);
	}
	
	// importedFunctions[] and bindInformations[]
	READ_NUM(count);
	module->importedFunctions.Allocate(count, 0);
	module->bindInformations.SetLength(count);
	for(i=0;i<count;++i)
	{
		func = new asCScriptFunction;
		ReadFunction(func);
		module->importedFunctions.PushLast(func);

		READ_NUM(module->bindInformations[i].importFrom);
		module->bindInformations[i].importedFunction = -1;
	}
	
	// usedTypeIds[]
	ReadUsedTypeIds();

	// Fake building
	module->isBuildWithoutErrors = true;

	// Init system functions properly
	engine->PrepareEngine();

	module->CallInit();

	return 0;
}
Example #25
0
int asCRestore::Restore() 
{
	// Before starting the load, make sure that 
	// any existing resources have been freed
	module->InternalReset();

	unsigned long i, count;

	asCScriptFunction* func;

	// Read enums
	READ_NUM(count);
	module->enumTypes.Allocate(count, 0);
	for( i = 0; i < count; i++ )
	{
		asCObjectType *ot = asNEW(asCObjectType)(engine);
		ReadObjectTypeDeclaration(ot, false);
		engine->classTypes.PushLast(ot);
		module->enumTypes.PushLast(ot);
		ot->AddRef();
		ReadObjectTypeDeclaration(ot, true);
	}

	// structTypes[]
	// First restore the structure names, then the properties
	READ_NUM(count);
	module->classTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		asCObjectType *ot = asNEW(asCObjectType)(engine);
		ReadObjectTypeDeclaration(ot, false);
		engine->classTypes.PushLast(ot);
		module->classTypes.PushLast(ot);
		ot->AddRef();

		// Add script classes to the GC
		if( (ot->GetFlags() & asOBJ_SCRIPT_OBJECT) && ot->GetSize() > 0 )
			engine->gc.AddScriptObjectToGC(ot, &engine->objectTypeBehaviours);
	}

	// Read interface methods
	for( i = 0; i < module->classTypes.GetLength(); i++ )
	{
		if( module->classTypes[i]->IsInterface() )
			ReadObjectTypeDeclaration(module->classTypes[i], true);
	}

	module->ResolveInterfaceIds();

	// Read class methods, properties, and behaviours
	for( i = 0; i < module->classTypes.GetLength(); ++i )
	{
		if( !module->classTypes[i]->IsInterface() )
			ReadObjectTypeDeclaration(module->classTypes[i], true);
	}

	// Read typedefs
	READ_NUM(count);
	module->typeDefs.Allocate(count, 0);
	for( i = 0; i < count; i++ )
	{
		asCObjectType *ot = asNEW(asCObjectType)(engine);
		ReadObjectTypeDeclaration(ot, false);
		engine->classTypes.PushLast(ot);
		module->typeDefs.PushLast(ot);
		ot->AddRef();
		ReadObjectTypeDeclaration(ot, true);
	}

	// scriptGlobals[]
	READ_NUM(count);
	module->scriptGlobals.Allocate(count, 0);
	for( i = 0; i < count; ++i ) 
	{
		ReadGlobalProperty();
	}

	// scriptFunctions[]
	READ_NUM(count);
	for( i = 0; i < count; ++i ) 
	{
		func = ReadFunction();
	}

	// globalFunctions[]
	READ_NUM(count);
	for( i = 0; i < count; ++i )
	{
		func = ReadFunction(false, false);

		module->globalFunctions.PushLast(func);
		func->AddRef();
	}

	// bindInformations[]
	READ_NUM(count);
	module->bindInformations.SetLength(count);
	for(i=0;i<count;++i)
	{
		sBindInfo *info = asNEW(sBindInfo);
		info->importedFunctionSignature = ReadFunction(false, false);
		info->importedFunctionSignature->id = int(FUNC_IMPORTED + engine->importedFunctions.GetLength());
		engine->importedFunctions.PushLast(info);
		ReadString(&info->importFromModule);
		info->boundFunctionId = -1;
		module->bindInformations[i] = info;
	}
	
	// usedTypes[]
	READ_NUM(count);
	usedTypes.Allocate(count, 0);
	for( i = 0; i < count; ++i )
	{
		asCObjectType *ot = ReadObjectType();
		usedTypes.PushLast(ot);
	}

	// usedTypeIds[]
	ReadUsedTypeIds();

	// usedFunctions[]
	ReadUsedFunctions();

	// usedGlobalProperties[]
	ReadUsedGlobalProps();

	// usedStringConstants[]
	ReadUsedStringConstants();

	for( i = 0; i < module->scriptFunctions.GetLength(); i++ )
		TranslateFunction(module->scriptFunctions[i]);
	for( i = 0; i < module->scriptGlobals.GetLength(); i++ )
		if( module->scriptGlobals[i]->initFunc )
			TranslateFunction(module->scriptGlobals[i]->initFunc);

	// Init system functions properly
	engine->PrepareEngine();

	// Add references for all functions
	for( i = 0; i < module->scriptFunctions.GetLength(); i++ )
		module->scriptFunctions[i]->AddReferences();
	for( i = 0; i < module->scriptGlobals.GetLength(); i++ )
		if( module->scriptGlobals[i]->initFunc )
			module->scriptGlobals[i]->initFunc->AddReferences();

	module->CallInit();

	return 0;
}
void asCRestore::ReadObjectProperty(asCObjectProperty* prop) 
{
	ReadString(&prop->name);
	ReadDataType(&prop->type);
	READ_NUM(prop->byteOffset);
}
Example #27
0
void asCRestore::ReadProperty(asCProperty* prop) 
{
	ReadString(&prop->name);
	ReadDataType(&prop->type);
	READ_NUM(prop->index);
}
asCObjectType* asCRestore::ReadObjectType() 
{
	asCObjectType *ot;
	char ch;
	READ_NUM(ch);
	if( ch == 'a' )
	{
		READ_NUM(ch);
		if( ch == 's' )
		{
			ot = ReadObjectType();
			asCDataType dt = asCDataType::CreateObject(ot, false);

			READ_NUM(ch);
			if( ch == 'h' )
				dt.MakeHandle(true);

			dt.MakeArray(engine);
			ot = dt.GetObjectType();
			
			asASSERT(ot);
		}
		else
		{
			eTokenType tokenType;
			READ_NUM(tokenType);
			asCDataType dt = asCDataType::CreatePrimitive(tokenType, false);
			dt.MakeArray(engine);
			ot = dt.GetObjectType();
			
			asASSERT(ot);
		}
	}
	else if( ch == 's' )
	{
		// Read the name of the template subtype
		asCString typeName;
		ReadString(&typeName);

		// Find the template subtype
		for( asUINT n = 0; n < engine->templateSubTypes.GetLength(); n++ )
		{
			if( engine->templateSubTypes[n] && engine->templateSubTypes[n]->name == typeName )
			{
				ot = engine->templateSubTypes[n];
				break;
			}
		}

		// TODO: Should give a friendly error in case the template type isn't found
		asASSERT(ot);
	}
	else
	{
		// Read the object type name
		asCString typeName;
		ReadString(&typeName);

		if( typeName.GetLength() && typeName != "_builtin_object_" )
		{
			// Find the object type
			ot = module->GetObjectType(typeName.AddressOf());
			if( !ot )
				ot = engine->GetObjectType(typeName.AddressOf());
			
			asASSERT(ot);
		}
		else if( typeName == "_builtin_object_" )
		{
			ot = &engine->scriptTypeBehaviours;
		}
		else
			ot = 0;
	}

	return ot;
}