Пример #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;
}
Пример #2
0
tAsyncCall* System_RuntimeType_get_Namespace(PTR pThis_, PTR pParams, PTR pReturnValue) {
	tRuntimeType *pRuntimeType = (tRuntimeType*)pThis_;
	HEAP_PTR strResult;

	strResult = SystemString_FromCharPtrASCII(pRuntimeType->pTypeDef->nameSpace);
	*(HEAP_PTR*)pReturnValue = strResult;

	return NULL;
}
Пример #3
0
tAsyncCall* System_IO_FileInternal_GetCurrentDirectory(PTR pThis_, PTR pParams, PTR pReturnValue) {
	U32 *pError = ((U32**)pParams)[0];
	HEAP_PTR curDir;
#ifdef WIN32
	unsigned short dir[256];
	GetCurrentDirectoryW(256, dir);
	curDir = SystemString_FromCharPtrUTF16(dir);
#else
	unsigned char dir[256];
	getcwd(dir, 256);
	curDir = SystemString_FromCharPtrASCII(dir);
#endif
	*pError = 0;
	*(HEAP_PTR*)pReturnValue = curDir;
	return NULL;
}
Пример #4
0
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();
}
Пример #5
0
tAsyncCall* System_IO_FileInternal_GetFileSystemEntries(PTR pThis_, PTR pParams, PTR pReturnValue) {
	//HEAP_PTR pathHP = ((HEAP_PTR*)pParams)[0];
	HEAP_PTR pathPatternHP = ((HEAP_PTR*)pParams)[1];
	U32 attrs = ((U32*)pParams)[2];
	U32 mask = ((U32*)pParams)[3];
	U32* pError = ((U32**)pParams)[4];
	U32 /*pathLen,*/ pathPatternLen;
	//STRING2 path = SystemString_GetString(pathHP, &pathLen);
	STRING2 pathPattern = SystemString_GetString(pathPatternHP, &pathPatternLen);
	HEAP_PTR retArray;
	U32 tempStoreSize = 32, tempStoreOfs = 0, i;
	HEAP_PTR *pTempStore = malloc(tempStoreSize * sizeof(void*));
	PTR arrayElements;
#ifdef WIN32
	unsigned short pathPatternNullTerm[256];
	HANDLE hFind;
	WIN32_FIND_DATA find;
	memcpy(pathPatternNullTerm, pathPattern, pathPatternLen << 1);
	pathPatternNullTerm[pathPatternLen] = 0;
	hFind = FindFirstFileW(pathPatternNullTerm, &find);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			if ((find.dwFileAttributes & mask) == attrs) {
				HEAP_PTR str;
				// Want this file, so store it in tempStore
				if (tempStoreOfs >= tempStoreSize) {
					tempStoreSize <<= 1;
					pTempStore = realloc(pTempStore, tempStoreSize * sizeof(void*));
				}
				str = SystemString_FromCharPtrUTF16(find.cFileName);
				// Need to temporarily make these undeletable, in case a GC happens before they're in the array
				Heap_MakeUndeletable(str);
				pTempStore[tempStoreOfs++] = str;
			}
		} while (FindNextFile(hFind, &find) != 0);
		FindClose(hFind);
	}
#else
	unsigned char path8[256];
	glob_t gl;
	for (i=0; i<pathPatternLen; i++) {
		path8[i] = (U8)pathPattern[i];
	}
	path8[i] = 0;
	i = glob(path8, GLOB_NOSORT, NULL, &gl);
	if (i == 0) {
		for (i=0; i<gl.gl_pathc; i++) {
			unsigned char *pResult = gl.gl_pathv[i];
			U32 fileAttrs = Attrs(pResult, pError);
			if (fileAttrs == (U32)-1) {
				break;
			}
			if ((fileAttrs & mask) == attrs) {
				HEAP_PTR str;
				// Want this file, so store it in tempStore
				if (tempStoreOfs >= tempStoreSize) {
					tempStoreSize <<= 1;
					pTempStore = realloc(pTempStore, tempStoreSize * sizeof(void*));
				}
				str = SystemString_FromCharPtrASCII(pResult);
				// Need to temporarily make these undeletable, in case a GC happens before they're in the array
				Heap_MakeUndeletable(str);
				pTempStore[tempStoreOfs++] = str;
			}
		}
		globfree(&gl);
	} else {
		*pError = errno;
	}
