⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emitter.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 5 页
字号:
            Case TypeCode.DateTime, TypeCode.Decimal                EmitStoreObject(Info, ElementType)                Return            Case TypeCode.String                Info.ILGen.Emit(OpCodes.Stelem_Ref)            Case TypeCode.Object                If ElementType.IsValueType Then                    Info.ILGen.Emit(OpCodes.Stobj, ElementType)                ElseIf ElementType.IsGenericParameter Then                    Info.ILGen.Emit(OpCodes.Stelem, ElementType)                Else                    Info.ILGen.Emit(OpCodes.Stelem_Ref)                End If            Case Else                Helper.Stop()        End Select        Info.Stack.Pop(ElementType)        Info.Stack.Pop(Info.Compiler.TypeCache.System_Int32)        Info.Stack.Pop(ArrayType)    End Sub    ''' <summary>    ''' Emits a Stobj instruction.    ''' </summary>    ''' <param name="Info"></param>    ''' <param name="ElementType"></param>    ''' <remarks></remarks>    Shared Sub EmitStoreObject(ByVal Info As EmitInfo, ByVal ElementType As Type)        ElementType = Helper.GetTypeOrTypeBuilder(ElementType)        Info.ILGen.Emit(OpCodes.Stobj, ElementType)        Info.Stack.Pop(ElementType)        Info.Stack.Pop(Info.Compiler.TypeManager.MakeByRefType(CType(Info.Method, ParsedObject), ElementType))    End Sub    ''' <summary>    ''' Emits a Ldobj instruction.    ''' </summary>    ''' <param name="Info"></param>    ''' <param name="ElementType"></param>    ''' <remarks></remarks>    Shared Sub EmitLoadObject(ByVal Info As EmitInfo, ByVal ElementType As Type)        ElementType = Helper.GetTypeOrTypeBuilder(ElementType)        Info.ILGen.Emit(OpCodes.Ldobj, ElementType)        Info.Stack.Pop(Info.Compiler.TypeManager.MakeByRefType(CType(Info.Method, ParsedObject), ElementType))        Info.Stack.Push(ElementType)    End Sub    ''' <summary>    ''' Creates a new array and the new array reference is loaded at the top of the stack.    ''' </summary>    ''' <param name="Info"></param>    ''' <param name="ElementType"></param>    ''' <param name="Elements"></param>    ''' <remarks></remarks>    Shared Sub CreateArray(ByVal Info As EmitInfo, ByVal ElementType As Type, ByVal Elements As Integer)        ElementType = Helper.GetTypeOrTypeBuilder(ElementType)        EmitLoadValue(Info.Clone(True, False, Info.Compiler.TypeCache.System_Int32), Elements)        EmitNewArr(Info, ElementType)    End Sub      Shared Sub EmitLoadI8Value(ByVal Info As EmitInfo, ByVal I As ULong, ByVal TypeToPushOnStack As Type)        TypeToPushOnStack = Helper.GetTypeOrTypeBuilder(TypeToPushOnStack)        EmitLoadI8Value(Info, BitConverter.ToInt64(BitConverter.GetBytes(I), 0), TypeToPushOnStack)    End Sub    Shared Sub EmitLoadI8Value(ByVal Info As EmitInfo, ByVal I As ULong)        EmitLoadI8Value(Info, BitConverter.ToInt64(BitConverter.GetBytes(I), 0), Info.Compiler.TypeCache.System_UInt64)    End Sub    Shared Sub EmitLoadI8Value(ByVal Info As EmitInfo, ByVal I As Long)        Info.ILGen.Emit(OpCodes.Ldc_I8, I)        Info.Stack.Push(Info.Compiler.TypeCache.System_Int64)    End Sub    Shared Sub EmitLoadI8Value(ByVal Info As EmitInfo, ByVal I As Long, ByVal TypeToPushOnStack As Type)        TypeToPushOnStack = Helper.GetTypeOrTypeBuilder(TypeToPushOnStack)        Info.ILGen.Emit(OpCodes.Ldc_I8, I)        Info.Stack.Push(TypeToPushOnStack)    End Sub    Shared Sub EmitLoadR8Value(ByVal Info As EmitInfo, ByVal I As Double)        Info.ILGen.Emit(OpCodes.Ldc_R8, I)        Info.Stack.Push(Info.Compiler.TypeCache.System_Double)    End Sub    Shared Sub EmitLoadR8Value(ByVal Info As EmitInfo, ByVal I As Double, ByVal TypeToPushOnStack As Type)        TypeToPushOnStack = Helper.GetTypeOrTypeBuilder(TypeToPushOnStack)        Info.ILGen.Emit(OpCodes.Ldc_R8, I)        Info.Stack.Push(TypeToPushOnStack)    End Sub    Shared Sub EmitLoadR4Value(ByVal Info As EmitInfo, ByVal I As Single)        Info.ILGen.Emit(OpCodes.Ldc_R4, I)        Info.Stack.Push(Info.Compiler.TypeCache.System_Single)    End Sub    Shared Sub EmitLoadI4Value(ByVal Info As EmitInfo, ByVal I As Integer, ByVal TypeToPushOnStack As Type)        TypeToPushOnStack = Helper.GetTypeOrTypeBuilder(TypeToPushOnStack)        Select Case I            Case -1                Info.ILGen.Emit(OpCodes.Ldc_I4_M1)            Case 0                Info.ILGen.Emit(OpCodes.Ldc_I4_0)            Case 1                Info.ILGen.Emit(OpCodes.Ldc_I4_1)            Case 2                Info.ILGen.Emit(OpCodes.Ldc_I4_2)            Case 3                Info.ILGen.Emit(OpCodes.Ldc_I4_3)            Case 4                Info.ILGen.Emit(OpCodes.Ldc_I4_4)            Case 5                Info.ILGen.Emit(OpCodes.Ldc_I4_5)            Case 6                Info.ILGen.Emit(OpCodes.Ldc_I4_6)            Case 7                Info.ILGen.Emit(OpCodes.Ldc_I4_7)            Case 8                Info.ILGen.Emit(OpCodes.Ldc_I4_8)            Case SByte.MinValue To SByte.MaxValue                Dim sbit As SByte = CSByte(I)                Info.ILGen.Emit(OpCodes.Ldc_I4_S, sbit)            Case Else                Info.ILGen.Emit(OpCodes.Ldc_I4, I)        End Select        Info.Stack.Push(TypeToPushOnStack)    End Sub    Shared Sub EmitLoadR4Value(ByVal Info As EmitInfo, ByVal I As Single, ByVal TypeToPushOnStack As Type)        TypeToPushOnStack = Helper.GetTypeOrTypeBuilder(TypeToPushOnStack)        Info.ILGen.Emit(OpCodes.Ldc_R4, I)        Info.Stack.Push(TypeToPushOnStack)    End Sub    Shared Sub EmitLoadI4Value(ByVal Info As EmitInfo, ByVal I As Boolean)        If I Then            EmitLoadI4Value(Info, -1, Info.Compiler.TypeCache.System_Boolean)        Else            EmitLoadI4Value(Info, 0, Info.Compiler.TypeCache.System_Boolean)        End If    End Sub    Shared Sub EmitLoadI4Value(ByVal Info As EmitInfo, ByVal I As UInteger)        EmitLoadI4Value(Info, BitConverter.ToInt32(BitConverter.GetBytes(I), 0), Info.Compiler.TypeCache.System_UInt32)    End Sub    Shared Sub EmitLoadI4Value(ByVal Info As EmitInfo, ByVal I As UInteger, ByVal TypeToPushOnStack As Type)        TypeToPushOnStack = Helper.GetTypeOrTypeBuilder(TypeToPushOnStack)        EmitLoadI4Value(Info, BitConverter.ToInt32(BitConverter.GetBytes(I), 0), TypeToPushOnStack)    End Sub    Shared Sub EmitLoadI4Value(ByVal Info As EmitInfo, ByVal I As Integer)        EmitLoadI4Value(Info, I, Info.Compiler.TypeCache.System_Int32)    End Sub    ''' <summary>    ''' Loads an value of the desired type onto the evaluation stack.    ''' </summary>    ''' <param name="Info"></param>    ''' <param name="Value"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Overloads Shared Function EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As Integer) As Boolean        Helper.Assert(Info.DesiredType IsNot Nothing)        Dim tmp As EmitInfo = Info        Dim DesiredTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, Info.DesiredType)        Select Case DesiredTypeCode            Case TypeCode.SByte, TypeCode.Int16, TypeCode.Int32, TypeCode.Boolean                EmitLoadI4Value(Info, Value, Info.DesiredType)                Return True            Case TypeCode.Int64                EmitLoadI8Value(Info, Value, Info.DesiredType)                Return True            Case TypeCode.Byte, TypeCode.UInt16                EmitLoadI4Value(Info, CUInt(Value), Info.DesiredType)                Return True            Case TypeCode.UInt32                If Value <= UInteger.MaxValue AndAlso Value >= UInteger.MinValue Then                    EmitLoadI4Value(Info, CUInt(Value), Info.DesiredType)                    Return True                End If            Case TypeCode.UInt64                If Value <= ULong.MaxValue AndAlso Value >= ULong.MinValue Then                    EmitLoadValue(tmp, CULng(Value))                    Return True                End If            Case TypeCode.Single                EmitLoadR4Value(tmp, CSng(Value))                Return True            Case TypeCode.Double                EmitLoadR8Value(tmp, CDbl(Value))                Return True            Case TypeCode.Decimal                EmitLoadDecimalValue(tmp, CDec(Value))                Return True            Case TypeCode.Object                EmitLoadI4Value(tmp, Value)                EmitBox(Info, Info.Compiler.TypeCache.System_Int32)                Return True        End Select        Helper.NotImplemented()    End Function    Overloads Shared Function EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As Long) As Boolean        Helper.Assert(Info.DesiredType IsNot Nothing)        Dim DesiredTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, Info.DesiredType)        If Value <= Integer.MaxValue AndAlso Value >= Integer.MinValue Then            Return EmitLoadValue(Info, CInt(Value))        End If        Dim tmp As EmitInfo = Info.Clone(CType(Nothing, TypeDescriptor))        Select Case DesiredTypeCode            Case TypeCode.Single                EmitLoadValue(tmp, CSng(Value))                Return True            Case TypeCode.Double                EmitLoadValue(tmp, CDbl(Value))                Return True            Case TypeCode.Decimal                EmitLoadValue(tmp, CDec(Value))                Return True        End Select        Return False    End Function    Overloads Shared Function EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As ULong) As Boolean        Helper.Assert(Info.DesiredType IsNot Nothing)        Dim DesiredTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, Info.DesiredType)        Dim tmp As EmitInfo = Info        'If Value <= Integer.MaxValue AndAlso Value >= Integer.MinValue Then        '    Helper.NotImplemented() 'Return EmitLoadValue(Info, CInt(Value))        'ElseIf Value <= Long.MaxValue AndAlso Value >= Long.MinValue Then        '    Return EmitLoadValue(Info, CLng(Value))        'End If        Select Case DesiredTypeCode            Case TypeCode.Single                EmitLoadValue(tmp, CSng(Value))                Return True            Case TypeCode.Double                EmitLoadValue(tmp, CDbl(Value))                Return True            Case TypeCode.Decimal                EmitLoadValue(tmp, CDec(Value))                Return True            Case TypeCode.Int64, TypeCode.UInt64                EmitLoadI8Value(Info, Value)                Return True        End Select        Helper.NotImplemented()        Return False    End Function    Overloads Shared Function EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As Decimal) As Boolean        Dim DesiredTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, Info.DesiredType)        Helper.Assert(Info.DesiredType IsNot Nothing)        If Math.Truncate(Value) = Value Then            If Value <= Integer.MaxValue AndAlso Value >= Integer.MinValue Then                Return EmitLoadValue(Info, CInt(Value))            ElseIf Value <= Long.MaxValue AndAlso Value >= Long.MinValue Then                Return EmitLoadValue(Info, CLng(Value))            ElseIf Value <= ULong.MaxValue AndAlso Value >= Long.MinValue Then                Return EmitLoadValue(Info, CULng(Value))            End If        End If        Dim tmp As EmitInfo = Info.Clone(CType(Nothing, TypeDescriptor))        Select Case DesiredTypeCode            Case TypeCode.Single                EmitLoadValue(tmp, CSng(Value))                Return True            Case TypeCode.Double                EmitLoadValue(tmp, CDbl(Value))                Return True        End Select        Return False    End Function    Overloads Shared Function EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As Double) As Boolean        Helper.Assert(Info.DesiredType IsNot Nothing)        Dim DesiredTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, Info.DesiredType)        Dim tmp As EmitInfo = Info        Select Case DesiredTypeCode            Case TypeCode.Single                If Value <= Single.MaxValue AndAlso Value >= Single.MinValue Then                    EmitLoadValue(tmp, CSng(Value))                    Return True                End If        End Select        Return False    End Function    '''' <summary>    '''' Loads the integer onto the stack.    '''' </summary>    '''' <param name="Info"></param>    '''' <param name="Value"></param>    '''' <remarks></remarks>    'Shared Sub EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As Integer)    '    EmitLoadI4Value(Info, Value)    '    Info.Stack.Push(Info.Compiler.TypeCache.Integer)    'End Sub    ''' <summary>    ''' Loads the integer onto the stack.    ''' </summary>    ''' <param name="Info"></param>    ''' <param name="Value"></param>    ''' <remarks></remarks>    Overloads Shared Sub EmitLoadValue(ByVal Info As EmitInfo, ByVal Value As String)        Info.ILGen.Emit(OpCodes.Ldstr, Value)        Info.Stack.Push(Info.Compiler.TypeCache.System_String)    End Sub    ''' <summary>   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -