示例#1
0
void uDelegate::Invoke(uTRef retval, void** args, size_t count)
{
    if (_prev != NULL)
        _prev->Invoke(retval, args, count);

    uDelegateType* type = (uDelegateType*)__type;
    size_t parameterCount = type->ParameterCount;

    if (count != parameterCount)
        U_THROW_IOORE();

    if (_this)
        count++;
    if (_generic)
        count++;
    if (retval._address)
        count++;

    void** stack = (void**)U_ALLOCA(count * sizeof(void*));
    void** ptr = stack;

    if (_this)
        *ptr++ = _this;
    if (_generic)
        *ptr++ = _generic;

    memcpy(ptr, args, parameterCount * sizeof(void*));
    ptr += parameterCount;

    if (retval._address)
        *ptr++ = retval._address;

    uInvoke(_func, stack, count);
}
示例#2
0
uObject* uDelegate::Invoke(uArray* array)
{
    uDelegateType* type = (uDelegateType*)GetType();
    size_t count = type->ParameterCount;
    uType** params = type->ParameterTypes;
    void** args = NULL;

    if (array)
    {
        if (!U_IS_OBJECT(((uArrayType*)array->GetType())->ElementType))
            U_THROW_ICE();
        if (count != array->Length())
            U_THROW_IOORE();

        uObject** objects = (uObject**)array->Ptr();
        void** ptr = args = count > 0
            ? (void**)U_ALLOCA(count * sizeof(void*))
            : NULL;

        for (size_t i = 0; i < count; i++)
        {
            uType* param = *params++;
            uObject* object = *objects++;

            switch (param->Type)
            {
            case uTypeTypeEnum:
            case uTypeTypeStruct:
                *ptr++ = (uint8_t*)object + sizeof(uObject);
                break;
            case uTypeTypeByRef:
                *ptr++ = U_IS_VALUE(((uByRefType*)param)->ValueType)
                        ? (uint8_t*)object + sizeof(uObject)
                        : (void*)&object;
                break;
            case uTypeTypeClass:
            case uTypeTypeDelegate:
            case uTypeTypeInterface:
            case uTypeTypeArray:
                *ptr++ = object;
                break;
            default:
                U_FATAL();
            }
        }
    }

    uType* returnType = type->ReturnType;
    void* retval = !U_IS_VOID(returnType)
        ? U_ALLOCA(returnType->ValueSize)
        : NULL;

    Invoke(retval, args, count);
    return uBoxPtr(returnType, retval, NULL, true);
}
示例#3
0
uType* uType::MakeGeneric(size_t count, uType** args)
{
    if (count != GenericCount)
        U_THROW_IOORE();

    uPtr(args);
    for (size_t i = 0; i < count; i++)
        uPtr(args[i]);

    return uGetParameterization(uTypeKey(this, args));
}
示例#4
0
void uArray::Copy(const uArray* srcArray, int srcIndex, uArray* dstArray, int dstIndex, int length)
{
    if (!srcArray || !dstArray)
        U_THROW_NRE();
    if (srcArray->GetType() != dstArray->GetType())
        U_THROW_ICE();
    if (length < 0 ||
        srcIndex < 0 || srcIndex + length > srcArray->Length() ||
        dstIndex < 0 || dstIndex + length > dstArray->Length())
        U_THROW_IOORE();

    uType* type = ((uArrayType*)srcArray->GetType())->ElementType;
    size_t size = type->ValueSize;
    uint8_t* dst = (uint8_t*)dstArray->Ptr() + size * dstIndex;
    const uint8_t* src = (const uint8_t*)srcArray->Ptr() + size * srcIndex;

    switch (type->Type)
    {
    case uTypeTypeEnum:
        memcpy(dst, src, size * length);
        break;

    case uTypeTypeStruct:
        if (type->Flags & uTypeFlagsRetainStruct)
        {
            for (int i = 0; i < length; i++)
                uAutoReleaseStruct(type, dst + i * size);
            memcpy(dst, src, size * length);
            for (int i = 0; i < length; i++)
                uRetainStruct(type, dst + i * size);
        }
        else
            memcpy(dst, src, size * length);
        break;

    default:
        for (int i = 0; i < length; i++)
            uAutoRelease((uObject*)dst + i);
        memcpy(dst, src, size * length);
        for (int i = 0; i < length; i++)
            uRetain((uObject*)dst + i);
        break;
    }
}
示例#5
0
void uDelegate::InvokeVoid(void* arg)
{
    if (_prev != NULL)
        _prev->InvokeVoid(arg);

    uDelegateType* type = (uDelegateType*)__type;
    if (type->ParameterCount != 1)
        U_THROW_IOORE();
    if (!U_IS_VOID(type->ReturnType))
        U_THROW_ICE();

    _this && _generic
        ? ((void(*)(void*, void*, void*))_func)(_this, _generic, arg) :
    _this
        ? ((void(*)(void*, void*))_func)(_this, arg) :
    _generic
        ? ((void(*)(void*, void*))_func)(_generic, arg)
        : ((void(*)(void*))_func)(arg);
}
示例#6
0
void uInvoke(const void* func, void** args, size_t count)
{
    switch (count)
    {
    default: U_THROW_IOORE();
    case  0: CALL() ME(); break;
    case  1: CALL(T) ME(A[0]); break;
    case  2: CALL(T,T) ME(A[0],A[1]); break;
    case  3: CALL(T,T,T) ME(A[0],A[1],A[2]); break;
    case  4: CALL(T,T,T,T) ME(A[0],A[1],A[2],A[3]); break;
    case  5: CALL(T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4]); break;
    case  6: CALL(T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5]); break;
    case  7: CALL(T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6]); break;
    case  8: CALL(T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7]); break;
    case  9: CALL(T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8]); break;
    case 10: CALL(T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9]); break;
    case 11: CALL(T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10])
             ; break;
    case 12: CALL(T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[
             10],A[11]); break;
    case 13: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[
             10],A[11],A[12]); break;
    case 14: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],
             A[10],A[11],A[12],A[13]); break;
    case 15: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[
             9],A[10],A[11],A[12],A[13],A[14]); break;
    case 16: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],
             A[9],A[10],A[11],A[12],A[13],A[14],A[15]); break;
    case 17: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8]
             ,A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16]); break;
    case 18: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[
             8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17]); break;
    case 19: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],
             A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18]); break;
    case 20: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[
             7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19]); break;
    case 21: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],
             A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[20]);
             break;
    case 22: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6]
             ,A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[20],A[21]
             ); break;
    case 23: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[
             6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[20],A[
             21],A[22]); break;
    case 24: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],
             A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[20],
             A[21],A[22],A[23]); break;
    case 25: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[
             5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[
             20],A[21],A[22],A[23],A[24]); break;
    case 26: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],
             A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[
             20],A[21],A[22],A[23],A[24],A[25]); break;
    case 27: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4]
             ,A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19],
             A[20],A[21],A[22],A[23],A[24],A[25],A[26]); break;
    case 28: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[
             4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[19]
             ,A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27]); break;
    case 29: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],
             A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],A[
             19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28]); break;
    case 30: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[
             3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[18],
             A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29]); break;
    case 31: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2],
             A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[
             18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30]); break;
    case 32: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[2]
             ,A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],A[
             18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30],A[31]);
             break;
    case 33: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],A[
             2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17],
             A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30],A[31],A[
             32]); break;
    case 34: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[1],
             A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[17]
             ,A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30],A[31],A[
             32],A[33]); break;
    case 35: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],A[
             1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],A[
             17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30],A[31]
             ,A[32],A[33],A[34]); break;
    case 36: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0],
             A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16],
             A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30],A[
             31],A[32],A[33],A[34],A[35]); break;
    case 37: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[0]
             ,A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[16]
             ,A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30],A[
             31],A[32],A[33],A[34],A[35],A[36]); break;
    case 38: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(A[
             0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],A[
             16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[30]
             ,A[31],A[32],A[33],A[34],A[35],A[36],A[37]); break;
    case 39: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T) ME(
             A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[15],
             A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29],A[
             30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38]); break;
    case 40: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T)
             ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[
             15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29]
             ,A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39]); break;
    case 41: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T)
             ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],A[
             15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[29]
             ,A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40]); break;
    case 42: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14],
             A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[
             29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41]); break;
    case 43: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[14]
             ,A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28],A[
             29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41],A[42]);
             break;
    case 44: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],A[
             14],A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[28]
             ,A[29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41],A[42],A[
             43]); break;
    case 45: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13],
             A[14],A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[
             28],A[29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41],A[42]
             ,A[43],A[44]); break;
    case 46: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[13]
             ,A[14],A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27],A[
             28],A[29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41],A[42]
             ,A[43],A[44],A[45]); break;
    case 47: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],A[
             13],A[14],A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[27]
             ,A[28],A[29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41],A[
             42],A[43],A[44],A[45],A[46]); break;
    case 48: CALL(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,
             T,T,T,T,T,T,T) ME(A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7],A[8],A[9],A[10],A[11],A[12],
             A[13],A[14],A[15],A[16],A[17],A[18],A[19],A[20],A[21],A[22],A[23],A[24],A[25],A[26],A[
             27],A[28],A[29],A[30],A[31],A[32],A[33],A[34],A[35],A[36],A[37],A[38],A[39],A[40],A[41]
             ,A[42],A[43],A[44],A[45],A[46],A[47]); break;
    }
}
示例#7
0
uObject* uFunction::Invoke(uObject* object, uArray* args)
{
    size_t count = ParameterTypes->Length();
    void* retval = !U_IS_VOID(ReturnType)
        ? U_ALLOCA(ReturnType->ValueSize)
        : NULL;

    if (!(Flags & uFunctionFlagsStatic))
        count++;
    if (Generic)
        count++;
    if (retval)
        count++;

    void** stack;
    void** ptr = stack = count > 0
            ? (void**)U_ALLOCA(count * sizeof(void*))
            : NULL;

    if (!(Flags & uFunctionFlagsStatic))
        *ptr++ = !(Flags & uFunctionFlagsVirtual) && U_IS_VALUE(DeclaringType)
            ? (uint8_t*)uPtr(object) + sizeof(uObject)
            : (void*)uPtr(object);
    if (Generic)
        *ptr++ = Generic;

    if (args)
    {
        if (args->Length() != ParameterTypes->Length())
            U_THROW_IOORE();
        if (U_IS_VALUE(((uArrayType*)args->GetType())->ElementType))
            U_THROW_ICE();

        uType** params = (uType**)ParameterTypes->Ptr();
        uObject** objects = (uObject**)args->Ptr();

        for (int i = 0; i < args->Length(); i++)
        {
            uType*& param = *params++;
            uObject*& arg = *objects++;

            switch (param->Type)
            {
            case uTypeTypeEnum:
            case uTypeTypeStruct:
                *ptr++ = (uint8_t*)arg + sizeof(uObject);
                break;
            case uTypeTypeByRef:
                *ptr++ = U_IS_VALUE(((uByRefType*)param)->ValueType)
                        ? (uint8_t*)arg + sizeof(uObject)
                        : (void*)&arg;
                break;
            case uTypeTypeClass:
            case uTypeTypeDelegate:
            case uTypeTypeInterface:
            case uTypeTypeArray:
                *ptr++ = arg;
                break;
            default:
                U_FATAL();
            }
        }
    }
    else if (ParameterTypes->Length() != 0)
        U_THROW_IOORE();

    if (retval)
        *ptr++ = retval;

    U_ASSERT(DeclaringType);
    DeclaringType->Init();
    uInvoke(Flags & uFunctionFlagsVirtual
            ? *(void**)((uint8_t*)object->GetType() + _offset)
            : _func,
        stack,
        count);
    return uBoxPtr(ReturnType, retval, NULL, true);
}