public static tAsyncCall *get_CurrentThread(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tThread *pThread = Thread.GetCurrent();

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pThread);

            return(null);
        }
Example #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);
        }
Example #3
0
        public static tAsyncCall *ctor_CharInt32(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *pSystemString;
            char           c;
            int            len;

            c             = (char)(*((uint *)(pParams + 0)));
            len           = (*((int *)(pParams + Sys.S_INT32)));
            pSystemString = FromMonoString(new System.String(c, len));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pSystemString);

            return(null);
        }
Example #4
0
        // Must return a boxed version of value-Type.types
        public static tAsyncCall *Internal_GetValue(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemArray *pArray = (tSystemArray *)pThis_;
            tMD_TypeDef * pArrayType;
            uint          index, elementSize;
            tMD_TypeDef * pElementType;
            byte *        pElement;

            index        = (*((uint *)(pParams + 0)));
            pArrayType   = Heap.GetType(pThis_);
            pElementType = pArrayType->pArrayElementType;
            elementSize  = pElementType->arrayElementSize;
            pElement     = tSystemArray.GetElements(pArray) + elementSize * index;
            if (pElementType->isValueType != 0)
            {
                // If it's a value-type, then box it
                /*HEAP_PTR*/ byte *boxedValue;
                if (pElementType->pGenericDefinition == Type.types[Type.TYPE_SYSTEM_NULLABLE])
                {
                    // Nullable type, so box specially
                    if (*(uint *)pElement != 0)
                    {
                        // Nullable has value
                        boxedValue = Heap.AllocType(pElementType->ppClassTypeArgs[0]);
                        // Don't copy the .hasValue part
                        Mem.memcpy(boxedValue, pElement + 4, elementSize - 4);
                    }
                    else
                    {
                        // Nullable does not have value
                        boxedValue = null;
                    }
                }
                else
                {
                    boxedValue = Heap.AllocType(pElementType);
                    Mem.memcpy(boxedValue, pElement, elementSize);
                }
                Sys.INTERNALCALL_RESULT_PTR(pReturnValue, boxedValue);
            }
            else
            {
                Sys.INTERNALCALL_RESULT_PTR(pReturnValue, *(byte **)pElement);
            }

            return(null);
        }
Example #5
0
        public static tAsyncCall *InternalConcat2(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *s0, s1, ret;
            string         str0, str1;

            s0 = (*((tSystemString **)(pParams + 0)));
            s1 = (*((tSystemString **)(pParams + Sys.S_PTR)));

            str0 = ToMonoString(s0);
            str1 = ToMonoString(s1);

            ret = FromMonoString(str0 + str1);

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, ret);

            return(null);
        }
Example #6
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);
        }
Example #7
0
        public static tAsyncCall *InternalReplace(tJITCallNative *pCallNative, byte *pThis, byte *pParams, byte *pReturnValue)
        {
            tSystemString *pOld, pNew, pResult;
            string         s, oldStr, newStr;

            s      = ToMonoString((tSystemString *)pThis);
            pOld   = (*((tSystemString **)(pParams + 0)));
            oldStr = ToMonoString(pOld);
            pNew   = (*((tSystemString **)(pParams + Sys.S_PTR)));
            newStr = ToMonoString(pNew);

            pResult = FromMonoString(s.Replace(oldStr, newStr));

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pResult);

            return(null);
        }
Example #8
0
        public static tAsyncCall *InternalSubstring(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *pStr, pResult;
            int            startIndex, length;
            string         str;

            pStr       = (*((tSystemString **)(pParams + 0)));
            str        = ToMonoString(pStr);
            startIndex = (*((int *)(pParams + Sys.S_PTR)));
            length     = (*((int *)(pParams + Sys.S_PTR + Sys.S_INT32)));

            pResult = FromMonoString(str.Substring(startIndex, length));

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pResult);

            return(null);
        }
Example #9
0
        public static tAsyncCall *InternalConcat(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *s0, s1, ret;
            char *         pS0Chars, pS1Chars, pRetChars;

            s0        = (*((tSystemString **)(pParams + 0)));
            pS0Chars  = tSystemString.GetChars(s0);
            s1        = (*((tSystemString **)(pParams + Sys.S_PTR)));
            pS1Chars  = tSystemString.GetChars(s1);
            ret       = CreateStringHeapObj(s0->length + s1->length);
            pRetChars = tSystemString.GetChars(ret);
            Mem.memcpy(pRetChars, pS0Chars, (SIZE_T)(s0->length << 1));
            Mem.memcpy(&pRetChars[s0->length], pS1Chars, (SIZE_T)(s1->length << 1));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, ret);

            return(null);
        }
