Skip to content

Commit

Permalink
Merge pull request #16 from x0k/editor
Browse files Browse the repository at this point in the history
Editor
  • Loading branch information
x0k authored Aug 27, 2024
2 parents ee5ef70 + 69439a2 commit f1034e0
Show file tree
Hide file tree
Showing 184 changed files with 3,122 additions and 1,212 deletions.
13 changes: 8 additions & 5 deletions apps/ppp/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from "astro/config";
import { fileURLToPath } from "node:url";

import { viteStaticCopy } from "vite-plugin-static-copy";
import crossOriginIsolation from 'vite-plugin-cross-origin-isolation'
import crossOriginIsolation from "vite-plugin-cross-origin-isolation";

import mdx from "@astrojs/mdx";
import svelte from "@astrojs/svelte";
Expand Down Expand Up @@ -35,19 +35,19 @@ export default defineConfig({
{
src: "node_modules/gleam-runtime/dist/precompiled",
dest: "_astro",
rename: "gleam"
rename: "gleam",
},
{
src: "node_modules/dotnet-runtime/dist/compiler",
dest: "_astro/dotnet"
dest: "_astro/dotnet",
},
{
src: "node_modules/dotnet-runtime/dist/lib",
dest: "_astro/dotnet"
dest: "_astro/dotnet",
},
],
}),
crossOriginIsolation()
crossOriginIsolation(),
],
},
markdown: {
Expand All @@ -63,4 +63,7 @@ export default defineConfig({
ru: "en",
},
},
experimental: {
contentLayer: true,
},
});
11 changes: 6 additions & 5 deletions apps/ppp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
},
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/mdx": "^3.1.3",
"@astrojs/mdx": "^3.1.4",
"@astrojs/svelte": "^5.7.0",
"@astrojs/tailwind": "^5.1.0",
"@xterm/addon-fit": "^0.10.0",
"@xterm/xterm": "^5.5.0",
"astro": "^4.14.2",
"astro": "^4.14.5",
"astro-icon": "^1.1.1",
"libs": "workspace:*",
"monaco-editor": "^0.50.0",
"monaco-editor": "^0.51.0",
"monaco-editor-textmate": "^4.0.0",
"monaco-textmate": "^3.0.1",
"monaco-vim": "^0.4.1",
"onigasm": "^2.2.5",
"tailwindcss": "^3.4.10",
"compiler": "workspace:*",
"testing": "workspace:*",
"dotnet-runtime": "workspace:*",
"gleam-runtime": "workspace:*",
Expand All @@ -38,13 +39,13 @@
"java-runtime": "workspace:*"
},
"devDependencies": {
"@iconify-json/lucide": "^1.1.207",
"@iconify-json/lucide": "^1.1.208",
"@iconify/svelte": "^4.0.2",
"@tailwindcss/typography": "^0.5.14",
"@types/color": "^3.0.6",
"color": "^4.2.3",
"daisyui": "^4.12.10",
"svelte": "5.0.0-next.225",
"svelte": "5.0.0-next.237",
"vite-plugin-cross-origin-isolation": "^0.1.6",
"vite-plugin-static-copy": "^1.0.6"
}
Expand Down
245 changes: 245 additions & 0 deletions apps/ppp/src/adapters/runtime/dotnet/compiler-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
import {
type CompilerModuleExports,
type CompilerModuleImports,
type DotnetModule,
DotnetProgram,
DotnetCompilerFactory,
DotnetRuntimeFactory,
} from "dotnet-runtime";
import type { CompilerFactory } from "compiler";
import { inContext } from "libs/context";
import { createLogger, redirect } from "libs/logger";
import { patch } from "libs/patcher";

const dotnetUrl = new URL(
import.meta.env.BASE_URL + "/_astro/dotnet/compiler/dotnet.js",
globalThis.location.origin
).toString();

const precompiledLibsIndexUrl = new URL(
import.meta.env.BASE_URL + "/_astro/dotnet/lib",
globalThis.location.origin
).toString();