#endif
	// Move the temp-store values into the final returnable array
	retArray = SystemArray_NewVector(types[TYPE_SYSTEM_ARRAY_STRING], tempStoreOfs);
	arrayElements = SystemArray_GetElements(retArray);
	memcpy(arrayElements, pTempStore, tempStoreOfs * sizeof(void*));
	free(pTempStore);
	*(HEAP_PTR*)pReturnValue = retArray;
	// Make the strings deletable again
	for (i=0; i<tempStoreOfs; i++) {
		Heap_MakeDeletable(((HEAP_PTR*)arrayElements)[i]);
	}
	return NULL;
}
Пример #6
0
U32 PInvoke_Call(tJITCallPInvoke *pCall, PTR pParams, PTR pReturnValue) {
	U32 _args[MAX_ARGS];
	double _argsd[MAX_ARGS];
	void* _pTempMem[MAX_ARGS];
	U32 numParams, param, paramTypeNum;
	tMD_MethodDef *pMethod = pCall->pMethod;
	tMD_TypeDef *pReturnType = pMethod->pReturnType;
	tMD_ImplMap *pImplMap = pCall->pImplMap;
	void *pFn = pCall->fn;
	U32 _argOfs = 0, _argdOfs = 0, paramOfs = 0;
	U32 _tempMemOfs = 0;
	U32 i;
	U32 funcParams = DEFAULT;
	U64 u64Ret;
	float fRet;
	double dRet;

	if (pReturnType != NULL) {
		if (pReturnType == types[TYPE_SYSTEM_SINGLE]) {
			funcParams = SINGLE;
		} else if (pReturnType == types[TYPE_SYSTEM_DOUBLE]) {
			funcParams = DOUBLE;
		}
	}

	numParams = pMethod->numberOfParameters;
	for (param = 0, paramTypeNum = 0; param<numParams; param++, paramTypeNum++) {
		tParameter *pParam = &(pMethod->pParams[param]);
		tMD_TypeDef *pParamType = pParam->pTypeDef;
		U32 paramType = DEFAULT;

		if (pParamType->stackType == EVALSTACK_INT32) {
			_args[_argOfs] = *(U32*)(pParams + paramOfs);
			_argOfs++;
			paramOfs += 4;
		} else if (pParamType == types[TYPE_SYSTEM_STRING]) {
			// Allocate a temp bit of memory for the string that's been converted.
			void *pString;
			if (IMPLMAP_ISCHARSET_ANSI(pImplMap) || IMPLMAP_ISCHARSET_AUTO(pImplMap) || IMPLMAP_ISCHARSET_NOTSPEC(pImplMap)) {
				pString = ConvertStringToANSI(*(HEAP_PTR*)(pParams + paramOfs));
			} else if (IMPLMAP_ISCHARSET_UNICODE(pImplMap)) {
				pString = ConvertStringToUnicode(*(HEAP_PTR*)(pParams + paramOfs));
			} else {
				Crash("PInvoke_Call() Cannot handle string marshalling of given type");
			}
			_pTempMem[_tempMemOfs] = pString;
			_tempMemOfs++;
			_args[_argOfs] = (U32)pString;
			_argOfs++;
			paramOfs += 4;
		} else if (pParamType == types[TYPE_SYSTEM_INTPTR]) {
			// Only works for 32-bit
			_args[_argOfs] = *(U32*)(pParams + paramOfs);
			_argOfs++;
			paramOfs += 4;
		} else if (pParamType == types[TYPE_SYSTEM_SINGLE]) {
			_argsd[_argdOfs] = *(float*)(pParams + paramOfs);
			_argdOfs++;
			paramOfs += 4;
			paramType = SINGLE;
		} else if (pParamType == types[TYPE_SYSTEM_DOUBLE]) {
			_argsd[_argdOfs] = *(double*)(pParams + paramOfs);
			_argdOfs++;
			paramOfs += 8;
			paramType = DOUBLE;
		} else {
			Crash("PInvoke_Call() Cannot handle parameter of type: %s", pParamType->name);
		}
		SET_ARG_TYPE(paramTypeNum, paramType);
	}
	
	switch (funcParams) {

#include "PInvoke_CaseCode.h"

	case CALL5(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT):
		u64Ret = ((_uCuuuuu)(pFn))(_args[0], _args[1], _args[2], _args[3], _args[4]);
		break;

	case CALL6(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT):
		u64Ret = ((_uCuuuuuu)(pFn))(_args[0], _args[1], _args[2], _args[3], _args[4], _args[5]);
		break;

	case CALL7(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT):
		u64Ret = ((_uCuuuuuuu)(pFn))(_args[0], _args[1], _args[2], _args[3], _args[4], _args[5], _args[6]);
		break;

	case CALL8(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT):
		u64Ret = ((_uCuuuuuuuu)(pFn))(_args[0], _args[1], _args[2], _args[3], _args[4], _args[5], _args[6], _args[7]);
		break;

	case CALL9(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT):
		u64Ret = ((_uCuuuuuuuuu)(pFn))(_args[0], _args[1], _args[2], _args[3], _args[4], _args[5], _args[6], _args[7], _args[8]);
		break;

	case CALL10(DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT):
		u64Ret = ((_uCuuuuuuuuuu)(pFn))(_args[0], _args[1], _args[2], _args[3], _args[4], _args[5], _args[6], _args[7], _args[8], _args[9]);
		break;

	default:
		Crash("PInvoke_Call() Cannot handle the function parameters: 0x%08x", funcParams);
	}
	
	for (i=0; i<_tempMemOfs; i++) {
		free(_pTempMem[i]);
	}

	if (pReturnType == NULL) {
		return 0;
	}
	if (pReturnType->stackType == EVALSTACK_INT32) {
		*(U32*)pReturnValue = (U32)u64Ret;
		return 4;
	}
	if (pReturnType == types[TYPE_SYSTEM_STRING]) {
		if (IMPLMAP_ISCHARSET_ANSI(pImplMap) || IMPLMAP_ISCHARSET_AUTO(pImplMap) || IMPLMAP_ISCHARSET_NOTSPEC(pImplMap)) {
			*(HEAP_PTR*)pReturnValue = SystemString_FromCharPtrASCII((U8*)(U32)u64Ret);
		} else if (IMPLMAP_ISCHARSET_UNICODE(pImplMap)) {
			*(HEAP_PTR*)pReturnValue = SystemString_FromCharPtrUTF16((U16*)(U32)u64Ret);
		} else {
			Crash("PInvoke_Call() Cannot handle return string in specified format");
		}
		return sizeof(void*);
	}
	if (pReturnType == types[TYPE_SYSTEM_INTPTR]) {
		*(void**)pReturnValue = (void*)(U32)u64Ret;
		return sizeof(void*);
	}
	if (pReturnType == types[TYPE_SYSTEM_SINGLE]) {
		*(double*)pReturnValue = (double)fRet;
		return 8;
	}
	if (pReturnType == types[TYPE_SYSTEM_DOUBLE]) {
		*(double*)pReturnValue = dRet;
		return 8;
	}

	Crash("PInvoke_Call() Cannot handle return type: %s", pReturnType->name);
	FAKE_RETURN;
}