@@ -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
@@ -1552,7 +1556,7 @@ and [<Sealed>] ILTypeDefs(f : unit -> (string list * string * ILAttributes * Laz
15521556 let mutable array = InlineDelayInit<_>( f)
15531557 let mutable dict = InlineDelayInit<_>( fun () ->
15541558 let arr = array.Value
1555- let t = Dictionary<_,_>( HashIdentity.Structural)
1559+ let t = Dictionary<_,_>( 3 , HashIdentity.Structural)
15561560 for ( nsp, nm, _ attr, ltd) in arr do
15571561 let key = nsp, nm
15581562 t.[ key] <- ltd
@@ -3661,7 +3665,11 @@ type ILTypeSigParser(tstring : string) =
36613665 // fetch the arity
36623666 let arity =
36633667 while ( int( here()) >= ( int( '0' ))) && ( int( here()) <= (( int( '9' )))) && ( int( peek()) >= ( int( '0' ))) && ( int( peek()) <= (( int( '9' )))) do step()
3668+ #if FABLE_ COMPILER
3669+ System.Convert.ToInt32( take())
3670+ #else
36643671 System.Int32.Parse( take())
3672+ #endif
36653673 // skip the '['
36663674 drop()
36673675 // get the specializations
@@ -3699,7 +3707,11 @@ type ILTypeSigParser(tstring : string) =
36993707 yield grabScopeComponent() // culture
37003708 yield grabScopeComponent() // public key token
37013709 ] |> String.concat " ,"
3710+ #if FABLE_ COMPILER
3711+ ILScopeRef.Assembly( mkSimpleAssRef scope)
3712+ #else
37023713 ILScopeRef.Assembly( ILAssemblyRef.FromAssemblyName( System.Reflection.AssemblyName( scope)))
3714+ #endif
37033715 else
37043716 ILScopeRef.Local
37053717
@@ -3844,7 +3856,11 @@ let decodeILAttribData ilg (ca: ILAttribute) =
38443856 pieces.[ 0 ], None
38453857 let scoref =
38463858 match rest with
3859+ #if FABLE_ COMPILER
3860+ | Some aname -> ILScopeRef.Assembly( mkSimpleAssRef aname)
3861+ #else
38473862 | Some aname -> ILScopeRef.Assembly( ILAssemblyRef.FromAssemblyName( System.Reflection.AssemblyName( aname)))
3863+ #endif
38483864 | None -> ilg.traits.ScopeRef
38493865
38503866 let tref = mkILTyRef ( scoref, unqualified_ tname)
@@ -4105,13 +4121,18 @@ let parseILVersion (vstr : string) =
41054121 // Set the revision number to number of seconds today / 2
41064122 versionComponents.[ 3 ] <- defaultRevision.ToString() ;
41074123 vstr <- System.String.Join( " ." , versionComponents) ;
4108-
4124+
4125+ #if FABLE_ COMPILER
4126+ let parts = vstr.Split([| '.' |])
4127+ let versions = Array.append ( Array.map uint16 parts) [| 0 us; 0 us; 0 us; 0 us|]
4128+ ( versions.[ 0 ], versions.[ 1 ], versions.[ 2 ], versions.[ 3 ])
4129+ #else
41094130 let version = System.Version( vstr)
41104131 let zero32 n = if n < 0 then 0 us else uint16( n)
41114132 // since the minor revision will be -1 if none is specified, we need to truncate to 0 to not break existing code
41124133 let minorRevision = if version.Revision = - 1 then 0 us else uint16( version.MinorRevision)
41134134 ( zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision);;
4114-
4135+ #endif
41154136
41164137let compareILVersions ( a1 , a2 , a3 , a4 ) (( b1 , b2 , b3 , b4 ) : ILVersionInfo ) =
41174138 let c = compare a1 b1
0 commit comments