Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 5a2aad5

Browse files
Prepare dotnet tool + project cracking
1 parent 9e237de commit 5a2aad5

22 files changed

+2371
-12
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
.vs/
77
paket-files/
88
**.user
9+
.ionide/
10+
.vscode/
11+
launchSettings.json
12+

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Peeble. A F# -> Php transpiler
2+
3+
## Why
4+
5+
I wrote a game using Fable Elmish that has more that 2000LoC of non-trivial game logic executed both in the browser and on the server. When I needed to port it to a platform accepting only Php backend, the simplest option would have been to rewrite the server side to php. But it would have led to heavy code duplication in two different languages.
6+
7+
This is why I tried to transpile F# to Php the same way Fable does to Javascript
8+
9+
## How it works
10+
11+
Peeble use Fable transforms to parse F# files and create a simpler intermediate representation. It then convert this to a Php model before serializing it to text.
12+
13+
## Build it
14+

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## 0.1.0-alpha
2+
* Peeble alpha release

build.fsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
nuget Fake.Core
33
nuget Fake.Core.Target
44
nuget Fake.Core.ReleaseNotes
5+
nuget Fake.DotNet.AssemblyInfoFile
56
nuget Fake.DotNet.Cli
67
nuget Fake.DotNet.Testing.Coverlet
78
nuget Fake.Testing.ReportGenerator
@@ -24,14 +25,20 @@ module Path =
2425
let peeble = bin </> "peeble"
2526
let tests = bin </> "tests"
2627
let coverage = tests </> "coverage.json"
28+
let tool = bin </> "tool"
29+
30+
31+
let releaseNotes = ReleaseNotes.load "RELEASE_NOTES.md"
32+
2733

2834
Target.create "Clean" <| fun _ ->
2935
Directory.delete Path.bin
3036

3137
Target.create "Build" <| fun _ ->
3238
Fake.DotNet.DotNet.publish (fun p ->
3339
{ p with Configuration = Fake.DotNet.DotNet.BuildConfiguration.Release
34-
OutputPath = Some Path.peeble }
40+
OutputPath = Some Path.peeble
41+
}
3542

3643
) "src/peeble/peeble.fsproj"
3744

@@ -57,11 +64,29 @@ Target.create "Test" <| fun _ ->
5764
})
5865
[ Path.coverage ]
5966

67+
68+
Target.create "Tool" <| fun _ ->
69+
let prefix, suffix =
70+
match releaseNotes.NugetVersion.Split([|'-'|], 2)|> Seq.toList with
71+
| [p] -> p, None
72+
| [p;s] -> p, Some s
73+
| _ -> failwithf "Unexpected version"
74+
75+
Trace.logfn "%s %A" prefix suffix
76+
Fake.DotNet.DotNet.pack (fun p ->
77+
{ p with
78+
MSBuildParams = { p.MSBuildParams with Properties = [ "VersionPrefix", prefix] }
79+
Configuration = Fake.DotNet.DotNet.BuildConfiguration.Release
80+
VersionSuffix = suffix
81+
} )
82+
"src/peeble/peeble.fsproj"
83+
6084
Target.create "All" ignore
6185

6286

6387
"Clean" ==> "Build"
6488
==> "Test"
89+
==> "Tool"
6590
==> "All"
6691

6792
Target.runOrDefault "All"

