Skip to content

Commit 4f75bd8

Browse files
committed
[WIP] Fable support
1 parent 729bdbf commit 4f75bd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+7928
-1882
lines changed

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node2",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"program": "${workspaceRoot}/src/fsharp/Fable.FCS/out/Fable.FCS/project.js",
12+
"cwd": "${workspaceRoot}"
13+
},
14+
{
15+
"type": "node2",
16+
"request": "attach",
17+
"name": "Attach to Process",
18+
"port": 5858
19+
}
20+
]
21+
}

Export.FCS.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25420.1
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service", "src\fsharp\FSharp.Compiler.Service\FSharp.Compiler.Service.fsproj", "{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}"
6+
EndProject
7+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Export.FCS", "src\fsharp\Export.FCS\Export.FCS.fsproj", "{C89727FE-5D40-4DE2-B751-753D75C86E4C}"
8+
EndProject
9+
Global
10+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
11+
Debug|Any CPU = Debug|Any CPU
12+
Release|Any CPU = Release|Any CPU
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{2E4D67B4-522D-4CF7-97E4-BA940F0B18F3}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{C89727FE-5D40-4DE2-B751-753D75C86E4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{C89727FE-5D40-4DE2-B751-753D75C86E4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{C89727FE-5D40-4DE2-B751-753D75C86E4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{C89727FE-5D40-4DE2-B751-753D75C86E4C}.Release|Any CPU.Build.0 = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(SolutionProperties) = preSolution
25+
HideSolutionNode = FALSE
26+
EndGlobalSection
27+
EndGlobal

build.fsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,27 @@ Target "CodeGen.NetCore" (fun _ ->
272272
let fsLex fsl out = runInDir (toolDir + "fslex.exe") "%s --unicode %s -o %s" fsl lexArgs out
273273
let fsYacc fsy out m o = runInDir (toolDir + "fsyacc.exe") "%s %s %s %s %s -o %s" fsy lexArgs yaccArgs m o out
274274

275+
#if FABLE_COMPILER
276+
// until a more recent version of fssrgen is released, building from source
277+
runInDir "dotnet" "run -c Release -p /Projects/FsSrGen/src/dotnet-fssrgen ../FSComp.txt ./FSComp.fs"
278+
runInDir "dotnet" "run -c Release -p /Projects/FsSrGen/src/dotnet-fssrgen ../fsi/FSIstrings.txt ./FSIstrings.fs"
279+
#else
275280
runInDir "dotnet" "fssrgen ../FSComp.txt ./FSComp.fs ./FSComp.resx"
276281
runInDir "dotnet" "fssrgen ../fsi/FSIstrings.txt ./FSIstrings.fs ./FSIstrings.resx"
282+
#endif
277283
fsLex "../lex.fsl" "lex.fs"
278284
fsLex "../pplex.fsl" "pplex.fs"
279285
fsLex "../../absil/illex.fsl" "illex.fs"
280286
fsYacc "../../absil/ilpars.fsy" "ilpars.fs" module1 open1
281287
fsYacc "../pars.fsy" "pars.fs" module2 open2
282288
fsYacc "../pppars.fsy" "pppars.fs" module3 open3
289+
290+
#if FABLE_COMPILER
291+
// comments the #line directive as it is not supported by Fable
292+
["lex.fs"; "pplex.fs"; "illex.fs"; "ilpars.fs"; "pars.fs"; "pppars.fs"]
293+
|> Seq.map (fun fileName -> IO.Path.Combine (workDir, fileName))
294+
|> RegexReplaceInFilesWithEncoding @"# (?=\d)" "//# " Text.Encoding.UTF8
295+
#endif
283296
)
284297

285298
Target "Build.NetCore" (fun _ ->

global.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"projects": [ "src/fsharp", "tests" ]
2+
"projects": [ "src/fsharp", "tests" ],
3+
"sdk": {
4+
"version": "1.0.0-preview2-003131"
5+
}
36
}

src/absil/il.fs

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ module (*internal*) Microsoft.FSharp.Compiler.AbstractIL.IL
88

99

1010
open Internal.Utilities
11+
#if FABLE_COMPILER
12+
open Microsoft.FSharp.Collections
13+
open Microsoft.FSharp.Core
14+
#endif
1115
open Microsoft.FSharp.Compiler.AbstractIL
1216
open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
1317
open Microsoft.FSharp.Compiler.AbstractIL.Internal
1418
open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
1519
open System.Collections
1620
open System.Collections.Generic
1721
open System.Collections.Concurrent
18-
22+
1923
let logging = false
2024

2125
let 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
8089
let memoizeNamespaceTable = new ConcurrentDictionary<string,string list>()
81-
82-
// ++GLOBAL MUTABLE STATE
8390
let memoizeNamespaceRightTable = new ConcurrentDictionary<string,string option * string>()
84-
91+
let memoizeNamespaceArrayTable = ConcurrentDictionary<string,string[]>()
92+
#endif
8593

8694
let splitNamespace nm =
8795
memoizeNamespaceTable.GetOrAdd(nm, splitNamespaceAux)
8896

8997
let splitNamespaceMemoized nm = splitNamespace nm
9098

91-
// ++GLOBAL MUTABLE STATE
92-
let memoizeNamespaceArrayTable =
93-
Concurrent.ConcurrentDictionary<string,string[]>()
94-
9599
let 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>]
538541
type 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) [|0us;0us;0us;0us|]
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 0us 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 0us else uint16(version.MinorRevision)
41134135
(zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision);;
4114-
4136+
#endif
41154137

41164138
let compareILVersions (a1,a2,a3,a4) ((b1,b2,b3,b4) : ILVersionInfo) =
41174139
let c = compare a1 b1

src/absil/il.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ type ILVersionInfo = uint16 * uint16 * uint16 * uint16
9999
[<Sealed>]
100100
type ILAssemblyRef =
101101
static member Create : name: string * hash: byte[] option * publicKey: PublicKey option * retargetable: bool * version: ILVersionInfo option * locale: string option -> ILAssemblyRef
102+
#if !FABLE_COMPILER
102103
static member FromAssemblyName : System.Reflection.AssemblyName -> ILAssemblyRef
104+
#endif
103105
member Name: string;
104106
/// The fully qualified name of the assembly reference, e.g. mscorlib, Version=1.0.3705 etc.
105107
member QualifiedName: string;

src/absil/ildiag.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ module internal Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
66

77
open Internal.Utilities
88

9+
#if FABLE_COMPILER
10+
let dprintf fmt = printf fmt
11+
let dprintfn fmt = printfn fmt
12+
let dprintn s = printfn "%s" s
13+
#else
14+
915
let diagnosticsLog = ref (Some stdout)
1016

1117
let setDiagnosticsChannel s = diagnosticsLog := s
@@ -21,3 +27,4 @@ let dprintf (fmt: Format<_,_,_,_>) =
2127
let dprintfn (fmt: Format<_,_,_,_>) =
2228
Printf.kfprintf dflushn (match !diagnosticsLog with None -> System.IO.TextWriter.Null | Some d -> d) fmt
2329

30+
#endif

src/absil/ildiag.fsi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
/// REVIEW: review if we should just switch to System.Diagnostics
99
module internal Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
1010

11-
open System.IO
1211
open Microsoft.FSharp.Core.Printf
12+
#if !FABLE_COMPILER
13+
open System.IO
1314

1415
val public setDiagnosticsChannel: TextWriter option -> unit
16+
#endif
1517

1618
val public dprintfn: TextWriterFormat<'a> -> 'a
1719
val public dprintf: TextWriterFormat<'a> -> 'a

0 commit comments

Comments
 (0)