Ejemplo n.º 1
0
        private CilStackValueInt32 ComputeBinaryComparisonOperation(
            IStackValue stackVal1,
            IStackValue stackVal2,
            Func <CilStackValueInt32, CilStackValueInt32, bool> computeInt32Int32,
            Func <CilStackValueInt64, CilStackValueInt64, bool> computeInt64Int64,
            Func <CilStackValueFloat, CilStackValueFloat, bool> computeFloatFloat
            )
        {
            bool result;

            if (stackVal1 is CilStackValueInt32 stackVal1Int32 && stackVal2 is CilStackValueInt32 stackVal2Int32)
            {
                result = computeInt32Int32(stackVal1Int32, stackVal2Int32);
            }
        private bool ComputeUnaryBranchOperation(
            IStackValue stackVal,
            Func <CilStackValueInt32, bool> computeInt32,
            Func <CilStackValueInt64, bool> computeInt64
            )
        {
            if (stackVal is CilStackValueInt32 stackValInt32)
            {
                return(computeInt32(stackValInt32));
            }
            if (stackVal is CilStackValueInt64 stackValInt64)
            {
                return(computeInt64(stackValInt64));
            }

            throw new System.NotImplementedException();
        }
Ejemplo n.º 3
0
        private IStackValue ComputeUnaryNumericOperation(
            IStackValue stackVal,
            Func <CilStackValueInt32, CilStackValueInt32> computeInt32,
            Func <CilStackValueInt64, CilStackValueInt64> computeInt64,
            Func <CilStackValueFloat, CilStackValueFloat> computeFloat
            )
        {
            if (stackVal is CilStackValueInt32 stackValInt32)
            {
                return(computeInt32(stackValInt32));
            }
            if (stackVal is CilStackValueInt64 stackValInt64)
            {
                return(computeInt64(stackValInt64));
            }
            if (stackVal is CilStackValueFloat stackValFloat)
            {
                return(computeFloat(stackValFloat));
            }

            throw new System.NotImplementedException();
        }
Ejemplo n.º 4
0
        private IStackValue ComputeBinaryNumericOperation(
            IStackValue stackVal1,
            IStackValue stackVal2,
            Func <CilStackValueInt32, CilStackValueInt32, CilStackValueInt32> computeInt32Int32,
            Func <CilStackValueInt64, CilStackValueInt64, CilStackValueInt64> computeInt64Int64,
            Func <CilStackValueFloat, CilStackValueFloat, CilStackValueFloat> computeFloatFloat
            )
        {
            if (stackVal1 is CilStackValueInt32 stackVal1Int32 && stackVal2 is CilStackValueInt32 stackVal2Int32)
            {
                return(computeInt32Int32(stackVal1Int32, stackVal2Int32));
            }
            if (stackVal1 is CilStackValueInt64 stackVal1Int64 && stackVal2 is CilStackValueInt64 stackVal2Int64)
            {
                return(computeInt64Int64(stackVal1Int64, stackVal2Int64));
            }
            if (stackVal1 is CilStackValueFloat stackVal1Float && stackVal2 is CilStackValueFloat stackVal2Float)
            {
                return(computeFloatFloat(stackVal1Float, stackVal2Float));
            }

            throw new System.NotImplementedException();
        }
Ejemplo n.º 5
0
 public void Pop(out IStackValue val1, out IStackValue val2)
 {
     Pop(out val2);
     Pop(out val1);
 }
Ejemplo n.º 6
0
 public void Pop(out IStackValue val)
 {
     val = Pop();
 }
Ejemplo n.º 7
0
 public void Push(IStackValue val)
 {
     _stack.Push(val);
 }
Ejemplo n.º 8
0
        private IValue ConvertToValue(IStackValue stackVal, Type valType)
        {
            if (stackVal is CilStackValueValueType stackValValueType)
            {
                if (valType == typeof(CilValueValueType))
                {
                    return(new CilValueValueType(stackValValueType.Value));
                }
            }

            if (stackVal is CilStackValueInt32 stackValIn64)
            {
                if (valType == typeof(CilValueValueType))
                {
                    return(new CilValueInt32(stackValIn64.Value));
                }
            }

            if (stackVal is CilStackValuePointer stackValPointer)
            {
                if (valType == typeof(CilValueManagedPointer))
                {
                    return(new CilValueManagedPointer(stackValPointer.ValueToRef));
                }
                if (valType == stackValPointer.ValueToRef.GetType())
                {
                    return(stackValPointer.ValueToRef);
                }
                if (valType == typeof(CilValueExternal))
                {
                    return(stackValPointer.ValueToRef);
                }
            }

            if (valType == typeof(CilValueInt8))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueInt8((sbyte)stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueInt16))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueInt16((short)stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueInt32))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueInt32(stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueInt64))
            {
                if (stackVal is CilStackValueInt64 stackValInt64)
                {
                    return(new CilValueInt64(stackValInt64.Value));
                }
            }

            if (valType == typeof(CilValueUInt8))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueUInt8((byte)stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueUInt16))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueUInt16((ushort)stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueUInt32))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueUInt32((uint)stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueUInt64))
            {
                if (stackVal is CilStackValueInt64 stackValInt64)
                {
                    return(new CilValueUInt64((ulong)stackValInt64.Value));
                }
            }

            if (valType == typeof(CilValueChar))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueChar((char)stackValInt32.Value));
                }
            }

            if (valType == typeof(CilValueFloat32))
            {
                if (stackVal is CilStackValueFloat stackValFloat)
                {
                    return(new CilValueFloat32((float)stackValFloat.Value));
                }
            }

            if (valType == typeof(CilValueFloat64))
            {
                if (stackVal is CilStackValueFloat stackValFloat)
                {
                    return(new CilValueFloat64(stackValFloat.Value));
                }
            }

            if (valType == typeof(CilValueReference))
            {
                if (stackVal is CilStackValueReference stackValReference)
                {
                    return(new CilValueReference(stackValReference.Address));
                }
            }

            if (valType == typeof(CilValueExternal))
            {
                if (stackVal is CilStackValueExternal stackValExternal)
                {
                    return(new CilValueExternal(stackValExternal.ExternalValue));
                }
            }

            if (valType == typeof(CilValueBool))
            {
                if (stackVal is CilStackValueInt32 stackValInt32)
                {
                    return(new CilValueBool(stackValInt32.Value != 0));
                }
            }

            throw new NotImplementedException();
        }