Beispiel #1
0
tAsyncCall* System_Enum_Internal_GetInfo(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tMD_TypeDef *pEnumType = RuntimeType_DeRef((PTR)((tMD_TypeDef**)pParams)[0]);
	U32 i, retIndex;
	HEAP_PTR names, values;

	// An enum type always has just one non-literal field, with all other fields being the values.
	names = SystemArray_NewVector(types[TYPE_SYSTEM_ARRAY_STRING], pEnumType->numFields - 1);
	values = SystemArray_NewVector(types[TYPE_SYSTEM_ARRAY_INT32], pEnumType->numFields - 1);
	
	for (i=0, retIndex=0; i<pEnumType->numFields; i++) {
		tMD_FieldDef *pField = pEnumType->ppFields[i];
		HEAP_PTR name;
		I32 value;

		if (!FIELD_ISLITERAL(pField)) {
			continue;
		}

		name = SystemString_FromCharPtrASCII(pField->name);
		SystemArray_StoreElement(names, retIndex, (PTR)&name);
		MetaData_GetConstant(pField->pMetaData, pField->tableIndex, (PTR)&value);
		SystemArray_StoreElement(values, retIndex, (PTR)&value);
		retIndex++;
	}

	*(((HEAP_PTR**)pParams)[1]) = names;
	*(((HEAP_PTR**)pParams)[2]) = values;

	return NULL;
}
// Get all the fields in the value-types in the parameters.
// If the 2nd parameter is NULL, then don't include it!
// The type of the objects will always be identical.
tAsyncCall* System_ValueType_GetFields(PTR pThis_, PTR pParams, PTR pReturnValue) {
	HEAP_PTR o1,o2, ret;
	tMD_TypeDef *pType;
	tMetaData *pMetaData;
	U32 i, retOfs, numInstanceFields;

	o1 = ((HEAP_PTR*)pParams)[0];
	o2 = ((HEAP_PTR*)pParams)[1];
	pType = Heap_GetType(o1);
	pMetaData = pType->pMetaData;

	numInstanceFields = 0;
	for (i=0; i<pType->numFields; i++) {
		if (!FIELD_ISSTATIC(pType->ppFields[i])) {
			numInstanceFields++;
		}
	}

	ret = SystemArray_NewVector(types[TYPE_SYSTEM_ARRAY_OBJECT], numInstanceFields << ((o2 == NULL)?0:1));

	retOfs = 0;
	for (i=0; i<pType->numFields; i++) {
		tMD_FieldDef *pField;

		pField = pType->ppFields[i];
		if (!FIELD_ISSTATIC(pField)) {
			if (pField->pType->isValueType) {
				HEAP_PTR boxed;

				boxed = Heap_Box(pField->pType, o1 + pField->memOffset);
				SystemArray_StoreElement(ret, retOfs++, (PTR)&boxed);
				if (o2 != NULL) {
					boxed = Heap_Box(pField->pType, o2 + pField->memOffset);
					SystemArray_StoreElement(ret, retOfs++, (PTR)&boxed);
				}
			} else {
				SystemArray_StoreElement(ret, retOfs++, o1 + pField->memOffset);
				if (o2 != NULL) {
					SystemArray_StoreElement(ret, retOfs++, o2 + pField->memOffset);
				}
			}
		}
	}

	*(HEAP_PTR*)pReturnValue = ret;

	return NULL;
}
Beispiel #3
0
tAsyncCall* System_RuntimeType_GetGenericArguments(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tMD_TypeDef *pType = ((tRuntimeType*)pThis_)->pTypeDef;
	tMD_TypeDef *pCoreType;
	U32 i, argCount = 0;
	HEAP_PTR ret;

	pCoreType = pType->pGenericDefinition;
	if (pCoreType != NULL) {
		// Find the core instantiation of this type
		tGenericInstance *pInst = pCoreType->pGenericInstances;
		while (pInst != NULL) {
			if (pInst->pInstanceTypeDef == pType) {
				// Found it!
				argCount = pInst->numTypeArgs;
			}
			pInst = pInst->pNext;
		}
	}

	ret = SystemArray_NewVector(types[TYPE_SYSTEM_ARRAY_TYPE], argCount);
	// Allocate to return value straight away, so it cannot be GCed
	*(HEAP_PTR*)pReturnValue = ret;

	for (i=0; i<argCount; i++) {
		HEAP_PTR argType = Type_GetTypeObject(pType->ppClassTypeArgs[i]);
		SystemArray_StoreElement(ret, i, (PTR)&argType);
	}

	return NULL;
}
I32 CLIFile_Execute(tCLIFile *pThis, int argc, char **argp) {
	tThread *pThread;
	HEAP_PTR args;
	int i;

	// Create a string array for the program arguments
	// Don't include the argument that is the program name.
	argc--;
	argp++;
	args = SystemArray_NewVector(types[TYPE_SYSTEM_ARRAY_STRING], argc);
	Heap_MakeUndeletable(args);
	for (i = 0; i < argc; i++) {
		HEAP_PTR arg = SystemString_FromCharPtrASCII(argp[i]);
		SystemArray_StoreElement(args, i, (PTR)&arg);
	}

	// Create the main application thread
	pThread = Thread();
	Thread_SetEntryPoint(pThread, pThis->pMetaData, pThis->entryPoint, (PTR)&args, sizeof(void*));

	return Thread_Execute();
}