export const LIBS = [
"Humanizer.dll",
"Microsoft.Bcl.AsyncInterfaces.dll",
"Microsoft.CSharp.dll",
// "Microsoft.CodeAnalysis.CSharp.Workspaces.dll",
// "Microsoft.CodeAnalysis.CSharp.dll",
// "Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll",
// "Microsoft.CodeAnalysis.VisualBasic.dll",
// "Microsoft.CodeAnalysis.Workspaces.dll",
// "Microsoft.CodeAnalysis.dll",
// "Microsoft.JSInterop.WebAssembly.dll",
// "Microsoft.JSInterop.dll",
// "Microsoft.VisualBasic.Core.dll",
// "Microsoft.VisualBasic.dll",
// "Microsoft.Win32.Primitives.dll",
// "Microsoft.Win32.Registry.dll",
"System.AppContext.dll",
"System.Buffers.dll",
"System.Collections.Concurrent.dll",
"System.Collections.Immutable.dll",
"System.Collections.NonGeneric.dll",
"System.Collections.Specialized.dll",
"System.Collections.dll",
// "System.ComponentModel.Annotations.dll",
// "System.ComponentModel.DataAnnotations.dll",
// "System.ComponentModel.EventBasedAsync.dll",
// "System.ComponentModel.Primitives.dll",
// "System.ComponentModel.TypeConverter.dll",
// "System.ComponentModel.dll",
// "System.Composition.AttributedModel.dll",
// "System.Composition.Convention.dll",
// "System.Composition.Hosting.dll",
// "System.Composition.Runtime.dll",
// "System.Composition.TypedParts.dll",
// "System.Configuration.dll",
"System.Console.dll",
"System.Core.dll",
// "System.Data.Common.dll",
// "System.Data.DataSetExtensions.dll",
// "System.Data.dll",
// "System.Diagnostics.Contracts.dll",
"System.Diagnostics.Debug.dll",
// "System.Diagnostics.DiagnosticSource.dll",
// "System.Diagnostics.FileVersionInfo.dll",
// "System.Diagnostics.Process.dll",
// "System.Diagnostics.StackTrace.dll",
// "System.Diagnostics.TextWriterTraceListener.dll",
// "System.Diagnostics.Tools.dll",
// "System.Diagnostics.TraceSource.dll",
// "System.Diagnostics.Tracing.dll",
// "System.Drawing.Primitives.dll",
// "System.Drawing.dll",
// "System.Dynamic.Runtime.dll",
// "System.Formats.Asn1.dll",
// "System.Formats.Tar.dll",
"System.Globalization.Calendars.dll",
"System.Globalization.Extensions.dll",
"System.Globalization.dll",
// "System.IO.Compression.Brotli.dll",
// "System.IO.Compression.FileSystem.dll",
// "System.IO.Compression.ZipFile.dll",
// "System.IO.Compression.dll",
// "System.IO.FileSystem.AccessControl.dll",
// "System.IO.FileSystem.DriveInfo.dll",
// "System.IO.FileSystem.Primitives.dll",
// "System.IO.FileSystem.Watcher.dll",
"System.IO.FileSystem.dll",
// "System.IO.IsolatedStorage.dll",
// "System.IO.MemoryMappedFiles.dll",
// "System.IO.Pipelines.dll",
// "System.IO.Pipes.AccessControl.dll",
// "System.IO.Pipes.dll",
"System.IO.UnmanagedMemoryStream.dll",
"System.IO.dll",
"System.Linq.Expressions.dll",
"System.Linq.Parallel.dll",
"System.Linq.Queryable.dll",
"System.Linq.dll",
"System.Memory.dll",
"System.Net.Http.Json.dll",
"System.Net.Http.dll",
"System.Net.HttpListener.dll",
// "System.Net.Mail.dll",
"System.Net.NameResolution.dll",
"System.Net.NetworkInformation.dll",
// "System.Net.Ping.dll",
"System.Net.Primitives.dll",
// "System.Net.Quic.dll",
"System.Net.Requests.dll",
// "System.Net.Security.dll",
// "System.Net.ServicePoint.dll",
"System.Net.Sockets.dll",
"System.Net.WebClient.dll",
"System.Net.WebHeaderCollection.dll",
// "System.Net.WebProxy.dll",
// "System.Net.WebSockets.Client.dll",
// "System.Net.WebSockets.dll",
"System.Net.dll",
"System.Numerics.Vectors.dll",
"System.Numerics.dll",
"System.ObjectModel.dll",
"System.Private.CoreLib.dll",
// "System.Private.DataContractSerialization.dll",
"System.Private.Uri.dll",
// "System.Private.Xml.Linq.dll",
// "System.Private.Xml.dll",
// "System.Reflection.DispatchProxy.dll",
// "System.Reflection.Emit.ILGeneration.dll",
// "System.Reflection.Emit.Lightweight.dll",
// "System.Reflection.Emit.dll",
// "System.Reflection.Extensions.dll",
// "System.Reflection.Metadata.dll",
// "System.Reflection.Primitives.dll",
// "System.Reflection.TypeExtensions.dll",
"System.Reflection.dll",
"System.Resources.Reader.dll",
"System.Resources.ResourceManager.dll",
"System.Resources.Writer.dll",
// "System.Runtime.CompilerServices.Unsafe.dll",
// "System.Runtime.CompilerServices.VisualC.dll",
"System.Runtime.Extensions.dll",
"System.Runtime.Handles.dll",
// "System.Runtime.InteropServices.JavaScript.dll",
"System.Runtime.InteropServices.RuntimeInformation.dll",
"System.Runtime.InteropServices.dll",
// "System.Runtime.Intrinsics.dll",
// "System.Runtime.Loader.dll",
// "System.Runtime.Numerics.dll",
// "System.Runtime.Serialization.Formatters.dll",
"System.Runtime.Serialization.Json.dll",
// "System.Runtime.Serialization.Primitives.dll",
// "System.Runtime.Serialization.Xml.dll",
// "System.Runtime.Serialization.dll",
"System.Runtime.dll",
// "System.Security.AccessControl.dll",
// "System.Security.Claims.dll",
// "System.Security.Cryptography.Algorithms.dll",
// "System.Security.Cryptography.Cng.dll",
// "System.Security.Cryptography.Csp.dll",
// "System.Security.Cryptography.Encoding.dll",
// "System.Security.Cryptography.OpenSsl.dll",
// "System.Security.Cryptography.Primitives.dll",
// "System.Security.Cryptography.X509Certificates.dll",
// "System.Security.Cryptography.dll",
// "System.Security.Principal.Windows.dll",
"System.Security.Principal.dll",
"System.Security.SecureString.dll",
"System.Security.dll",
// "System.ServiceModel.Web.dll",
// "System.ServiceProcess.dll",
// "System.Text.Encoding.CodePages.dll",
"System.Text.Encoding.Extensions.dll",
"System.Text.Encoding.dll",
"System.Text.Encodings.Web.dll",
"System.Text.Json.dll",
"System.Text.RegularExpressions.dll",
// "System.Threading.Channels.dll",
// "System.Threading.Overlapped.dll",
// "System.Threading.Tasks.Dataflow.dll",
"System.Threading.Tasks.Extensions.dll",
"System.Threading.Tasks.Parallel.dll",
"System.Threading.Tasks.dll",
"System.Threading.Thread.dll",
"System.Threading.ThreadPool.dll",
"System.Threading.Timer.dll",
"System.Threading.dll",
// "System.Transactions.Local.dll",
"System.Transactions.dll",
"System.ValueTuple.dll",
"System.Web.HttpUtility.dll",
// "System.Web.dll",
// "System.Windows.dll",
// "System.Xml.Linq.dll",
// "System.Xml.ReaderWriter.dll",
// "System.Xml.Serialization.dll",
// "System.Xml.XDocument.dll",
// "System.Xml.XPath.XDocument.dll",
// "System.Xml.XPath.dll",
// "System.Xml.XmlDocument.dll",
// "System.Xml.XmlSerializer.dll",
// "System.Xml.dll",
"System.dll",
"WebAssembly.dll",
// "WindowsBase.dll",
// "compiler.dll",
"mscorlib.dll",
"netstandard.dll",
];