build.fsx.lock

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ NUGET
5252
Fake.Core.Xml (5.20.3)
5353
Fake.Core.String (>= 5.20.3)
5454
FSharp.Core (>= 4.7.2)
55+
Fake.DotNet.AssemblyInfoFile (5.20.3)
56+
Fake.Core.Environment (>= 5.20.3)
57+
Fake.Core.String (>= 5.20.3)
58+
Fake.Core.Trace (>= 5.20.3)
59+
Fake.IO.FileSystem (>= 5.20.3)
60+
FSharp.Core (>= 4.7.2)
5561
Fake.DotNet.Cli (5.20.3)
5662
Fake.Core.Environment (>= 5.20.3)
5763
Fake.Core.Process (>= 5.20.3)
@@ -106,12 +112,12 @@ NUGET
106112
FSharp.Core (>= 4.7.2)
107113
System.Reactive (>= 4.4.1)
108114
FSharp.Core (4.7.2)
109-
Microsoft.Build (16.6)
110-
Microsoft.Build.Framework (16.6)
115+
Microsoft.Build (16.7)
116+
Microsoft.Build.Framework (16.7)
111117
System.Security.Permissions (>= 4.7)
112-
Microsoft.Build.Tasks.Core (16.6)
113-
Microsoft.Build.Framework (>= 16.6)
114-
Microsoft.Build.Utilities.Core (>= 16.6)
118+
Microsoft.Build.Tasks.Core (16.7)
119+
Microsoft.Build.Framework (>= 16.7)
120+
Microsoft.Build.Utilities.Core (>= 16.7)
115121
Microsoft.Win32.Registry (>= 4.3)
116122
System.CodeDom (>= 4.4)
117123
System.Collections.Immutable (>= 1.5)
@@ -121,13 +127,13 @@ NUGET
121127
System.Security.Permissions (>= 4.7)
122128
System.Threading.Tasks.Dataflow (>= 4.9)
123129
Microsoft.Build.Tasks.Git (1.0)
124-
Microsoft.Build.Utilities.Core (16.6)
125-
Microsoft.Build.Framework (>= 16.6)
130+
Microsoft.Build.Utilities.Core (16.7)
131+
Microsoft.Build.Framework (>= 16.7)
126132
Microsoft.Win32.Registry (>= 4.3)
127133
System.Collections.Immutable (>= 1.5)
128134
System.Security.Permissions (>= 4.7)
129135
System.Text.Encoding.CodePages (>= 4.0.1)
130-
Microsoft.NETCore.Platforms (3.1.2)
136+
Microsoft.NETCore.Platforms (3.1.3)
131137
Microsoft.NETCore.Targets (3.1)
132138
Microsoft.SourceLink.Common (1.0)
133139
Microsoft.SourceLink.GitHub (1.0)

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
dotnet tool restore
3+
dotnet fake build

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source https://api.nuget.org/v3/index.json
33
storage: none
44
framework: netcore3.1, netstandard2.0, netstandard2.1
55

6+
nuget Dotnet.ProjInfo
67
nuget Fable.Core
78
github fable-compiler/fable lib\fcs\FSharp.Compiler.Service.dll
89
github fable-compiler/fable lib\fcs\FSharp.Compiler.Service.xml