Example #10
0
        public static tAsyncCall *ctor_StringIntInt(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *pThis;
            //tSystemString* pStr;
            uint  startIndex, length;
            char *pChars;

            //pStr = (*((tSystemString**)(pParams + 0)));
            startIndex = (*((uint *)(pParams + Sys.S_PTR)));
            length     = (*((uint *)(pParams + Sys.S_PTR + Sys.S_INT32)));

            pThis  = CreateStringHeapObj(length);
            pChars = tSystemString.GetChars(pThis);
            Mem.memcpy(pChars, &pChars[startIndex], (SIZE_T)(length << 1));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pThis);

            return(null);
        }
Example #11
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);
        }
Example #12
0
        public static tAsyncCall *ctor_CharInt32(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *pSystemString;
            char           c;
            uint           i, len;
            char *         pChars;

            c             = (char)(*((uint *)(pParams + 0)));
            len           = (*((uint *)(pParams + Sys.S_INT32)));
            pSystemString = CreateStringHeapObj(len);
            pChars        = tSystemString.GetChars(pSystemString);
            for (i = 0; i < len; i++)
            {
                pChars[i] = c;
            }
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pSystemString);

            return(null);
        }
Example #13
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);
        }
Example #14
0
        private static tAsyncCall *ToString_Internal(byte *pThis, byte *pParams, byte *pReturnValue, System.TypeCode typecode)
        {
            tSystemString *pFormat;
//            byte* pFormatProvider;
            string         format, s;
            tSystemString *pResult;

            pFormat = (*((tSystemString **)(pParams + 0)));
            format  = ToMonoString(pFormat);

            // Ignore IFormatProvider for now!
            //pFormatProvider = (*((tSystemString**)(pParams + Sys.S_PTR)));

            switch (typecode)
            {
            case System.TypeCode.Byte:
                s = (*(byte *)pThis).ToString(format);
                break;

            case System.TypeCode.SByte:
                s = (*(sbyte *)pThis).ToString(format);
                break;

            case System.TypeCode.UInt16:
                s = (*(ushort *)pThis).ToString(format);
                break;

            case System.TypeCode.Int16:
                s = (*(short *)pThis).ToString(format);
                break;

            case System.TypeCode.UInt32:
                s = (*(uint *)pThis).ToString(format);
                break;

            case System.TypeCode.Int32:
                s = (*(int *)pThis).ToString(format);
                break;

            case System.TypeCode.UInt64:
                s = (*(ulong *)pThis).ToString(format);
                break;

            case System.TypeCode.Int64:
                s = (*(long *)pThis).ToString(format);
                break;

            case System.TypeCode.Single:
                s = (*(float *)pThis).ToString(format);
                break;

            case System.TypeCode.Double:
                s = (*(double *)pThis).ToString(format);
                break;

            default:
                throw new System.NotImplementedException();
            }

            pResult = System_String.FromMonoString(s);

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pResult);

            return(null);
        }
Example #15
0
        public static tAsyncCall *InternalReplace(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *pThis = (tSystemString *)pThis_;
            tSystemString *pOld  = (*((tSystemString **)(pParams + 0)));
            tSystemString *pNew  = (*((tSystemString **)(pParams + Sys.S_PTR)));
            tSystemString *pResult;
            uint           thisLen, oldLen, newLen;
            char *         pThisChar0, pOldChar0, pNewChar0, pResultChar0;
            uint           i, j, replacements, dstIndex;
            uint           resultLen;

            // This function (correctly) assumes that the old string is not empty
            thisLen    = pThis->length;
            oldLen     = pOld->length;
            newLen     = pNew->length;
            pThisChar0 = tSystemString.GetChars(pThis);
            pOldChar0  = tSystemString.GetChars(pOld);
            pNewChar0  = tSystemString.GetChars(pNew);

            replacements = 0;
            for (i = 0; i < thisLen - oldLen + 1; i++)
            {
                uint match = 1;
                for (j = 0; j < oldLen; j++)
                {
                    if (pThisChar0[i + j] != pOldChar0[j])
                    {
                        match = 0;
                        break;
                    }
                }
                if (match != 0)
                {
                    i += oldLen - 1;
                    replacements++;
                }
            }
            resultLen    = thisLen - (oldLen - newLen) * replacements;
            pResult      = CreateStringHeapObj(resultLen);
            pResultChar0 = tSystemString.GetChars(pResult);
            dstIndex     = 0;
            for (i = 0; i < thisLen; i++)
            {
                uint match = 1;
                if (i < thisLen - oldLen + 1)
                {
                    for (j = 0; j < oldLen; j++)
                    {
                        match = 1;
                        if (pThisChar0[i + j] != pOldChar0[j])
                        {
                            match = 0;
                            break;
                        }
                    }
                }
                else
                {
                    match = 0;
                }
                if (match != 0)
                {
                    Mem.memcpy(&pResultChar0[dstIndex], pNewChar0, newLen << 1);
                    dstIndex += newLen;
                    i        += oldLen - 1;
                }
                else
                {
                    pResultChar0[dstIndex++] = pThisChar0[i];
                }
            }
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pResult);

            return(null);
        }
Example #16
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);
        }