@@ -8,14 +8,18 @@ module (*internal*) Microsoft.FSharp.Compiler.AbstractIL.IL
88
99
1010open Internal.Utilities
11+ #if FABLE_ COMPILER
12+ open Microsoft.FSharp .Collections
13+ open Microsoft.FSharp .Core
14+ #endif
1115open Microsoft.FSharp .Compiler .AbstractIL
1216open Microsoft.FSharp .Compiler .AbstractIL .Diagnostics
1317open Microsoft.FSharp .Compiler .AbstractIL .Internal
1418open Microsoft.FSharp .Compiler .AbstractIL .Internal .Library
1519open System.Collections
1620open System.Collections .Generic
1721open System.Collections .Concurrent
18-
22+
1923let logging = false
2024
2125let runningOnMono =
@@ -77,21 +81,21 @@ let rec splitNamespaceAux (nm:string) =
7781
7882/// Global State. All namespace splits ever seen
7983// ++GLOBAL MUTABLE STATE
84+ #if FABLE_ COMPILER
85+ let memoizeNamespaceTable = new Dictionary< string, string list>()
86+ let memoizeNamespaceRightTable = new Dictionary< string, string option * string>()
87+ let memoizeNamespaceArrayTable = Dictionary< string, string[]>()
88+ #else
8089let memoizeNamespaceTable = new ConcurrentDictionary< string, string list>()
81-
82- // ++GLOBAL MUTABLE STATE
8390let memoizeNamespaceRightTable = new ConcurrentDictionary< string, string option * string>()
84-
91+ let memoizeNamespaceArrayTable = ConcurrentDictionary< string, string[]>()
92+ #endif
8593
8694let splitNamespace nm =
8795 memoizeNamespaceTable.GetOrAdd( nm, splitNamespaceAux)
8896
8997let splitNamespaceMemoized nm = splitNamespace nm
9098
91- // ++GLOBAL MUTABLE STATE
92- let memoizeNamespaceArrayTable =
93- Concurrent.ConcurrentDictionary< string, string[]>()
94-
9599let splitNamespaceToArray nm =
96100 memoizeNamespaceArrayTable.GetOrAdd( nm, fun nm ->
97101 let x = Array.ofList ( splitNamespace nm)
@@ -373,6 +377,7 @@ type ILAssemblyRef(data) =
373377 assemRefVersion= version;
374378 assemRefLocale= locale; }
375379
380+ #if ! FABLE_ COMPILER
376381 static member FromAssemblyName ( aname : System.Reflection.AssemblyName ) =
377382 let locale = None
378383 //match aname.CultureInfo with
@@ -395,13 +400,12 @@ type ILAssemblyRef(data) =
395400 let retargetable = aname.Flags = System.Reflection.AssemblyNameFlags.Retargetable
396401
397402 ILAssemblyRef.Create( aname.Name, None, publicKey, retargetable, version, locale)
398-
399-
403+ #endif
400404
401405 member aref.QualifiedName =
402406 let b = new System.Text.StringBuilder( 100 )
403407 let add ( s : string ) = ( b.Append( s) |> ignore)
404- let addC ( s : char ) = ( b.Append( s) |> ignore)
408+ let addC ( s : char ) = ( b.Append( string s) |> ignore)
405409 add( aref.Name);
406410 match aref.Version with
407411 | None -> ()
@@ -468,7 +472,7 @@ type ILScopeRef =
468472 member scoref.QualifiedName =
469473 match scoref with
470474 | ILScopeRef.Local -> " "
471- | ILScopeRef.Module mref -> " module " ^ mref.Name
475+ | ILScopeRef.Module mref -> " module " + mref.Name
472476 | ILScopeRef.Assembly aref when aref.Name = " mscorlib" -> " "
473477 | ILScopeRef.Assembly aref -> aref.QualifiedName
474478
@@ -532,7 +536,6 @@ type ILBoxity =
532536 | AsObject
533537 | AsValue
534538
535-
536539// IL type references have a pre-computed hash code to enable quick lookup tables during binary generation.
537540[<CustomEquality; CustomComparison>]
538541type ILTypeRef =
@@ -568,12 +571,14 @@ type ILTypeRef =
568571 | _ -> ILType.Boxed tspec
569572
570573 override x.GetHashCode () = x.hashCode
571- override x.Equals ( yobj ) =
572- let y = ( yobj :?> ILTypeRef)
573- ( x.ApproxId = y.ApproxId) &&
574- ( x.Scope = y.Scope) &&
575- ( x.Name = y.Name) &&
576- ( x.Enclosing = y.Enclosing)
574+ override x.Equals ( yobj : obj ) =
575+ match yobj with
576+ | :? ILTypeRef as y ->
577+ ( x.ApproxId = y.ApproxId) &&
578+ ( x.Scope = y.Scope) &&
579+ ( x.Name = y.Name) &&
580+ ( x.Enclosing = y.Enclosing)
581+ | _ -> false
577582 interface System.IComparable with
578583 override x.CompareTo ( yobj ) =
579584 let y = ( yobj :?> ILTypeRef)
@@ -1365,10 +1370,10 @@ type ILMethodDef =
13651370 member x.IsNonVirtualInstance = match x.mdKind with | MethodKind.NonVirtual -> true | _ -> false
13661371 member x.IsVirtual = match x.mdKind with | MethodKind.Virtual _ -> true | _ -> false
13671372
1368- member x.IsFinal = match x.mdKind with | MethodKind.Virtual v -> v.IsFinal | _ -> invalidOp " not virtual"
1369- member x.IsNewSlot = match x.mdKind with | MethodKind.Virtual v -> v.IsNewSlot | _ -> invalidOp " not virtual"
1370- member x.IsCheckAccessOnOverride = match x.mdKind with | MethodKind.Virtual v -> v.IsCheckAccessOnOverride | _ -> invalidOp " not virtual"
1371- member x.IsAbstract = match x.mdKind with | MethodKind.Virtual v -> v.IsAbstract | _ -> invalidOp " not virtual"
1373+ member x.IsFinal = match x.mdKind with | MethodKind.Virtual v -> v.IsFinal | _ -> false // invalidOp "not virtual"
1374+ member x.IsNewSlot = match x.mdKind with | MethodKind.Virtual v -> v.IsNewSlot | _ -> false // invalidOp "not virtual"
1375+ member x.IsCheckAccessOnOverride = match x.mdKind with | MethodKind.Virtual v -> v.IsCheckAccessOnOverride | _ -> false // invalidOp "not virtual"
1376+ member x.IsAbstract = match x.mdKind with | MethodKind.Virtual v -> v.IsAbstract | _ -> false // invalidOp "not virtual"
13721377
13731378 member md.CallingSignature = mkILCallSig ( md.CallingConv, md.ParameterTypes, md.Return.Type)
13741379
@@ -1552,7 +1557,7 @@ and [<Sealed>] ILTypeDefs(f : unit -> (string list * string * ILAttributes * Laz
15521557 let mutable array = InlineDelayInit<_>( f)
15531558 let mutable dict = InlineDelayInit<_>( fun () ->
15541559 let arr = array.Value
1555- let t = Dictionary<_,_>( HashIdentity.Structural)
1560+ let t = Dictionary<_,_>( 3 , HashIdentity.Structural)
15561561 for ( nsp, nm, _ attr, ltd) in arr do
15571562 let key = nsp, nm
15581563 t.[ key] <- ltd
@@ -3661,7 +3666,11 @@ type ILTypeSigParser(tstring : string) =
36613666 // fetch the arity
36623667 let arity =
36633668 while ( int( here()) >= ( int( '0' ))) && ( int( here()) <= (( int( '9' )))) && ( int( peek()) >= ( int( '0' ))) && ( int( peek()) <= (( int( '9' )))) do step()
3669+ #if FABLE_ COMPILER
3670+ System.Convert.ToInt32( take())
3671+ #else
36643672 System.Int32.Parse( take())
3673+ #endif
36653674 // skip the '['
36663675 drop()
36673676 // get the specializations
@@ -3699,7 +3708,11 @@ type ILTypeSigParser(tstring : string) =
36993708 yield grabScopeComponent() // culture
37003709 yield grabScopeComponent() // public key token
37013710 ] |> String.concat " ,"
3711+ #if FABLE_ COMPILER
3712+ ILScopeRef.Assembly( mkSimpleAssRef scope)
3713+ #else
37023714 ILScopeRef.Assembly( ILAssemblyRef.FromAssemblyName( System.Reflection.AssemblyName( scope)))
3715+ #endif
37033716 else
37043717 ILScopeRef.Local
37053718
@@ -3844,7 +3857,11 @@ let decodeILAttribData ilg (ca: ILAttribute) =
38443857 pieces.[ 0 ], None
38453858 let scoref =
38463859 match rest with
3860+ #if FABLE_ COMPILER
3861+ | Some aname -> ILScopeRef.Assembly( mkSimpleAssRef aname)
3862+ #else
38473863 | Some aname -> ILScopeRef.Assembly( ILAssemblyRef.FromAssemblyName( System.Reflection.AssemblyName( aname)))
3864+ #endif
38483865 | None -> ilg.traits.ScopeRef
38493866
38503867 let tref = mkILTyRef ( scoref, unqualified_ tname)
@@ -4105,13 +4122,18 @@ let parseILVersion (vstr : string) =
41054122 // Set the revision number to number of seconds today / 2
41064123 versionComponents.[ 3 ] <- defaultRevision.ToString() ;
41074124 vstr <- System.String.Join( " ." , versionComponents) ;
4108-
4125+
4126+ #if FABLE_ COMPILER
4127+ let parts = vstr.Split([| '.' |])
4128+ let versions = Array.append ( Array.map uint16 parts) [| 0 us; 0 us; 0 us; 0 us|]
4129+ ( versions.[ 0 ], versions.[ 1 ], versions.[ 2 ], versions.[ 3 ])
4130+ #else
41094131 let version = System.Version( vstr)
41104132 let zero32 n = if n < 0 then 0 us else uint16( n)
41114133 // since the minor revision will be -1 if none is specified, we need to truncate to 0 to not break existing code
41124134 let minorRevision = if version.Revision = - 1 then 0 us else uint16( version.MinorRevision)
41134135 ( zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision);;
4114-
4136+ #endif
41154137
41164138let compareILVersions ( a1 , a2 , a3 , a4 ) (( b1 , b2 , b3 , b4 ) : ILVersionInfo ) =
41174139 let c = compare a1 b1
0 commit comments