Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit e1112c2

Browse files
committed
[WIP] Fable support - unfinished
1 parent 7e18b8a commit e1112c2

Some content is hidden

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

76 files changed

+3393
-249
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": "node",
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": "node",
16+
"request": "attach",
17+
"name": "Attach to Process",
18+
"port": 5858
19+
}
20+
]
21+
}

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: 36 additions & 15 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

@@ -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) [|0us;0us;0us;0us|]
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 0us 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 0us else uint16(version.MinorRevision)
41134134
(zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision);;
4114-
4135+
#endif
41154136

41164137
let compareILVersions (a1,a2,a3,a4) ((b1,b2,b3,b4) : ILVersionInfo) =
41174138
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)