Exemplo n.º 1
0
        public static tAsyncCall *Resize(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            /*HEAP_PTR*/ byte **ppArray_, pHeap;
            tSystemArray *      pOldArray, pNewArray;
            uint         newSize, oldSize;
            tMD_TypeDef *pArrayTypeDef;
            byte *       pOldElements, pNewElements;

            ppArray_ = (*((byte ***)(pParams + 0)));
            newSize  = (*((uint *)(pParams + Sys.S_PTR)));

            pOldArray = (tSystemArray *)*ppArray_;
            oldSize   = pOldArray->length;

            if (oldSize == newSize)
            {
                // Do nothing if new length equals the current length.
                return(null);
            }

            pArrayTypeDef = Heap.GetType(*ppArray_);
            pHeap         = (byte **)System_Array.NewVector(pArrayTypeDef, newSize);
            pNewArray     = (tSystemArray *)pHeap;
            *ppArray_ = (byte *)pHeap;
            pOldElements = tSystemArray.GetElements(pOldArray);
            pNewElements = tSystemArray.GetElements(pNewArray);
            Mem.memcpy(pNewElements, pOldElements,
                       (SIZE_T)(pArrayTypeDef->pArrayElementType->arrayElementSize * ((newSize < oldSize)?newSize:oldSize)));

            return(null);
        }
Exemplo n.º 2
0
        public static tAsyncCall *CreateInstance(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tRuntimeType *pRuntimeType = (*((tRuntimeType **)(pParams + 0)));
            tMD_TypeDef * pElementType = System_RuntimeType.DeRef((byte *)pRuntimeType);
            tMD_TypeDef * pArrayType   = Type.GetArrayTypeDef(pElementType, null, null);
            uint          length       = (*((uint *)(pParams + Sys.S_PTR)));

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, System_Array.NewVector(pArrayType, length));
            return(null);
        }
Exemplo n.º 3
0
        // Get the size of a heap entry, NOT including the header
        // This works by returning the size of the type, unless the type is an array or a string,
        // which are the only two type that can have variable sizes
        static uint GetSize(tHeapEntry *pHeapEntry)
        {
            tMD_TypeDef *pType = pHeapEntry->pTypeDef;

            if (MetaData.TYPE_ISARRAY(pType))
            {
                // If it's an array, return the array length * array element size
                return(System_Array.GetNumBytes(null /* This is ok */, (/*HEAP_PTR*/ byte *)(pHeapEntry + 1), pType->pArrayElementType));
            }
            // If it's not array, just return the instance memory size
            return(pType->instanceMemSize);
        }
Exemplo n.º 4
0
        public static tAsyncCall *InternalIndexOfAny(tJITCallNative *pCallNative, byte *pThis, byte *pParams, byte *pReturnValue)
        {
            /*HEAP_PTR*/ byte *valueArray;
            int    startIndex, count;
            uint   forwards;
            string s;

            s          = ToMonoString((tSystemString *)pThis);
            valueArray = (*((/*HEAP_PTR*/ byte **)(pParams + 0)));
            startIndex = (*((int *)(pParams + Sys.S_PTR)));
            count      = (*((int *)(pParams + Sys.S_PTR + Sys.S_INT32)));
            forwards   = (*((uint *)(pParams + Sys.S_PTR + Sys.S_INT32 + Sys.S_INT32)));

            byte *valueChars    = System_Array.GetElements(valueArray);
            uint  numValueChars = System_Array.GetLength(valueArray);

            int lastIndex;
            int inc;
            int i, j;

            if (forwards != 0)
            {
                lastIndex = startIndex + count;
                inc       = 1;
                i         = startIndex;
            }
            else
            {
                lastIndex = startIndex - 1;
                inc       = -1;
                i         = startIndex + count - 1;
            }
            for (; i != lastIndex; i += inc)
            {
                char thisChar = s[i];
                for (j = (int)numValueChars - 1; j >= 0; j--)
                {
                    if (thisChar == ((ushort *)valueChars)[j])
                    {
                        Sys.INTERNALCALL_RESULT_I32(pReturnValue, i);
                        return(null);
                    }
                }
            }
            Sys.INTERNALCALL_RESULT_I32(pReturnValue, -1);
            return(null);
        }
Exemplo n.º 5
0
        public static tAsyncCall *ctor_CharAIntInt(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *    pSystemString;
            /*HEAP_PTR*/ byte *charArray;
            char *charElements;
            int   startIndex, length;

            charArray  = (*((byte **)(pParams + 0)));
            startIndex = (*((int *)(pParams + Sys.S_PTR)));
            length     = (*((int *)(pParams + Sys.S_PTR + Sys.S_INT32)));

            charElements  = (char *)System_Array.GetElements(charArray);
            pSystemString = FromMonoString(new System.String(charElements, startIndex, length));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pSystemString);

            return(null);
        }
Exemplo n.º 6
0
        // Get the size of a heap entry, NOT including the header
        // This works by returning the size of the type, unless the type is an array or a string,
        // which are the only two type that can have variable sizes
        static uint GetSize(tHeapEntry *pHeapEntry)
        {
            tMD_TypeDef *pType = pHeapEntry->pTypeDef;

            if (pType == Type.types[Type.TYPE_SYSTEM_STRING])
            {
                // If it's a string, return the string length in bytes
                return(System_String.GetNumBytes((/*HEAP_PTR*/ byte *)(pHeapEntry + 1)));
            }
            if (MetaData.TYPE_ISARRAY(pType))
            {
                // If it's an array, return the array length * array element size
                return(System_Array.GetNumBytes(null /* This is ok */, (/*HEAP_PTR*/ byte *)(pHeapEntry + 1), pType->pArrayElementType));
            }
            // If it's not string or array, just return the instance memory size
            return(pType->instanceMemSize);
        }