export const makeDotnetCompiler: CompilerFactory = async (ctx, out) => {
const log = createLogger(out);
const patchedConsole = redirect(globalThis.console, log);

const { dotnet } = await inContext(ctx, import(/* @vite-ignore */ dotnetUrl));
const consolePatch = patch(globalThis, "console", patchedConsole);
try {
const compilerModule: DotnetModule<
CompilerModuleImports,
CompilerModuleExports
> = await inContext(ctx, dotnet.create());
const compiler = await inContext(
ctx,
new DotnetCompilerFactory(log, compilerModule).create(
precompiledLibsIndexUrl,
LIBS
)
);
const runtimeFactory = new DotnetRuntimeFactory(compiler);
return {
async compile(_, files) {
if (files.length !== 1) {
throw new Error("Compilation of multiple files is not implemented");
}
const runtime = runtimeFactory.create(files[0].content);
return new DotnetProgram(runtime);
},
[Symbol.dispose]() {},
};
} finally {
consolePatch[Symbol.dispose]();
}
};
23 changes: 3 additions & 20 deletions apps/ppp/src/adapters/runtime/dotnet/description.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
<script lang="ts">
import { version } from "dotnet-runtime/version";
import { LIBS } from "./test-compiler-factory";
import Info from "./info.svelte";
</script>

<p>
.NET {version}
</p>

<p>
Your code is compiled by the Roslyn compiler (compiled to WebAssembly with a
several .NET assemblies) and is executed in the context of the current page.
Class <code>Program</code> with a public static method <code>Main</code> is required.
</p>

<p>Namespace <code>test</code> is reserved.</p>

<p>Available libraries:</p>

<div class="grid grid-flow-row grid-cols-2 gap-x-2">
{#each LIBS as lib}
<p class="truncate">
{lib}
</p>
{/each}
</div>
<Info />
24 changes: 24 additions & 0 deletions apps/ppp/src/adapters/runtime/dotnet/info.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import { version } from "dotnet-runtime/version";
import { LIBS } from "./test-compiler-factory";
</script>

<p>
.NET {version}
</p>

<p>
Your code is compiled by the Roslyn compiler (compiled to WebAssembly with a
several .NET assemblies) and is executed in the context of the current page.
</p>

<p>Available libraries:</p>

<div class="grid grid-flow-row grid-cols-2 gap-x-2">
{#each LIBS as lib}
<p class="truncate">
{lib}
</p>
{/each}
</div>
7 changes: 7 additions & 0 deletions apps/ppp/src/adapters/runtime/dotnet/test-description.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang="ts">
import Info from "./info.svelte";
</script>

<p>Namespace <code>test</code> is reserved.</p>

<Info />
5 changes: 5 additions & 0 deletions apps/ppp/src/adapters/runtime/dotnet/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { startCompilerActor } from "compiler/actor";

import { makeDotnetCompiler } from "./compiler-factory";

startCompilerActor(makeDotnetCompiler);
Loading

0 comments on commit f1034e0

Please sign in to comment.