paket.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ NUGET
77
System.Configuration.ConfigurationManager (>= 4.4)
88
coverlet.collector (1.3)
99
coverlet.msbuild (2.9)
10+
Dotnet.ProjInfo (0.44)
11+
FSharp.Core (>= 4.6.2)
12+
Microsoft.NETFramework.ReferenceAssemblies (>= 1.0)
13+
System.ValueTuple (>= 4.4)
1014
Fable.Core (3.1.5)
1115
FSharp.Core (>= 4.7)
1216
FSharp.Core (4.7.2)
@@ -15,6 +19,7 @@ NUGET
1519
Microsoft.CodeCoverage (>= 16.7.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= net45)) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= net45)) (&& (== netstandard2.1) (>= netcoreapp2.1))
1620
Microsoft.TestPlatform.TestHost (>= 16.7.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
1721
Microsoft.NETCore.Platforms (3.1.2)
22+
Microsoft.NETFramework.ReferenceAssemblies (1.0)
1823
Microsoft.TestPlatform.ObjectModel (16.7.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
1924
NuGet.Frameworks (>= 5.0)
2025
Microsoft.TestPlatform.TestHost (16.7.1) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp2.1)) (&& (== netstandard2.1) (>= netcoreapp2.1))
@@ -48,6 +53,7 @@ NUGET
4853
System.Security.AccessControl (>= 4.7)
4954
System.Windows.Extensions (>= 4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
5055
System.Security.Principal.Windows (4.7)
56+
System.ValueTuple (4.5)
5157
System.Windows.Extensions (4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
5258
System.Drawing.Common (>= 4.7) - restriction: || (== netcoreapp3.1) (&& (== netstandard2.0) (>= netcoreapp3.0)) (&& (== netstandard2.1) (>= netcoreapp3.0))
5359
Unquote (5.0)

peeble.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{E5F881
1212
build.cmd = build.cmd
1313
build.fsx = build.fsx
1414
paket.dependencies = paket.dependencies
15+
README.md = README.md
1516
EndProjectSection
1617
EndProject
1718
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "sample", "sample\sample.fsproj", "{A0E1D26F-8347-4D34-BB21-CF2DC5B37A2A}"
@@ -20,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{EDC8338C
2021
EndProject
2122
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "peeble.tests", "tests\peeble.tests\peeble.tests.fsproj", "{3709B967-ABCA-4241-A93E-2E45C5C1BFBE}"
2223
EndProject
24+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FSharp.Core", "FSharp.Core", "{9F388538-E59A-4747-9153-5A4CA36E7E8A}"
25+
EndProject
2326
Global
2427
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2528
Debug|Any CPU = Debug|Any CPU
@@ -73,6 +76,7 @@ Global
7376
GlobalSection(NestedProjects) = preSolution
7477
{F64FE7F3-697C-4524-8CC9-163F4B02A351} = {8E5084BC-7C05-4DBD-9DE7-F89CCBAE19C3}
7578
{3709B967-ABCA-4241-A93E-2E45C5C1BFBE} = {EDC8338C-CA75-44DC-B828-204C1010CC44}
79+
{9F388538-E59A-4747-9153-5A4CA36E7E8A} = {8E5084BC-7C05-4DBD-9DE7-F89CCBAE19C3}
7680
EndGlobalSection
7781
GlobalSection(ExtensibilityGlobals) = postSolution
7882
SolutionGuid = {DA6AC55B-22A3-4299-8FCD-34973A51BF0A}

src/FSharp.Core/FSharp.Core.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
include "FSharpArray.php";
4+
include "FSharpList.php";
5+
include "Seq.php";
6+
include "Set.php";
7+
include "Map.php";
8+
9+
$equals = function ($x,$y) { return $x == $y; };
10+
11+
interface iComparable {
12+
public function CompareTo($Other);
13+
}
14+
15+
16+
17+
class Util {
18+
static function equals($x,$y) {
19+
if ( $x instanceof iComparable)
20+
return $x->CompareTo($y) == 0;
21+
22+
return $x == $y; }
23+
24+
static function max($comparer, $x, $y) {
25+
return $comparer($x,$y) >= 0 ? $x : $y;
26+
}
27+
static function min($comparer, $x, $y) {
28+
return $comparer($x,$y) <= 0 ? $x : $y;
29+
}
30+
31+
32+
static function randomNext($min,$max)
33+
{
34+
return bga_rand ($min , $max );
35+
}
36+
37+
38+
static function comparePrimitives($x,$y)
39+
{ return $x == $y ? 0 : ($x > $y ? 1 : -1); }
40+
41+
static function compareArrays ($x,$y) {
42+
$i = 0;
43+
$xl = count($x);
44+
$yl = count($y);
45+
while(true)
46+
{
47+
if ($i == $xl && $i == $yl)
48+
return 0;
49+
if ($i == $xl)
50+
return -1;
51+
if ($i == $yl)
52+
return 1;
53+
54+
$c = Util::compare($x[$i],$y[$i]);
55+
if ($c !== 0)
56+
return $c;
57+
$i++;
58+
}
59+
}
60+
61+
static function compare($x,$y)
62+
{
63+
if (is_array($x))
64+
{
65+
if (is_array($y))
66+
return Util::compareArrays($x,$y);
67+
else
68+
return 1;
69+
}
70+
elseif ($x instanceof iComparable )
71+
{
72+
return $x->CompareTo($y);
73+
}
74+
{
75+
if (is_array($y))
76+
return -1;
77+
else
78+
return Util::comparePrimitives($x,$y);
79+
}
80+
81+
82+
}
83+
}
84+
interface Union {
85+
public function get_Case();
86+
}
87+
interface FSharpUnion {
88+
public function get_FSharpCase();
89+
}
90+
91+
92+
function void($x) {}
93+
94+
class Result {
95+
96+
}
97+
98+
class Ok extends Result {
99+
public $ResultValue;
100+
function __construct($value)
101+
{
102+
$this->ResultValue = $value;
103+
}
104+
105+
}
106+
107+
class ResultError extends Result {
108+
public $ErrorValue;
109+
function __construct($value)
110+
{
111+
$this->ErrorValue = $value;
112+
}
113+
}
114+
115+
class Option {
116+
static function defaultArg($opt, $val)
117+
{
118+
return is_null($opt) ? $val : $opt;
119+
}
120+
}

0 commit comments

Comments
 (0)