2019-07-29 02:05:05 +08:00
|
|
|
|
#Region "Microsoft.VisualBasic::07b523fb539260b7cd01bff7c4c2311e, Microsoft.VisualBasic.Core\Language\Runtime.vb"
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
2019-03-22 22:19:09 +08:00
|
|
|
|
' Author:
|
|
|
|
|
|
'
|
|
|
|
|
|
' asuka (amethyst.asuka@gcmodeller.org)
|
|
|
|
|
|
' xie (genetics@smrucc.org)
|
|
|
|
|
|
' xieguigang (xie.guigang@live.com)
|
|
|
|
|
|
'
|
|
|
|
|
|
' Copyright (c) 2018 GPL3 Licensed
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' GNU GENERAL PUBLIC LICENSE (GPL3)
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
' it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
' the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
' (at your option) any later version.
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
' GNU General Public License for more details.
|
|
|
|
|
|
'
|
|
|
|
|
|
' You should have received a copy of the GNU General Public License
|
|
|
|
|
|
' along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-03-11 18:14:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-22 22:19:09 +08:00
|
|
|
|
' /********************************************************************************/
|
2019-03-11 18:14:59 +08:00
|
|
|
|
|
2019-03-22 22:19:09 +08:00
|
|
|
|
' Summaries:
|
2019-03-11 18:14:59 +08:00
|
|
|
|
|
2019-03-22 22:19:09 +08:00
|
|
|
|
' Class ArgumentReference
|
|
|
|
|
|
'
|
|
|
|
|
|
' Properties: Expression, Key, ValueType
|
|
|
|
|
|
'
|
2019-05-06 18:27:46 +08:00
|
|
|
|
' Function: [As], GetUnderlyingType, ToString
|
2019-03-22 22:19:09 +08:00
|
|
|
|
' Operators: <>, =
|
|
|
|
|
|
'
|
|
|
|
|
|
' Class TypeSchema
|
|
|
|
|
|
'
|
|
|
|
|
|
' Properties: Type
|
|
|
|
|
|
'
|
|
|
|
|
|
' Constructor: (+1 Overloads) Sub New
|
|
|
|
|
|
' Function: Equals, ToString
|
|
|
|
|
|
' Operators: (+2 Overloads) And, (+2 Overloads) Or
|
|
|
|
|
|
'
|
|
|
|
|
|
' Class Runtime
|
|
|
|
|
|
'
|
|
|
|
|
|
' Function: ToString
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' /********************************************************************************/
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
|
|
Imports System.Runtime.CompilerServices
|
|
|
|
|
|
Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic
|
2019-03-11 18:14:59 +08:00
|
|
|
|
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel.Repository
|
|
|
|
|
|
Imports Microsoft.VisualBasic.Emit.Delegates
|
|
|
|
|
|
Imports Microsoft.VisualBasic.Language.Default
|
|
|
|
|
|
|
|
|
|
|
|
Namespace Language
|
|
|
|
|
|
|
2019-03-11 18:14:59 +08:00
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' ``[name => value]`` tuple
|
|
|
|
|
|
''' </summary>
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Public Class ArgumentReference : Inherits Value
|
2019-03-15 18:19:37 +08:00
|
|
|
|
Implements INamedValue
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
Private Property Key As String Implements IKeyedEntity(Of String).Key
|
|
|
|
|
|
Get
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Return Name
|
2018-08-02 20:14:48 +08:00
|
|
|
|
End Get
|
|
|
|
|
|
Set(value As String)
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Name = value
|
2018-08-02 20:14:48 +08:00
|
|
|
|
End Set
|
|
|
|
|
|
End Property
|
|
|
|
|
|
|
|
|
|
|
|
Public ReadOnly Property Expression(Optional null$ = "Nothing",
|
|
|
|
|
|
Optional stringEscaping As Func(Of String, String) = Nothing,
|
|
|
|
|
|
Optional isVar As Assert(Of String) = Nothing) As String
|
|
|
|
|
|
Get
|
|
|
|
|
|
Dim val$
|
|
|
|
|
|
|
2019-05-22 19:02:42 +08:00
|
|
|
|
Static [isNot] As New [Default](Of Assert(Of String))(Function(var) False)
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
If value Is Nothing Then
|
|
|
|
|
|
val = null
|
|
|
|
|
|
ElseIf value.GetType Is GetType(String) Then
|
2019-03-19 21:03:20 +08:00
|
|
|
|
' string can be a variable name
|
2018-08-02 20:14:48 +08:00
|
|
|
|
If (isVar Or [isNot])(value) Then
|
|
|
|
|
|
val = value
|
|
|
|
|
|
Else
|
|
|
|
|
|
val = $"""{(stringEscaping Or noEscaping)(value)}"""
|
|
|
|
|
|
End If
|
|
|
|
|
|
ElseIf value.GetType Is GetType(Char) Then
|
|
|
|
|
|
val = $"""{value}"""
|
|
|
|
|
|
Else
|
|
|
|
|
|
val = value
|
|
|
|
|
|
End If
|
|
|
|
|
|
|
|
|
|
|
|
Return $"{name} = {val}"
|
|
|
|
|
|
End Get
|
|
|
|
|
|
End Property
|
|
|
|
|
|
|
2019-03-15 18:19:37 +08:00
|
|
|
|
Public ReadOnly Property ValueType As Type
|
|
|
|
|
|
Get
|
|
|
|
|
|
If value Is Nothing Then
|
|
|
|
|
|
Return GetType(Void)
|
|
|
|
|
|
Else
|
|
|
|
|
|
Return value.GetType
|
|
|
|
|
|
End If
|
|
|
|
|
|
End Get
|
|
|
|
|
|
End Property
|
|
|
|
|
|
|
2019-03-30 17:57:43 +08:00
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Public Overrides Function GetUnderlyingType() As Type
|
|
|
|
|
|
Return ValueType
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
2019-03-11 18:14:59 +08:00
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Public Function [As](Of T)() As NamedValue(Of T)
|
|
|
|
|
|
Return New NamedValue(Of T)(name, value)
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Public Overrides Function ToString() As String
|
|
|
|
|
|
Return $"Dim {name} As Object = {Scripting.ToString(value, "null")}"
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Argument variable value assign
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="var">The argument name</param>
|
|
|
|
|
|
''' <param name="value">argument value</param>
|
|
|
|
|
|
''' <returns></returns>
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Public Overloads Shared Operator =(var As ArgumentReference, value As Object) As ArgumentReference
|
|
|
|
|
|
var.Value = value
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Return var
|
|
|
|
|
|
End Operator
|
|
|
|
|
|
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Public Overloads Shared Operator <>(var As ArgumentReference, value As Object) As ArgumentReference
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Throw New NotImplementedException
|
|
|
|
|
|
End Operator
|
2019-03-11 18:14:59 +08:00
|
|
|
|
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Public Overloads Shared Narrowing Operator CType(arg As ArgumentReference) As (name As String, value As Object)
|
|
|
|
|
|
Return (arg.Name, arg.Value)
|
2019-03-11 18:14:59 +08:00
|
|
|
|
End Operator
|
2019-03-15 18:19:37 +08:00
|
|
|
|
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
2019-03-30 17:57:43 +08:00
|
|
|
|
Public Overloads Shared Widening Operator CType(name As String) As ArgumentReference
|
|
|
|
|
|
Return New ArgumentReference With {.Name = name}
|
2019-03-15 18:19:37 +08:00
|
|
|
|
End Operator
|
2018-08-02 20:14:48 +08:00
|
|
|
|
End Class
|
|
|
|
|
|
|
|
|
|
|
|
Public Class TypeSchema
|
|
|
|
|
|
|
|
|
|
|
|
Public ReadOnly Property Type As Type
|
|
|
|
|
|
|
|
|
|
|
|
Sub New(type As Type)
|
|
|
|
|
|
Me.Type = type
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Public Overrides Function ToString() As String
|
|
|
|
|
|
Return Type.FullName
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Public Overloads Shared Operator And(info As TypeSchema, types As Type()) As Boolean
|
|
|
|
|
|
Return types.All(Function(t) Equals(info.Type, base:=t))
|
|
|
|
|
|
End Operator
|
|
|
|
|
|
|
|
|
|
|
|
Private Overloads Shared Function Equals(info As Type, base As Type) As Boolean
|
|
|
|
|
|
If info.IsInheritsFrom(base) Then
|
|
|
|
|
|
Return True
|
|
|
|
|
|
Else
|
|
|
|
|
|
If base.IsInterface AndAlso info.ImplementInterface(base) Then
|
|
|
|
|
|
Return True
|
|
|
|
|
|
Else
|
|
|
|
|
|
Return False
|
|
|
|
|
|
End If
|
|
|
|
|
|
End If
|
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Public Overloads Shared Operator Or(info As TypeSchema, types As Type()) As Boolean
|
|
|
|
|
|
Return types.Any(Function(t) Equals(info.Type, base:=t))
|
|
|
|
|
|
End Operator
|
|
|
|
|
|
End Class
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Runtime helper
|
|
|
|
|
|
'''
|
|
|
|
|
|
''' ```vbnet
|
|
|
|
|
|
''' Imports VB = Microsoft.VisualBasic.Language.Runtime
|
|
|
|
|
|
'''
|
|
|
|
|
|
''' With New VB
|
|
|
|
|
|
''' ' ...
|
|
|
|
|
|
''' End With
|
|
|
|
|
|
''' ```
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
Public Class Runtime
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Language syntax supports for argument list
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="name$"></param>
|
|
|
|
|
|
''' <returns></returns>
|
|
|
|
|
|
Default Public ReadOnly Property Argument(name$) As ArgumentReference
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Get
|
|
|
|
|
|
Return New ArgumentReference With {
|
|
|
|
|
|
.name = name
|
|
|
|
|
|
}
|
|
|
|
|
|
End Get
|
|
|
|
|
|
End Property
|
|
|
|
|
|
|
|
|
|
|
|
Public Overrides Function ToString() As String
|
|
|
|
|
|
Return "sciBASIC for VB.NET language runtime API"
|
|
|
|
|
|
End Function
|
|
|
|
|
|
End Class
|
|
|
|
|
|
End Namespace
|