Skip to content

Commit

Permalink
Merge pull request #9 from jaccarmac/wip-core
Browse files Browse the repository at this point in the history
Run the 39.0 kernel on .NET 8.0.
  • Loading branch information
rkoeninger authored Oct 23, 2024
2 parents d788608 + 4d45967 commit 810b1d9
Show file tree
Hide file tree
Showing 26 changed files with 200 additions and 149 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Shen Version](https://img.shields.io/badge/shen-38.3-blue.svg)](https://github.com/Shen-Language)
[![Shen Version](https://img.shields.io/badge/shen-39.0-blue.svg)](https://github.com/Shen-Language)
[![Latest Nuget](https://img.shields.io/nuget/v/ShenSharp.svg)](https://www.nuget.org/packages/ShenSharp)

# Shen for the Common Language Runtime
Expand Down
10 changes: 7 additions & 3 deletions src/Kl.Get/GetKl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open System
open System.IO
open System.IO.Compression
open System.Net
open System.Net.Http
open ShenSharp.Shared

let url = sprintf "https://github.com/Shen-Language/shen-sources/releases/download/shen-%s/%s.zip" KernelRevision KernelFolderName
Expand All @@ -22,8 +22,12 @@ let main _ =
printfn "Extracted folder: \"%s\"" extractedFolder
printfn "Kernel folder: \"%s\"" kernelFolder
printfn "Downloading sources package..."
use client = new WebClient()
client.DownloadFile(url, zipPath)
(task {
use client = new HttpClient()
use zip = new FileStream(zipPath, FileMode.Create)
let! req = client.GetStreamAsync url
do! req.CopyToAsync zip
}).Wait ()
printfn "Extracting sources package..."
safeDelete kernelFolder
ZipFile.ExtractToDirectory(zipPath, root)
Expand Down
2 changes: 1 addition & 1 deletion src/Kl.Get/Kl.Get.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Kl.Get</AssemblyName>
<PackageId>Kl.Get</PackageId>
<RootNamespace>Kl</RootNamespace>
Expand Down
35 changes: 17 additions & 18 deletions src/Kl.Make/BuildRuntime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ open Kl.Values
open Loader
open ShenSharp.Shared

let outputPath = fromRoot ["kernel"; "dotnet"; BuildConfig]
let sourcePath = fromRoot ["kernel"; "klambda"]
let sourceFiles = [
"toplevel.kl"
"core.kl"
"sys.kl"
"dict.kl"
"sequent.kl"
"yacc.kl"
"reader.kl"
"prolog.kl"
"track.kl"
"load.kl"
"writer.kl"
"macros.kl"
"declarations.kl"
"types.kl"
"t-star.kl"
"init.kl"
"dict.kl"
"sys.kl"
"writer.kl"
"core.kl"
"reader.kl"
"declarations.kl"
"toplevel.kl"
"macros.kl"
"load.kl"
"prolog.kl"
"sequent.kl"
"track.kl"
"t-star.kl"
"yacc.kl"
"types.kl"
"init.kl"
]

let buildRuntime () = make sourcePath sourceFiles outputPath
let buildRuntime () = make sourcePath sourceFiles

[<EntryPoint>]
let main _ = separateThread128MB buildRuntime
2 changes: 1 addition & 1 deletion src/Kl.Make/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ let buildMetadataFile name copyright version config =
meta ["System"; "Reflection"; "AssemblyFileVersion"] version
meta ["System"; "Reflection"; "AssemblyInformationalVersion"] <| version.Substring(0, version.Length - 2)
meta ["System"; "Reflection"; "AssemblyConfiguration"] config
meta ["System"; "Runtime"; "Versioning"; "TargetFramework"] ".NETStandard,Version=v2.1"
meta ["System"; "Runtime"; "Versioning"; "TargetFramework"] ".NETCoreApp,Version=v8.0"
]
4 changes: 2 additions & 2 deletions src/Kl.Make/Kl.Make.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Kl.Make</AssemblyName>
<PackageId>Kl.Make</PackageId>
<RootNamespace>Kl</RootNamespace>
Expand All @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="FParsec" Version="1.1.1" />
<PackageReference Include="FSharp.Compiler.Service" Version="34.0.1" />
<PackageReference Include="FSharp.Compiler.Service" Version="43.8.300" />
</ItemGroup>

<ItemGroup>
Expand Down
42 changes: 10 additions & 32 deletions src/Kl.Make/Loader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

open System
open System.IO
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Diagnostics
open FSharp.Compiler.Text
open Kl
open Kl.Values
Expand All @@ -13,24 +14,24 @@ open ShenSharp.Shared

let private dllName = sprintf "%s.dll" GeneratedModule
let private pdbName = sprintf "%s.pdb" GeneratedModule
let private deps = ["Kl.dll"]
let private deps = ["Kl"; "System.Runtime"; "System.Runtime.Numerics"; "System.Collections"; "System.Net.Requests"; "System.Net.WebClient"]
let private sharedMetadataPath = fromRoot ["src"; "Shared.fs"]

let private import sourcePath =
List.collect (fun f -> combine [sourcePath; f] |> File.ReadAllText |> readAll)

let private filterMessages severity messages = Seq.filter (fun (m: FSharpErrorInfo) -> m.Severity = severity) messages
let private filterMessages severity messages = Seq.filter (fun (m: FSharpDiagnostic) -> m.Severity = severity) messages

let private logWarnings messages =
messages |> filterMessages FSharpErrorSeverity.Warning |> Seq.iter (fun (m: FSharpErrorInfo) -> printfn "%O" m)
messages |> filterMessages FSharpDiagnosticSeverity.Warning |> Seq.iter (fun (m: FSharpDiagnostic) -> printfn "%O" m)

let private raiseErrors messages =
let errors = filterMessages FSharpErrorSeverity.Error messages
let errors = filterMessages FSharpDiagnosticSeverity.Error messages
raise(Exception(String.Join("\r\n\r\n", Seq.map string errors)))

let private handleResults (value, messages) =
logWarnings messages
if filterMessages FSharpErrorSeverity.Error messages |> Seq.length > 0
if filterMessages FSharpDiagnosticSeverity.Error messages |> Seq.length > 0
then raiseErrors messages
else value

Expand All @@ -46,25 +47,8 @@ let private parseFile (checker: FSharpChecker) file =
let result =
checker.ParseFile(file, input, parsingOptions)
|> Async.RunSynchronously
logWarnings result.Errors
match result.ParseTree with
| Some tree -> tree
| None -> raiseErrors result.Errors

// TODO: specify arguments to exclude mscorlib.dll

let private emit (checker: FSharpChecker) asts =
let (errors, _) =
checker.Compile(
asts,
GeneratedModule,
dllName,
deps,
pdbName,
false,
true)
|> Async.RunSynchronously
handleResults ((), errors)
logWarnings result.Diagnostics
result.ParseTree

let private move source destination =
if File.Exists destination then
Expand All @@ -78,16 +62,10 @@ let private filterDefuns excluded =
| _ -> false // Exclude all non-defuns too
List.filter filter

let make sourcePath sourceFiles outputPath =
let make sourcePath sourceFiles =
let checker = FSharpChecker.Create()
let exprs = import sourcePath sourceFiles |> filterDefuns ["cd"]
printfn "Translating kernel..."
let ast = buildInstallationFile GeneratedModule exprs
File.WriteAllText("Kernel.fs", writeFile ast)
let sharedAst = parseFile checker sharedMetadataPath
let metadataAst = buildMetadataFile GeneratedModule Copyright Revision BuildConfig
printfn "Compiling kernel..."
emit checker [ast; sharedAst; metadataAst]
printfn "Copying artifacts to output path..."
move dllName (combine [outputPath; dllName])
printfn "Done."
Loading

0 comments on commit 810b1d9

Please sign in to comment.