Exemplo n.º 7
0
        public static tAsyncCall *InternalTrim(tJITCallNative *pCallNative, byte *pThis, byte *pParams, byte *pReturnValue)
        {
            /*HEAP_PTR*/ byte *pWhiteChars;
            uint           trimType, i, checkCharsLen;
            string         s, ret;
            char *         pCheckChars;
            tSystemString *pRet;

            pWhiteChars = (*((/*HEAP_PTR*/ byte **)(pParams + 0)));
            char[] whiteChars = null;
            if (pWhiteChars != null)
            {
                pCheckChars   = (char *)System_Array.GetElements(pWhiteChars);
                checkCharsLen = System_Array.GetLength(pWhiteChars);
                whiteChars    = new char[checkCharsLen];
                for (i = 0; i < checkCharsLen; i++)
                {
                    whiteChars[i] = pCheckChars[i];
                }
            }
            trimType = (*((uint *)(pParams + Sys.S_PTR)));

            s   = ToMonoString((tSystemString *)pThis);
            ret = null;

            if (trimType == 1)
            {
                ret = s.TrimStart(whiteChars);
            }
            else if (trimType == 2)
            {
                ret = s.TrimEnd(whiteChars);
            }
            else if (trimType == 3)
            {
                ret = s.Trim(whiteChars);
            }

            pRet = FromMonoString(ret);

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pRet);

            return(null);
        }
Exemplo n.º 8
0
        public static tAsyncCall *ctor_CharAIntInt(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *    pSystemString;
            /*HEAP_PTR*/ byte *charArray;
            byte *charElements;
            uint  startIndex, length;
            char *pChars;

            charArray  = (*((byte **)(pParams + 0)));
            startIndex = (*((uint *)(pParams + Sys.S_PTR)));
            length     = (*((uint *)(pParams + Sys.S_PTR + Sys.S_INT32)));

            charElements  = System_Array.GetElements(charArray);
            pSystemString = CreateStringHeapObj(length);
            pChars        = tSystemString.GetChars(pSystemString);
            Mem.memcpy(pChars, charElements + (startIndex << 1), (SIZE_T)(length << 1));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pSystemString);

            return(null);
        }
Exemplo n.º 9
0
        public static int Execute(tCLIFile *pThis, string[] args)
        {
            tThread *          pThread;
            /*HEAP_PTR*/ byte *pArgs;
            int i;

            // Create a string array for the program arguments
            // Don't include the argument that is the program name.
            pArgs = System_Array.NewVector(Type.types[Type.TYPE_SYSTEM_ARRAY_STRING], (uint)(args.Length - 1));
            Heap.MakeUndeletable(pArgs);
            for (i = 1; i < args.Length; i++)
            {
                tSystemString *pArgStr = System_String.FromMonoString(args[i]);
                System_Array.StoreElement(pArgs, (uint)(i - 1), (byte *)&pArgStr);
            }

            // Create the main application thread
            pThread = Thread.New();
            Thread.SetEntryPoint(pThread, pThis->pMetaData, pThis->entryPoint, (byte *)&pArgs, (uint)sizeof(void *));

            return(Thread.Execute());
        }
Exemplo n.º 10
0
        public static tAsyncCall *InternalTrim(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *    pThis = (tSystemString *)pThis_;
            /*HEAP_PTR*/ byte *pWhiteChars;
            uint           trimType, i, j, checkCharsLen;
            uint           ofsStart, ofsEnd;
            ushort *       pCheckChars;
            uint           isWhiteSpace;
            tSystemString *pRet;
            ushort         c;
            char *         pChars, pRetChars;

            pWhiteChars   = (*((/*HEAP_PTR*/ byte **)(pParams + 0)));
            trimType      = (*((uint *)(pParams + Sys.S_PTR)));
            pCheckChars   = (ushort *)System_Array.GetElements(pWhiteChars);
            checkCharsLen = System_Array.GetLength(pWhiteChars);

            ofsStart = 0;
            ofsEnd   = pThis->length;
            pChars   = tSystemString.GetChars(pThis);
            if ((trimType & 1) != 0)
            {
                // Trim start
                for (i = ofsStart; i < ofsEnd; i++)
                {
                    // Check if each char is in the array
                    isWhiteSpace = 0;
                    c            = pChars[i];
                    for (j = 0; j < checkCharsLen; j++)
                    {
                        if (c == pCheckChars[j])
                        {
                            isWhiteSpace = 1;
                            break;
                        }
                    }
                    if (isWhiteSpace == 0)
                    {
                        ofsStart = i;
                        break;
                    }
                }
            }
            if ((trimType & 2) != 0)
            {
                // Trim end
                for (i = ofsEnd - 1; i >= ofsStart; i--)
                {
                    // Check if each char is in the array
                    isWhiteSpace = 0;
                    c            = pChars[i];
                    for (j = 0; j < checkCharsLen; j++)
                    {
                        if (c == pCheckChars[j])
                        {
                            isWhiteSpace = 1;
                            break;
                        }
                    }
                    if (isWhiteSpace == 0)
                    {
                        ofsEnd = i + 1;
                        break;
                    }
                }
            }

            pRet      = CreateStringHeapObj(ofsEnd - ofsStart);
            pRetChars = tSystemString.GetChars(pRet);
            Mem.memcpy(pRetChars, &pChars[ofsStart], (SIZE_T)((ofsEnd - ofsStart) << 1));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pRet);

            return(null);
        }