Skip to content

Commit

Permalink
Add support for F# compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
KubaZ2 committed Aug 14, 2024
1 parent 34afd35 commit f247037
Show file tree
Hide file tree
Showing 19 changed files with 573 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Backend/Sandbox/Asm/Asm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<ProjectReference Include="..\..\..\Sharp.Runtime\Sharp.Runtime.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="8.0.400" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand Down
4 changes: 4 additions & 0 deletions Backend/Sandbox/Runner/Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<ProjectReference Include="..\..\..\Sharp.Runtime\Sharp.Runtime.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="8.0.400" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
Expand Down
11 changes: 6 additions & 5 deletions Bot/Sharp/CommandHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ private static async Task<ReplyMessageProperties> HandleAsync(string? sourceLang

private static async Task<ReplyMessageProperties> HandleAsyncCore(Language? sourceLanguage, string code, CommandContext context, IServiceProvider services, IResponseProvider responseProvider, Language targetLanguage)
{
var compilationResult = await services.GetRequiredService<ICompilationProvider>().CompileAsync(sourceLanguage.GetValueOrDefault(), code, null);
var operationId = context.Message.Id;
var compilationResult = await services.GetRequiredService<ICompilationProvider>().CompileAsync(operationId, sourceLanguage.GetValueOrDefault(), code, null);

if (compilationResult is not CompilationResult.Success { Assembly: var assembly, Diagnostics: var diagnostics })
return responseProvider.CompilationResultResponse<ReplyMessageProperties>(context.Message.Id, compilationResult);
return responseProvider.CompilationResultResponse<ReplyMessageProperties>(operationId, compilationResult);

var decompilationResult = await services.GetRequiredService<IDecompilationProvider>().DecompileAsync(assembly, targetLanguage);
var decompilationResult = await services.GetRequiredService<IDecompilationProvider>().DecompileAsync(operationId, assembly, targetLanguage);

if (decompilationResult is not DecompilationResult.Success { Code: var decompiledCode })
return responseProvider.DecompilationResultResponse<ReplyMessageProperties>(context.Message.Id, decompilationResult);
return responseProvider.DecompilationResultResponse<ReplyMessageProperties>(operationId, decompilationResult);

return responseProvider.DecompilationResponse<ReplyMessageProperties>(context.Message.Id, targetLanguage, decompiledCode, diagnostics);
return responseProvider.DecompilationResponse<ReplyMessageProperties>(operationId, targetLanguage, decompiledCode, diagnostics);
}

public static IHost AddHelpCommands(this IHost host)
Expand Down
4 changes: 2 additions & 2 deletions Bot/Sharp/Compilation/CompilationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ namespace Sharp.Compilation;

public class CompilationProvider(ICompilerProvider compilerProvider) : ICompilationProvider
{
public async Task<CompilationResult> CompileAsync(Language language, string code, CompilationOutput? output)
public async Task<CompilationResult> CompileAsync(ulong operationId, Language language, string code, CompilationOutput? output)
{
var compiler = compilerProvider.GetCompiler(language);
if (compiler is null)
return new CompilationResult.CompilerNotFound(language);

List<Diagnostic> diagnostics = [];
MemoryStream assembly = new();
var success = await compiler.CompileAsync(code, diagnostics, assembly, output);
var success = await compiler.CompileAsync(operationId, code, diagnostics, assembly, output);

if (!success)
return new CompilationResult.Fail(language, diagnostics);
Expand Down
Loading

0 comments on commit f247037

Please sign in to comment.