wasm-idle 0.7.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +760 -81
- package/dist/index.d.ts +4 -9
- package/dist/index.js +2 -4
- package/dist/playground/applicationAssets.d.ts +4 -0
- package/dist/playground/applicationAssets.js +277 -0
- package/dist/playground/assemblyscript.d.ts +41 -0
- package/dist/playground/assemblyscript.js +630 -0
- package/dist/playground/assetBridge.d.ts +18 -7
- package/dist/playground/assetBridge.js +824 -100
- package/dist/playground/assets.d.ts +813 -19
- package/dist/playground/assets.js +2096 -156
- package/dist/playground/awk.d.ts +5 -0
- package/dist/playground/awk.js +60 -0
- package/dist/playground/bash.d.ts +53 -0
- package/dist/playground/bash.js +1096 -0
- package/dist/playground/bashWorkerProtocol.d.ts +88 -0
- package/dist/playground/bashWorkerProtocol.js +135 -0
- package/dist/playground/bqn.d.ts +5 -0
- package/dist/playground/bqn.js +57 -0
- package/dist/playground/bqnPreflight.d.ts +26 -0
- package/dist/playground/bqnPreflight.js +399 -0
- package/dist/playground/c3.d.ts +15 -0
- package/dist/playground/c3.js +154 -0
- package/dist/playground/clang.d.ts +35 -19
- package/dist/playground/clang.js +241 -52
- package/dist/playground/clangAssetIntegrity.d.ts +32 -0
- package/dist/playground/clangAssetIntegrity.js +8 -0
- package/dist/playground/clojurescript.d.ts +5 -0
- package/dist/playground/clojurescript.js +59 -0
- package/dist/playground/clojurescriptPreflight.d.ts +26 -0
- package/dist/playground/clojurescriptPreflight.js +383 -0
- package/dist/playground/cobol.d.ts +46 -0
- package/dist/playground/cobol.js +703 -0
- package/dist/playground/d.d.ts +47 -0
- package/dist/playground/d.js +644 -0
- package/dist/playground/dOuterAssets.d.ts +16 -0
- package/dist/playground/dOuterAssets.js +163 -0
- package/dist/playground/dotnet.d.ts +99 -0
- package/dist/playground/dotnet.js +1131 -0
- package/dist/playground/duckdb.d.ts +36 -0
- package/dist/playground/duckdb.js +542 -0
- package/dist/playground/elixir.d.ts +18 -10
- package/dist/playground/elixir.js +630 -96
- package/dist/playground/elixirAssets.d.ts +6 -0
- package/dist/playground/elixirAssets.js +33 -0
- package/dist/playground/executionObservation.d.ts +22 -0
- package/dist/playground/executionObservation.js +65 -0
- package/dist/playground/forth.d.ts +5 -0
- package/dist/playground/forth.js +53 -0
- package/dist/playground/forthPreflight.d.ts +24 -0
- package/dist/playground/forthPreflight.js +198 -0
- package/dist/playground/fortran.d.ts +47 -0
- package/dist/playground/fortran.js +651 -0
- package/dist/playground/fortranAssets.d.ts +6 -0
- package/dist/playground/fortranAssets.js +27 -0
- package/dist/playground/gleam.d.ts +6 -0
- package/dist/playground/gleam.js +33 -0
- package/dist/playground/go.d.ts +17 -11
- package/dist/playground/go.js +376 -72
- package/dist/playground/goDebugInstrumentation.d.ts +1 -0
- package/dist/playground/goDebugInstrumentation.js +229 -0
- package/dist/playground/haskell.d.ts +44 -0
- package/dist/playground/haskell.js +678 -0
- package/dist/playground/haskellAssets.d.ts +24 -0
- package/dist/playground/haskellAssets.js +93 -0
- package/dist/playground/index.d.ts +1 -1
- package/dist/playground/index.js +360 -111
- package/dist/playground/j.d.ts +5 -0
- package/dist/playground/j.js +60 -0
- package/dist/playground/jPreflight.d.ts +26 -0
- package/dist/playground/jPreflight.js +372 -0
- package/dist/playground/janet.d.ts +5 -0
- package/dist/playground/janet.js +64 -0
- package/dist/playground/java.d.ts +24 -10
- package/dist/playground/java.js +706 -84
- package/dist/playground/javaSource.d.ts +5 -0
- package/dist/playground/javaSource.js +16 -0
- package/dist/playground/javaStdin.d.ts +1 -1
- package/dist/playground/javaStdin.js +13 -4
- package/dist/playground/julia.d.ts +5 -0
- package/dist/playground/julia.js +64 -0
- package/dist/playground/lfortran.d.ts +8 -0
- package/dist/playground/lfortran.js +30 -0
- package/dist/playground/lfortranAssets.d.ts +21 -0
- package/dist/playground/lfortranAssets.js +118 -0
- package/dist/playground/lisp.d.ts +45 -0
- package/dist/playground/lisp.js +640 -0
- package/dist/playground/lispAssets.d.ts +9 -0
- package/dist/playground/lispAssets.js +74 -0
- package/dist/playground/lldbManifest.d.ts +3 -0
- package/dist/playground/lldbManifest.js +155 -0
- package/dist/playground/lldbSession.d.ts +115 -0
- package/dist/playground/lldbSession.js +1347 -0
- package/dist/playground/loadingProgress.d.ts +16 -0
- package/dist/playground/loadingProgress.js +166 -0
- package/dist/playground/lua.d.ts +44 -0
- package/dist/playground/lua.js +630 -0
- package/dist/playground/nim.d.ts +5 -0
- package/dist/playground/nim.js +76 -0
- package/dist/playground/objectivec.d.ts +39 -0
- package/dist/playground/objectivec.js +288 -0
- package/dist/playground/ocaml.d.ts +28 -10
- package/dist/playground/ocaml.js +815 -253
- package/dist/playground/octave.d.ts +43 -0
- package/dist/playground/octave.js +783 -0
- package/dist/playground/options.d.ts +19 -40
- package/dist/playground/options.js +2 -1
- package/dist/playground/pascal.d.ts +5 -0
- package/dist/playground/pascal.js +60 -0
- package/dist/playground/perl.d.ts +5 -0
- package/dist/playground/perl.js +61 -0
- package/dist/playground/php.d.ts +44 -0
- package/dist/playground/php.js +665 -0
- package/dist/playground/prolog.d.ts +6 -0
- package/dist/playground/prolog.js +75 -0
- package/dist/playground/python.d.ts +20 -14
- package/dist/playground/python.js +445 -101
- package/dist/playground/pythonPackageLock.d.ts +6 -0
- package/dist/playground/pythonPackageLock.js +56 -0
- package/dist/playground/r.d.ts +44 -0
- package/dist/playground/r.js +637 -0
- package/dist/playground/ruby.d.ts +46 -0
- package/dist/playground/ruby.js +732 -0
- package/dist/playground/rubyAssets.d.ts +23 -0
- package/dist/playground/rubyAssets.js +68 -0
- package/dist/playground/rubyTestPreflight.d.ts +2 -0
- package/dist/playground/rubyTestPreflight.js +18 -0
- package/dist/playground/runtimeModule.d.ts +1 -0
- package/dist/playground/runtimeModule.js +5 -0
- package/dist/playground/rust.d.ts +44 -13
- package/dist/playground/rust.js +714 -76
- package/dist/playground/rustExecutableGraph.d.ts +85 -0
- package/dist/playground/rustExecutableGraph.js +946 -0
- package/dist/playground/rustWorkerLimits.d.ts +17 -0
- package/dist/playground/rustWorkerLimits.js +34 -0
- package/dist/playground/sandbox.d.ts +16 -10
- package/dist/playground/sharedBuffer.d.ts +6 -0
- package/dist/playground/sharedBuffer.js +12 -0
- package/dist/playground/sqlite.d.ts +38 -0
- package/dist/playground/sqlite.js +550 -0
- package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -0
- package/dist/playground/staticRuntimeModuleVersion.js +2 -0
- package/dist/playground/staticRuntimePreflight.d.ts +13 -0
- package/dist/playground/staticRuntimePreflight.js +231 -0
- package/dist/playground/staticRuntimePreflightExecute.d.ts +8 -0
- package/dist/playground/staticRuntimePreflightExecute.js +66 -0
- package/dist/playground/staticRuntimePreflightProtocol.d.ts +68 -0
- package/dist/playground/staticRuntimePreflightProtocol.js +339 -0
- package/dist/playground/staticStdinRing.d.ts +45 -0
- package/dist/playground/staticStdinRing.js +158 -0
- package/dist/playground/staticWorkerRuntime.d.ts +154 -0
- package/dist/playground/staticWorkerRuntime.js +1917 -0
- package/dist/playground/stdinBuffer.d.ts +9 -7
- package/dist/playground/stdinBuffer.js +9 -18
- package/dist/playground/swift.d.ts +5 -0
- package/dist/playground/swift.js +17 -0
- package/dist/playground/tcl.d.ts +5 -0
- package/dist/playground/tcl.js +62 -0
- package/dist/playground/teavmConfig.d.ts +1 -1
- package/dist/playground/teavmConfig.js +2 -2
- package/dist/playground/tinygo.d.ts +48 -18
- package/dist/playground/tinygo.js +1202 -329
- package/dist/playground/tinygoExecutableGraph.d.ts +44 -0
- package/dist/playground/tinygoExecutableGraph.js +449 -0
- package/dist/playground/typescript.d.ts +55 -0
- package/dist/playground/typescript.js +924 -0
- package/dist/playground/wasm.d.ts +43 -0
- package/dist/playground/wasm.js +608 -0
- package/dist/playground/wasmAwkVersion.d.ts +59 -0
- package/dist/playground/wasmAwkVersion.js +31 -0
- package/dist/playground/wasmBashVersion.d.ts +63 -0
- package/dist/playground/wasmBashVersion.js +36 -0
- package/dist/playground/wasmBqnVersion.d.ts +24 -0
- package/dist/playground/wasmBqnVersion.js +24 -0
- package/dist/playground/wasmC3Version.d.ts +20 -0
- package/dist/playground/wasmC3Version.js +21 -0
- package/dist/playground/wasmClojureScriptVersion.d.ts +21 -0
- package/dist/playground/wasmClojureScriptVersion.js +21 -0
- package/dist/playground/wasmDIntegrity.d.ts +15 -0
- package/dist/playground/wasmDIntegrity.js +15 -0
- package/dist/playground/wasmDVersion.d.ts +1 -0
- package/dist/playground/wasmDVersion.js +1 -0
- package/dist/playground/wasmDebugVersion.d.ts +6 -0
- package/dist/playground/wasmDebugVersion.js +6 -0
- package/dist/playground/wasmDotnetVersion.d.ts +1 -0
- package/dist/playground/wasmDotnetVersion.js +1 -0
- package/dist/playground/wasmElixirVersion.d.ts +21 -1
- package/dist/playground/wasmElixirVersion.js +21 -1
- package/dist/playground/wasmForthVersion.d.ts +18 -0
- package/dist/playground/wasmForthVersion.js +18 -0
- package/dist/playground/wasmFortranExecutionAssets.d.ts +15 -0
- package/dist/playground/wasmFortranExecutionAssets.js +15 -0
- package/dist/playground/wasmFortranVersion.d.ts +1 -0
- package/dist/playground/wasmFortranVersion.js +1 -0
- package/dist/playground/wasmGleamVersion.d.ts +5 -0
- package/dist/playground/wasmGleamVersion.js +5 -0
- package/dist/playground/wasmGoVersion.d.ts +1 -1
- package/dist/playground/wasmGoVersion.js +1 -1
- package/dist/playground/wasmHaskellVersion.d.ts +1 -0
- package/dist/playground/wasmHaskellVersion.js +1 -0
- package/dist/playground/wasmJVersion.d.ts +24 -0
- package/dist/playground/wasmJVersion.js +24 -0
- package/dist/playground/wasmJanetVersion.d.ts +53 -0
- package/dist/playground/wasmJanetVersion.js +30 -0
- package/dist/playground/wasmJuliaVersion.d.ts +71 -0
- package/dist/playground/wasmJuliaVersion.js +39 -0
- package/dist/playground/wasmLfortranVersion.d.ts +28 -0
- package/dist/playground/wasmLfortranVersion.js +29 -0
- package/dist/playground/wasmLispVersion.d.ts +1 -0
- package/dist/playground/wasmLispVersion.js +1 -0
- package/dist/playground/wasmLuaVersion.d.ts +1 -0
- package/dist/playground/wasmLuaVersion.js +1 -0
- package/dist/playground/wasmNimVersion.d.ts +125 -0
- package/dist/playground/wasmNimVersion.js +66 -0
- package/dist/playground/wasmObjectiveCVersion.d.ts +27 -0
- package/dist/playground/wasmObjectiveCVersion.js +27 -0
- package/dist/playground/wasmOcamlVersion.d.ts +12 -1
- package/dist/playground/wasmOcamlVersion.js +12 -1
- package/dist/playground/wasmOctaveVersion.d.ts +1 -0
- package/dist/playground/wasmOctaveVersion.js +1 -0
- package/dist/playground/wasmPascalVersion.d.ts +61 -0
- package/dist/playground/wasmPascalVersion.js +34 -0
- package/dist/playground/wasmPerlVersion.d.ts +71 -0
- package/dist/playground/wasmPerlVersion.js +39 -0
- package/dist/playground/wasmPrologVersion.d.ts +31 -0
- package/dist/playground/wasmPrologVersion.js +31 -0
- package/dist/playground/wasmRVersion.d.ts +1 -0
- package/dist/playground/wasmRVersion.js +1 -0
- package/dist/playground/wasmRustVersion.d.ts +1306 -1
- package/dist/playground/wasmRustVersion.js +1458 -1
- package/dist/playground/wasmSwiftVersion.d.ts +1 -0
- package/dist/playground/wasmSwiftVersion.js +1 -0
- package/dist/playground/wasmTclVersion.d.ts +85 -0
- package/dist/playground/wasmTclVersion.js +46 -0
- package/dist/playground/wasmTinyGoVersion.d.ts +98 -1
- package/dist/playground/wasmTinyGoVersion.js +107 -1
- package/dist/playground/wasmTypeScriptVersion.d.ts +5 -0
- package/dist/playground/wasmTypeScriptVersion.js +5 -0
- package/dist/playground/wasmWatVersion.d.ts +1 -0
- package/dist/playground/wasmWatVersion.js +1 -0
- package/dist/playground/wasmZigVersion.d.ts +13 -0
- package/dist/playground/wasmZigVersion.js +13 -0
- package/dist/playground/wat.d.ts +44 -0
- package/dist/playground/wat.js +622 -0
- package/dist/playground/worker/assemblyscript.js +339 -0
- package/dist/playground/worker/assets.d.ts +7 -0
- package/dist/playground/worker/assets.js +288 -39
- package/dist/playground/worker/bash.js +338 -0
- package/dist/playground/worker/bashNestedBootstrap.d.ts +6 -0
- package/dist/playground/worker/bashNestedBootstrap.js +59 -0
- package/dist/playground/worker/bashRuntime.d.ts +89 -0
- package/dist/playground/worker/bashRuntime.js +982 -0
- package/dist/playground/worker/clang.js +92 -13
- package/dist/playground/worker/cobol.js +107 -0
- package/dist/playground/worker/d.js +199 -0
- package/dist/playground/worker/dotnet.js +141 -0
- package/dist/playground/worker/duckdb.d.ts +1 -0
- package/dist/playground/worker/duckdb.js +136 -0
- package/dist/playground/worker/elixir.js +307 -41
- package/dist/playground/worker/fortran.d.ts +1 -0
- package/dist/playground/worker/fortran.js +295 -0
- package/dist/playground/worker/go.js +246 -40
- package/dist/playground/worker/haskell.d.ts +7 -0
- package/dist/playground/worker/haskell.js +465 -0
- package/dist/playground/worker/java.js +59 -20
- package/dist/playground/worker/lisp.d.ts +1 -0
- package/dist/playground/worker/lisp.js +195 -0
- package/dist/playground/worker/lua.d.ts +1 -0
- package/dist/playground/worker/lua.js +163 -0
- package/dist/playground/worker/objectivec.d.ts +1 -0
- package/dist/playground/worker/objectivec.js +10 -0
- package/dist/playground/worker/ocaml.js +206 -58
- package/dist/playground/worker/php.d.ts +1 -0
- package/dist/playground/worker/php.js +261 -0
- package/dist/playground/worker/python.js +201 -44
- package/dist/playground/worker/r.d.ts +1 -0
- package/dist/playground/worker/r.js +192 -0
- package/dist/playground/worker/ruby.d.ts +1 -0
- package/dist/playground/worker/ruby.js +248 -0
- package/dist/playground/worker/runtimeAssetFetch.d.ts +15 -0
- package/dist/playground/worker/runtimeAssetFetch.js +375 -0
- package/dist/playground/worker/rust.js +546 -20
- package/dist/playground/worker/sqlite.d.ts +1 -0
- package/dist/playground/worker/sqlite.js +112 -0
- package/dist/playground/worker/staticRuntimePreflight.d.ts +1 -0
- package/dist/playground/worker/staticRuntimePreflight.js +56 -0
- package/dist/playground/worker/tinygo.js +34 -9
- package/dist/playground/worker/typescript.d.ts +1 -0
- package/dist/playground/worker/typescript.js +251 -0
- package/dist/playground/worker/wasm.d.ts +1 -0
- package/dist/playground/worker/wasm.js +273 -0
- package/dist/playground/worker/wat.d.ts +1 -0
- package/dist/playground/worker/wat.js +188 -0
- package/dist/playground/worker/zig.d.ts +8 -0
- package/dist/playground/worker/zig.js +578 -0
- package/dist/playground/workerProgress.d.ts +15 -0
- package/dist/playground/workerProgress.js +72 -0
- package/dist/playground/workerSession.d.ts +28 -0
- package/dist/playground/workerSession.js +164 -0
- package/dist/playground/zig.d.ts +46 -0
- package/dist/playground/zig.js +690 -0
- package/dist/playground/zigAssets.d.ts +6 -0
- package/dist/playground/zigAssets.js +49 -0
- package/package.json +234 -105
- package/dist/clang/app.d.ts +0 -75
- package/dist/clang/app.js +0 -744
- package/dist/clang/apply.d.ts +0 -2
- package/dist/clang/apply.js +0 -11
- package/dist/clang/color.d.ts +0 -3
- package/dist/clang/color.js +0 -3
- package/dist/clang/encode.d.ts +0 -4
- package/dist/clang/encode.js +0 -20
- package/dist/clang/error.d.ts +0 -14
- package/dist/clang/error.js +0 -27
- package/dist/clang/gccCompat.d.ts +0 -15
- package/dist/clang/gccCompat.js +0 -767
- package/dist/clang/index.d.ts +0 -85
- package/dist/clang/index.js +0 -1077
- package/dist/clang/memory/index.d.ts +0 -4
- package/dist/clang/memory/index.js +0 -4
- package/dist/clang/memory/memFs.d.ts +0 -35
- package/dist/clang/memory/memFs.js +0 -132
- package/dist/clang/memory/memory.d.ts +0 -22
- package/dist/clang/memory/memory.js +0 -73
- package/dist/clang/memory/tar.d.ts +0 -2
- package/dist/clang/memory/tar.js +0 -59
- package/dist/clang/url.d.ts +0 -4
- package/dist/clang/url.js +0 -5
- package/dist/clang/wasm.d.ts +0 -4
- package/dist/clang/wasm.js +0 -50
- package/dist/clangd/config.d.ts +0 -18
- package/dist/clangd/config.js +0 -14
- package/dist/clangd/jsonStream.d.ts +0 -9
- package/dist/clangd/jsonStream.js +0 -48
- package/dist/clangd/session.d.ts +0 -18
- package/dist/clangd/session.js +0 -112
- package/dist/clangd/worker.js +0 -131
- package/dist/debug/controller.svelte.d.ts +0 -43
- package/dist/debug/controller.svelte.js +0 -268
- package/dist/debug/editor/index.d.ts +0 -2
- package/dist/debug/editor/index.js +0 -1
- package/dist/debug/editor/monaco.d.ts +0 -26
- package/dist/debug/editor/monaco.js +0 -128
- package/dist/debug/expression.d.ts +0 -26
- package/dist/debug/expression.js +0 -547
- package/dist/debug/index.d.ts +0 -8
- package/dist/debug/index.js +0 -5
- package/dist/debug/language/cpp.d.ts +0 -2
- package/dist/debug/language/cpp.js +0 -7
- package/dist/debug/language/index.d.ts +0 -3
- package/dist/debug/language/index.js +0 -2
- package/dist/debug/language/python.d.ts +0 -2
- package/dist/debug/language/python.js +0 -14
- package/dist/debug/language/types.d.ts +0 -6
- package/dist/debug/locals.d.ts +0 -2
- package/dist/debug/locals.js +0 -8
- package/dist/lsp/cpp/server.d.ts +0 -2
- package/dist/lsp/cpp/server.js +0 -68
- package/dist/lsp/index.d.ts +0 -5
- package/dist/lsp/index.js +0 -4
- package/dist/lsp/python/main.worker.js +0 -92
- package/dist/lsp/python/package/arcturus_python_lsp/__init__.py +0 -3
- package/dist/lsp/python/package/arcturus_python_lsp/server.py +0 -462
- package/dist/lsp/python/server.d.ts +0 -2
- package/dist/lsp/python/server.js +0 -54
- package/dist/lsp/registry.d.ts +0 -2
- package/dist/lsp/registry.js +0 -12
- package/dist/lsp/runtime.d.ts +0 -5
- package/dist/lsp/runtime.js +0 -31
- package/dist/lsp/types.d.ts +0 -17
- package/dist/terminal/Terminal.svelte +0 -422
- package/dist/terminal/Terminal.svelte.d.ts +0 -26
- package/dist/terminal/index.d.ts +0 -7
- package/dist/terminal/index.js +0 -5
- package/dist/terminal/plugin/index.d.ts +0 -9
- package/dist/terminal/plugin/index.js +0 -19
- package/dist/terminal/theme.d.ts +0 -49
- package/dist/terminal/theme.js +0 -49
- package/dist/terminal/types.d.ts +0 -18
- package/dist/utils/vscodeJsonrpcBrowser.d.ts +0 -5
- package/dist/utils/vscodeJsonrpcBrowser.js +0 -4
- /package/dist/{clangd/worker.d.ts → playground/worker/assemblyscript.d.ts} +0 -0
- /package/dist/{debug/language/types.js → playground/worker/bash.d.ts} +0 -0
- /package/dist/{lsp/python/main.worker.d.ts → playground/worker/cobol.d.ts} +0 -0
- /package/dist/{lsp/types.js → playground/worker/d.d.ts} +0 -0
- /package/dist/{terminal/types.js → playground/worker/dotnet.d.ts} +0 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { ConsoleStdout, Directory, File, OpenFile, PreopenDirectory, WASI, wasi } from '@bjorn3/browser_wasi_shim';
|
|
2
|
+
import { installWasiExtractionQuota } from '@wasm-idle/llvm-core';
|
|
3
|
+
import { loadVerifiedHaskellRuntimeAssets, snapshotHaskellRuntimeAssetConfig } from '../haskellAssets';
|
|
4
|
+
import { waitForBufferedStdin } from '../stdinBuffer';
|
|
5
|
+
let moduleUrl = '';
|
|
6
|
+
let rootfsUrl = '';
|
|
7
|
+
let bsdtarUrl = '';
|
|
8
|
+
let integrity = null;
|
|
9
|
+
let maxAssetBytes = 128 * 1024 * 1024;
|
|
10
|
+
let mainSoPath = '/tmp/libplayground001.so';
|
|
11
|
+
let searchDirs = ['/tmp/clib', '/tmp/hslib/lib/wasm32-wasi-ghc-9.14.0.20251031-inplace'];
|
|
12
|
+
let loadedAssetKey = '';
|
|
13
|
+
let runtimePromise = null;
|
|
14
|
+
let activeStderrCollector = null;
|
|
15
|
+
let activeDiagnosticPaths = null;
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const workspaceRootName = 'wasm-idle-workspace';
|
|
18
|
+
const workspaceRootPath = `/tmp/${workspaceRootName}`;
|
|
19
|
+
class HaskellStdin {
|
|
20
|
+
fixedStdin = false;
|
|
21
|
+
initialStdinPending = false;
|
|
22
|
+
initialStdin = null;
|
|
23
|
+
buffer = null;
|
|
24
|
+
chunk = new Uint8Array(0);
|
|
25
|
+
offset = 0;
|
|
26
|
+
log = false;
|
|
27
|
+
reset({ stdin, buffer, log }) {
|
|
28
|
+
this.fixedStdin = typeof stdin === 'string';
|
|
29
|
+
this.initialStdinPending = this.fixedStdin;
|
|
30
|
+
this.initialStdin = typeof stdin === 'string' ? stdin : null;
|
|
31
|
+
this.buffer = buffer ? new Int32Array(buffer) : null;
|
|
32
|
+
this.chunk = new Uint8Array(0);
|
|
33
|
+
this.offset = 0;
|
|
34
|
+
this.log = log;
|
|
35
|
+
}
|
|
36
|
+
fd_fdstat_get() {
|
|
37
|
+
const fdstat = new wasi.Fdstat(wasi.FILETYPE_CHARACTER_DEVICE, 0);
|
|
38
|
+
fdstat.fs_rights_base = BigInt(wasi.RIGHTS_FD_READ);
|
|
39
|
+
fdstat.fs_rights_inherited = 0n;
|
|
40
|
+
return { ret: wasi.ERRNO_SUCCESS, fdstat };
|
|
41
|
+
}
|
|
42
|
+
fd_filestat_get() {
|
|
43
|
+
return {
|
|
44
|
+
ret: wasi.ERRNO_SUCCESS,
|
|
45
|
+
filestat: new wasi.Filestat(0n, wasi.FILETYPE_CHARACTER_DEVICE, 0n)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
fd_read(size) {
|
|
49
|
+
if (this.offset >= this.chunk.length) {
|
|
50
|
+
const nextChunk = this.readNextChunk();
|
|
51
|
+
if (nextChunk === null) {
|
|
52
|
+
this.chunk = new Uint8Array(0);
|
|
53
|
+
this.offset = 0;
|
|
54
|
+
return { ret: wasi.ERRNO_SUCCESS, data: new Uint8Array(0) };
|
|
55
|
+
}
|
|
56
|
+
this.chunk = encoder.encode(nextChunk);
|
|
57
|
+
this.offset = 0;
|
|
58
|
+
}
|
|
59
|
+
const end = Math.min(this.offset + size, this.chunk.length);
|
|
60
|
+
const data = this.chunk.slice(this.offset, end);
|
|
61
|
+
this.offset = end;
|
|
62
|
+
return { ret: wasi.ERRNO_SUCCESS, data };
|
|
63
|
+
}
|
|
64
|
+
readNextChunk() {
|
|
65
|
+
if (this.initialStdinPending) {
|
|
66
|
+
this.initialStdinPending = false;
|
|
67
|
+
const chunk = this.initialStdin ?? '';
|
|
68
|
+
this.initialStdin = null;
|
|
69
|
+
this.logRead(chunk);
|
|
70
|
+
return chunk;
|
|
71
|
+
}
|
|
72
|
+
if (this.fixedStdin) {
|
|
73
|
+
this.logRead(null);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (!this.buffer) {
|
|
77
|
+
this.logRead(null);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const chunk = waitForBufferedStdin(this.buffer, () => postMessage({ buffer: true }));
|
|
81
|
+
this.logRead(chunk);
|
|
82
|
+
return chunk;
|
|
83
|
+
}
|
|
84
|
+
logRead(chunk) {
|
|
85
|
+
if (!this.log)
|
|
86
|
+
return;
|
|
87
|
+
if (chunk === null) {
|
|
88
|
+
console.log('[wasm-idle:haskell-stdin] fd_read(bytes=0, eof=true)');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
console.log(`[wasm-idle:haskell-stdin] fd_read(bytes=${encoder.encode(chunk).byteLength}, text=${JSON.stringify(chunk)})`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function postProgress(percent) {
|
|
95
|
+
postMessage({ progress: { percent: Math.max(0, Math.min(100, percent)) } });
|
|
96
|
+
}
|
|
97
|
+
function outputLine(line) {
|
|
98
|
+
postMessage({ output: line.endsWith('\n') ? line : `${line}\n` });
|
|
99
|
+
}
|
|
100
|
+
function remapDiagnosticPath(line) {
|
|
101
|
+
const match = /^(.*?)(:\d+:\d+:\s+(?:error|warning):)/i.exec(line);
|
|
102
|
+
if (!match)
|
|
103
|
+
return line;
|
|
104
|
+
const workspacePath = activeDiagnosticPaths?.get(match[1]);
|
|
105
|
+
return workspacePath ? `${workspacePath}${line.slice(match[1].length)}` : line;
|
|
106
|
+
}
|
|
107
|
+
function formatError(error) {
|
|
108
|
+
return error instanceof Error ? error.message : String(error);
|
|
109
|
+
}
|
|
110
|
+
function instantiateResult(result) {
|
|
111
|
+
return result instanceof WebAssembly.Instance ? result : result.instance;
|
|
112
|
+
}
|
|
113
|
+
function installRootfsExtractionWasiPatches(tarWasi, pendingSymlinks) {
|
|
114
|
+
const extractionQuota = installWasiExtractionQuota(tarWasi, {
|
|
115
|
+
label: 'Haskell rootfs'
|
|
116
|
+
});
|
|
117
|
+
tarWasi.wasiImport.fd_filestat_set_times = () => wasi.ERRNO_SUCCESS;
|
|
118
|
+
tarWasi.wasiImport.path_filestat_set_times = () => wasi.ERRNO_SUCCESS;
|
|
119
|
+
tarWasi.wasiImport.path_symlink = (oldPathPointer, oldPathLength, fd, newPathPointer, newPathLength) => {
|
|
120
|
+
if (!tarWasi.fds[fd])
|
|
121
|
+
return wasi.ERRNO_BADF;
|
|
122
|
+
const symlink = extractionQuota.readSymlink(tarWasi, oldPathPointer, oldPathLength, newPathPointer, newPathLength);
|
|
123
|
+
extractionQuota.recordEntry(symlink.path);
|
|
124
|
+
pendingSymlinks.push(symlink);
|
|
125
|
+
return wasi.ERRNO_SUCCESS;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function materializeRootfsSymlinks(rootfs, pendingSymlinks) {
|
|
129
|
+
for (const symlink of pendingSymlinks) {
|
|
130
|
+
const linkPath = symlink.path;
|
|
131
|
+
const { ret, inode_obj: inode } = rootfs.path_lookup(symlink.resolvedTarget, 0);
|
|
132
|
+
if (ret !== wasi.ERRNO_SUCCESS || !inode) {
|
|
133
|
+
throw new Error(`failed to resolve Haskell rootfs symlink ${linkPath} -> ${symlink.target}`);
|
|
134
|
+
}
|
|
135
|
+
const linkRet = rootfs.path_link(linkPath, inode, false);
|
|
136
|
+
if (linkRet !== wasi.ERRNO_SUCCESS) {
|
|
137
|
+
throw new Error(`failed to materialize Haskell rootfs symlink ${linkPath}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function unpackRootfs(bsdtarBytes, rootfsBytes) {
|
|
142
|
+
const rootfs = new PreopenDirectory('/', new Map());
|
|
143
|
+
const pendingSymlinks = [];
|
|
144
|
+
let tarOutput = '';
|
|
145
|
+
const tarStdout = ConsoleStdout.lineBuffered((line) => {
|
|
146
|
+
tarOutput += `${line}\n`;
|
|
147
|
+
});
|
|
148
|
+
const tarStderr = ConsoleStdout.lineBuffered((line) => {
|
|
149
|
+
tarOutput += `${line}\n`;
|
|
150
|
+
});
|
|
151
|
+
const tarWasi = new WASI(['bsdtar.wasm', '-x'], [], [
|
|
152
|
+
new OpenFile(new File(new Uint8Array(), { readonly: true })),
|
|
153
|
+
tarStdout,
|
|
154
|
+
tarStderr,
|
|
155
|
+
rootfs
|
|
156
|
+
], { debug: false });
|
|
157
|
+
installRootfsExtractionWasiPatches(tarWasi, pendingSymlinks);
|
|
158
|
+
postProgress(75);
|
|
159
|
+
const tarInstance = instantiateResult(await WebAssembly.instantiate(bsdtarBytes, {
|
|
160
|
+
wasi_snapshot_preview1: tarWasi.wasiImport
|
|
161
|
+
}));
|
|
162
|
+
tarWasi.fds[0] = new OpenFile(new File(rootfsBytes, { readonly: true }));
|
|
163
|
+
const exitCode = tarWasi.start(tarInstance);
|
|
164
|
+
if (typeof exitCode === 'number' && exitCode !== 0) {
|
|
165
|
+
throw new Error(tarOutput || `bsdtar exited with code ${exitCode}`);
|
|
166
|
+
}
|
|
167
|
+
materializeRootfsSymlinks(rootfs, pendingSymlinks);
|
|
168
|
+
postProgress(90);
|
|
169
|
+
return rootfs;
|
|
170
|
+
}
|
|
171
|
+
async function createRuntime() {
|
|
172
|
+
if (!moduleUrl || !rootfsUrl || !bsdtarUrl || !integrity) {
|
|
173
|
+
throw new Error('Haskell runtime is not configured. Set PUBLIC_WASM_HASKELL_MODULE_URL, PUBLIC_WASM_HASKELL_ROOTFS_URL, and PUBLIC_WASM_HASKELL_BSDTAR_URL, or runtimeAssets.haskell.');
|
|
174
|
+
}
|
|
175
|
+
const assetKey = JSON.stringify({
|
|
176
|
+
moduleUrl,
|
|
177
|
+
rootfsUrl,
|
|
178
|
+
bsdtarUrl,
|
|
179
|
+
integrity,
|
|
180
|
+
maxAssetBytes,
|
|
181
|
+
mainSoPath,
|
|
182
|
+
searchDirs
|
|
183
|
+
});
|
|
184
|
+
if (loadedAssetKey === assetKey && runtimePromise) {
|
|
185
|
+
return await runtimePromise;
|
|
186
|
+
}
|
|
187
|
+
const pendingRuntime = (async () => {
|
|
188
|
+
postProgress(5);
|
|
189
|
+
const verified = await loadVerifiedHaskellRuntimeAssets({
|
|
190
|
+
moduleUrl,
|
|
191
|
+
rootfsUrl,
|
|
192
|
+
bsdtarUrl,
|
|
193
|
+
integrity,
|
|
194
|
+
maxAssetBytes
|
|
195
|
+
}, {
|
|
196
|
+
onProgress({ asset, loaded, total }) {
|
|
197
|
+
if (!total || total <= 0)
|
|
198
|
+
return;
|
|
199
|
+
const [start, end] = asset === 'dyld.mjs'
|
|
200
|
+
? [5, 15]
|
|
201
|
+
: asset === 'bsdtar.wasm'
|
|
202
|
+
? [15, 25]
|
|
203
|
+
: [25, 70];
|
|
204
|
+
postProgress(start + ((end - start) * loaded) / total);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const rootfs = await unpackRootfs(verified.bsdtarBytes, verified.rootfsBytes);
|
|
208
|
+
const verifiedModuleUrl = URL.createObjectURL(new Blob([verified.moduleSource], { type: 'text/javascript' }));
|
|
209
|
+
let dyldModule;
|
|
210
|
+
try {
|
|
211
|
+
dyldModule = await import(/* @vite-ignore */ verifiedModuleUrl);
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
URL.revokeObjectURL(verifiedModuleUrl);
|
|
215
|
+
}
|
|
216
|
+
if (typeof dyldModule.main !== 'function' ||
|
|
217
|
+
typeof dyldModule.DyLDBrowserHost !== 'function') {
|
|
218
|
+
throw new Error('wasm-haskell module must export main and DyLDBrowserHost');
|
|
219
|
+
}
|
|
220
|
+
const stdin = new HaskellStdin();
|
|
221
|
+
const host = new dyldModule.DyLDBrowserHost({
|
|
222
|
+
rootfs,
|
|
223
|
+
stdin,
|
|
224
|
+
stdout: outputLine,
|
|
225
|
+
stderr(line) {
|
|
226
|
+
const mappedLine = remapDiagnosticPath(line);
|
|
227
|
+
activeStderrCollector?.(mappedLine);
|
|
228
|
+
outputLine(mappedLine);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const dyld = await dyldModule.main({
|
|
232
|
+
rpc: host,
|
|
233
|
+
searchDirs,
|
|
234
|
+
mainSoPath,
|
|
235
|
+
args: [mainSoPath.split('/').pop() || 'libplayground001.so', '+RTS', '-c', '-RTS'],
|
|
236
|
+
isIserv: false
|
|
237
|
+
});
|
|
238
|
+
const exportedMain = dyld?.exportFuncs?.myMain;
|
|
239
|
+
if (typeof exportedMain !== 'function') {
|
|
240
|
+
throw new Error('wasm-haskell runtime did not export myMain');
|
|
241
|
+
}
|
|
242
|
+
const mainFunc = await exportedMain('/tmp/hslib/lib');
|
|
243
|
+
if (typeof mainFunc !== 'function') {
|
|
244
|
+
throw new Error('wasm-haskell myMain did not return a callable function');
|
|
245
|
+
}
|
|
246
|
+
postProgress(100);
|
|
247
|
+
return { mainFunc, rootfs, stdin };
|
|
248
|
+
})();
|
|
249
|
+
loadedAssetKey = assetKey;
|
|
250
|
+
runtimePromise = pendingRuntime;
|
|
251
|
+
try {
|
|
252
|
+
return await pendingRuntime;
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
if (runtimePromise === pendingRuntime) {
|
|
256
|
+
runtimePromise = null;
|
|
257
|
+
loadedAssetKey = '';
|
|
258
|
+
}
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
export function parseHaskellDiagnostics(output) {
|
|
263
|
+
const diagnostics = [];
|
|
264
|
+
const lines = output.split(/\r\n|\r|\n/);
|
|
265
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
266
|
+
const match = /^(.*?):(\d+):(\d+):\s+(error|warning):\s*(.*)$/i.exec(lines[index]);
|
|
267
|
+
if (!match)
|
|
268
|
+
continue;
|
|
269
|
+
let message = match[5].trim();
|
|
270
|
+
if (!message) {
|
|
271
|
+
for (const extraLine of lines.slice(index + 1)) {
|
|
272
|
+
const trimmed = extraLine.trim();
|
|
273
|
+
if (!trimmed || trimmed === '|' || /^\d+\s+\|/.test(trimmed))
|
|
274
|
+
continue;
|
|
275
|
+
message = trimmed;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
diagnostics.push({
|
|
280
|
+
fileName: match[1] || null,
|
|
281
|
+
lineNumber: Math.max(1, Number(match[2] || 1)),
|
|
282
|
+
columnNumber: Math.max(1, Number(match[3] || 1)),
|
|
283
|
+
severity: match[4].toLowerCase() === 'warning' ? 'warning' : 'error',
|
|
284
|
+
message: message || lines[index]
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return diagnostics;
|
|
288
|
+
}
|
|
289
|
+
function createWorkspaceTree() {
|
|
290
|
+
return { directories: new Map(), files: new Map() };
|
|
291
|
+
}
|
|
292
|
+
function encodeWorkspacePath(path) {
|
|
293
|
+
return path
|
|
294
|
+
.split('/')
|
|
295
|
+
.map((segment) => encodeURIComponent(segment))
|
|
296
|
+
.join('/');
|
|
297
|
+
}
|
|
298
|
+
function addWorkspaceFile(tree, encodedPath, content) {
|
|
299
|
+
const pathParts = encodedPath.split('/');
|
|
300
|
+
const fileName = pathParts.pop();
|
|
301
|
+
if (!fileName)
|
|
302
|
+
throw new Error(`Invalid Haskell workspace path: ${encodedPath}`);
|
|
303
|
+
let directory = tree;
|
|
304
|
+
for (const pathPart of pathParts) {
|
|
305
|
+
if (directory.files.has(pathPart)) {
|
|
306
|
+
throw new Error(`Haskell workspace path collides with a file: ${encodedPath}`);
|
|
307
|
+
}
|
|
308
|
+
let child = directory.directories.get(pathPart);
|
|
309
|
+
if (!child) {
|
|
310
|
+
child = createWorkspaceTree();
|
|
311
|
+
directory.directories.set(pathPart, child);
|
|
312
|
+
}
|
|
313
|
+
directory = child;
|
|
314
|
+
}
|
|
315
|
+
if (directory.directories.has(fileName)) {
|
|
316
|
+
throw new Error(`Haskell workspace path collides with a directory: ${encodedPath}`);
|
|
317
|
+
}
|
|
318
|
+
directory.files.set(fileName, encoder.encode(content));
|
|
319
|
+
}
|
|
320
|
+
function materializeWorkspaceTree(tree) {
|
|
321
|
+
const contents = [];
|
|
322
|
+
for (const [name, directory] of tree.directories) {
|
|
323
|
+
contents.push([name, materializeWorkspaceTree(directory)]);
|
|
324
|
+
}
|
|
325
|
+
for (const [name, content] of tree.files) {
|
|
326
|
+
contents.push([name, new File(content, { readonly: true })]);
|
|
327
|
+
}
|
|
328
|
+
return new Directory(contents);
|
|
329
|
+
}
|
|
330
|
+
function addImportRoot(importRoots, seen, encodedDirectory) {
|
|
331
|
+
const root = encodedDirectory ? `${workspaceRootPath}/${encodedDirectory}` : workspaceRootPath;
|
|
332
|
+
if (seen.has(root))
|
|
333
|
+
return;
|
|
334
|
+
seen.add(root);
|
|
335
|
+
importRoots.push(root);
|
|
336
|
+
}
|
|
337
|
+
function addFileImportRoots(importRoots, seen, encodedPath) {
|
|
338
|
+
const directoryParts = encodedPath.split('/').slice(0, -1);
|
|
339
|
+
for (let length = directoryParts.length; length >= 0; length -= 1) {
|
|
340
|
+
addImportRoot(importRoots, seen, directoryParts.slice(0, length).join('/'));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function mountWorkspace(rootfs, code, activePath, workspaceFiles) {
|
|
344
|
+
const sourceFiles = new Map();
|
|
345
|
+
for (const file of workspaceFiles) {
|
|
346
|
+
if (file.path !== activePath)
|
|
347
|
+
sourceFiles.set(file.path, file.content);
|
|
348
|
+
}
|
|
349
|
+
sourceFiles.set(activePath, code);
|
|
350
|
+
const tree = createWorkspaceTree();
|
|
351
|
+
const diagnosticPaths = new Map([
|
|
352
|
+
['/tmp/Main.hs', activePath],
|
|
353
|
+
['tmp/Main.hs', activePath],
|
|
354
|
+
['Main.hs', activePath]
|
|
355
|
+
]);
|
|
356
|
+
const encodedPaths = new Map();
|
|
357
|
+
for (const [path, content] of sourceFiles) {
|
|
358
|
+
const encodedPath = encodeWorkspacePath(path);
|
|
359
|
+
encodedPaths.set(path, encodedPath);
|
|
360
|
+
addWorkspaceFile(tree, encodedPath, content);
|
|
361
|
+
const absolutePath = `${workspaceRootPath}/${encodedPath}`;
|
|
362
|
+
diagnosticPaths.set(absolutePath, path);
|
|
363
|
+
diagnosticPaths.set(absolutePath.slice(1), path);
|
|
364
|
+
}
|
|
365
|
+
let tmp = rootfs.dir.contents.get('tmp');
|
|
366
|
+
if (tmp === undefined) {
|
|
367
|
+
tmp = new Directory(new Map());
|
|
368
|
+
rootfs.dir.contents.set('tmp', tmp);
|
|
369
|
+
}
|
|
370
|
+
if (!(tmp instanceof Directory)) {
|
|
371
|
+
throw new Error('Haskell runtime rootfs /tmp entry is not a directory');
|
|
372
|
+
}
|
|
373
|
+
tmp.contents.set(workspaceRootName, materializeWorkspaceTree(tree));
|
|
374
|
+
const importRoots = [];
|
|
375
|
+
const seenImportRoots = new Set();
|
|
376
|
+
const encodedActivePath = encodedPaths.get(activePath);
|
|
377
|
+
if (encodedActivePath) {
|
|
378
|
+
addFileImportRoots(importRoots, seenImportRoots, encodedActivePath);
|
|
379
|
+
}
|
|
380
|
+
for (const [path, encodedPath] of encodedPaths) {
|
|
381
|
+
if (path !== activePath)
|
|
382
|
+
addFileImportRoots(importRoots, seenImportRoots, encodedPath);
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
diagnosticPaths,
|
|
386
|
+
importRoots,
|
|
387
|
+
hasAuxiliaryFiles: sourceFiles.size > 1
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function appendWorkspaceCompilerArgs(ghcArgs, workspace) {
|
|
391
|
+
if (!workspace.hasAuxiliaryFiles)
|
|
392
|
+
return ghcArgs;
|
|
393
|
+
const internalArgs = ['-fforce-recomp', `-i${workspace.importRoots.join(':')}`];
|
|
394
|
+
return [...internalArgs, ghcArgs].filter(Boolean).join(' ');
|
|
395
|
+
}
|
|
396
|
+
self.onmessage = async (event) => {
|
|
397
|
+
const { load, moduleUrl: nextModuleUrl, rootfsUrl: nextRootfsUrl, bsdtarUrl: nextBsdtarUrl, integrity: nextIntegrity, maxAssetBytes: nextMaxAssetBytes, mainSoPath: nextMainSoPath, searchDirs: nextSearchDirs, code, prepare, buffer, stdin, ghcArgs = '', activePath = 'main.hs', workspaceFiles = [], log } = event.data;
|
|
398
|
+
try {
|
|
399
|
+
if (load) {
|
|
400
|
+
const nextConfig = snapshotHaskellRuntimeAssetConfig({
|
|
401
|
+
moduleUrl: nextModuleUrl,
|
|
402
|
+
rootfsUrl: nextRootfsUrl,
|
|
403
|
+
bsdtarUrl: nextBsdtarUrl,
|
|
404
|
+
integrity: nextIntegrity,
|
|
405
|
+
maxAssetBytes: nextMaxAssetBytes
|
|
406
|
+
});
|
|
407
|
+
moduleUrl = nextConfig.moduleUrl;
|
|
408
|
+
rootfsUrl = nextConfig.rootfsUrl;
|
|
409
|
+
bsdtarUrl = nextConfig.bsdtarUrl;
|
|
410
|
+
integrity = nextConfig.integrity;
|
|
411
|
+
maxAssetBytes = nextConfig.maxAssetBytes;
|
|
412
|
+
mainSoPath = nextMainSoPath || mainSoPath;
|
|
413
|
+
searchDirs =
|
|
414
|
+
Array.isArray(nextSearchDirs) && nextSearchDirs.length
|
|
415
|
+
? nextSearchDirs
|
|
416
|
+
: searchDirs;
|
|
417
|
+
if (log) {
|
|
418
|
+
console.log(`[wasm-idle:haskell-worker] load moduleUrl=${moduleUrl} rootfsUrl=${rootfsUrl} bsdtarUrl=${bsdtarUrl}`);
|
|
419
|
+
}
|
|
420
|
+
await createRuntime();
|
|
421
|
+
postMessage({ load: true });
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (prepare) {
|
|
425
|
+
postMessage({ results: true });
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const runtime = await createRuntime();
|
|
429
|
+
const source = String(code ?? '');
|
|
430
|
+
const workspace = mountWorkspace(runtime.rootfs, source, activePath, workspaceFiles);
|
|
431
|
+
const compilerArgs = appendWorkspaceCompilerArgs(String(ghcArgs || ''), workspace);
|
|
432
|
+
runtime.stdin.reset({ stdin, buffer, log: !!log });
|
|
433
|
+
let stderrText = '';
|
|
434
|
+
try {
|
|
435
|
+
activeDiagnosticPaths = workspace.diagnosticPaths;
|
|
436
|
+
activeStderrCollector = (line) => {
|
|
437
|
+
stderrText += line.endsWith('\n') ? line : `${line}\n`;
|
|
438
|
+
};
|
|
439
|
+
if (log) {
|
|
440
|
+
console.log(`[wasm-idle:haskell-worker] run start activePath=${activePath} ghcArgs=${JSON.stringify(compilerArgs)} bytes=${source.length}`);
|
|
441
|
+
}
|
|
442
|
+
await runtime.mainFunc(compilerArgs, source);
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
for (const diagnostic of parseHaskellDiagnostics(stderrText)) {
|
|
446
|
+
postMessage({ diagnostic });
|
|
447
|
+
}
|
|
448
|
+
throw new Error(stderrText.trim() || formatError(error), { cause: error });
|
|
449
|
+
}
|
|
450
|
+
finally {
|
|
451
|
+
activeStderrCollector = null;
|
|
452
|
+
activeDiagnosticPaths = null;
|
|
453
|
+
}
|
|
454
|
+
for (const diagnostic of parseHaskellDiagnostics(stderrText)) {
|
|
455
|
+
postMessage({ diagnostic });
|
|
456
|
+
}
|
|
457
|
+
postMessage({ results: true });
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
if (log) {
|
|
461
|
+
console.error('[wasm-idle:haskell-worker] failed', error);
|
|
462
|
+
}
|
|
463
|
+
postMessage({ error: error?.message || String(error) });
|
|
464
|
+
}
|
|
465
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { prepareJavaStdinInjection } from '../javaStdin';
|
|
2
|
+
import { resolveJavaSourceIdentity } from '../javaSource';
|
|
2
3
|
import { waitForBufferedStdin } from '../stdinBuffer';
|
|
3
4
|
import { configureWorkerRuntimeAssets, handleWorkerAssetMessage, loadWorkerRuntimeAsset } from './assets';
|
|
4
5
|
let compilerLib = null;
|
|
@@ -14,7 +15,9 @@ let compiledCode = '';
|
|
|
14
15
|
let compiledStdin = '';
|
|
15
16
|
let compiledMainClass = '';
|
|
16
17
|
let compiledWasm = null;
|
|
17
|
-
let
|
|
18
|
+
let compiledActivePath = '';
|
|
19
|
+
let compiledWorkspaceFiles = [];
|
|
20
|
+
let currentSourcePaths = new Set();
|
|
18
21
|
const decoder = new TextDecoder();
|
|
19
22
|
const toInt8Array = (bytes) => new Int8Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
|
|
20
23
|
const flushStdout = () => {
|
|
@@ -42,7 +45,7 @@ const pushStderr = (charCode) => {
|
|
|
42
45
|
self.addEventListener('message', async (event) => {
|
|
43
46
|
if (handleWorkerAssetMessage(event.data))
|
|
44
47
|
return;
|
|
45
|
-
const { load, assets, buffer, code, prepare, args = [], stdin = '' } = event.data;
|
|
48
|
+
const { load, assets, buffer, code, prepare, args = [], stdin = '', hasExplicitStdin = false, activePath, workspaceFiles = [] } = event.data;
|
|
46
49
|
try {
|
|
47
50
|
if (load) {
|
|
48
51
|
const runtimeAssets = assets;
|
|
@@ -72,6 +75,9 @@ self.addEventListener('message', async (event) => {
|
|
|
72
75
|
compiledStdin = '';
|
|
73
76
|
compiledMainClass = '';
|
|
74
77
|
compiledWasm = null;
|
|
78
|
+
compiledActivePath = '';
|
|
79
|
+
compiledWorkspaceFiles = [];
|
|
80
|
+
currentSourcePaths = new Set();
|
|
75
81
|
}
|
|
76
82
|
self.postMessage({ load: true });
|
|
77
83
|
return;
|
|
@@ -80,23 +86,36 @@ self.addEventListener('message', async (event) => {
|
|
|
80
86
|
throw new Error('TeaVM compiler not loaded');
|
|
81
87
|
stdoutBuffer = '';
|
|
82
88
|
stderrBuffer = '';
|
|
83
|
-
const
|
|
89
|
+
const explicitStdin = hasExplicitStdin === true;
|
|
90
|
+
const stdinInjection = prepareJavaStdinInjection(code, stdin, explicitStdin);
|
|
91
|
+
const sourceIdentity = resolveJavaSourceIdentity(code);
|
|
92
|
+
const sourcePath = typeof activePath === 'string' && activePath ? activePath : sourceIdentity.sourcePath;
|
|
93
|
+
const sourceFileName = sourcePath.split('/').pop() || sourcePath;
|
|
94
|
+
if (!Array.isArray(workspaceFiles) ||
|
|
95
|
+
!workspaceFiles.every((file) => file && typeof file.path === 'string' && typeof file.content === 'string')) {
|
|
96
|
+
throw new Error('Invalid Java workspace files');
|
|
97
|
+
}
|
|
98
|
+
const sourceFiles = workspaceFiles;
|
|
99
|
+
const workspaceChanged = compiledActivePath !== sourcePath ||
|
|
100
|
+
compiledWorkspaceFiles.length !== sourceFiles.length ||
|
|
101
|
+
compiledWorkspaceFiles.some((file, index) => file.path !== sourceFiles[index]?.path ||
|
|
102
|
+
file.content !== sourceFiles[index]?.content);
|
|
103
|
+
if (stdinInjection.usesStdin &&
|
|
104
|
+
stdinInjection.helperSourcePath &&
|
|
105
|
+
(sourcePath === stdinInjection.helperSourcePath ||
|
|
106
|
+
sourceFiles.some((file) => file.path === stdinInjection.helperSourcePath))) {
|
|
107
|
+
throw new Error(`Java workspace conflicts with generated stdin helper: ${stdinInjection.helperSourcePath}`);
|
|
108
|
+
}
|
|
84
109
|
if (prepare ||
|
|
85
110
|
compiledCode !== code ||
|
|
86
111
|
compiledStdin !== stdinInjection.stdinCacheKey ||
|
|
112
|
+
workspaceChanged ||
|
|
87
113
|
!compiledWasm) {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
throw new Error('Java source must define a top-level class, record, enum, or interface');
|
|
94
|
-
const packageName = packageMatch?.[1] || '';
|
|
95
|
-
const sourcePath = packageName
|
|
96
|
-
? `${packageName.replaceAll('.', '/')}/${className}.java`
|
|
97
|
-
: `${className}.java`;
|
|
98
|
-
const mainClass = packageName ? `${packageName}.${className}` : className;
|
|
99
|
-
currentSourcePath = sourcePath;
|
|
114
|
+
const mainClass = sourceIdentity.mainClass;
|
|
115
|
+
currentSourcePaths = new Set([sourcePath, ...sourceFiles.map((file) => file.path)].flatMap((path) => [
|
|
116
|
+
path,
|
|
117
|
+
path.split('/').pop() || path
|
|
118
|
+
]));
|
|
100
119
|
const diagnosticLines = [];
|
|
101
120
|
const diagnosticRegistration = compiler.onDiagnostic((diagnostic) => {
|
|
102
121
|
const severity = diagnostic.severity
|
|
@@ -107,9 +126,7 @@ self.addEventListener('message', async (event) => {
|
|
|
107
126
|
: 'TeaVM';
|
|
108
127
|
diagnosticLines.push(`${location}: ${severity}: ${diagnostic.message}`);
|
|
109
128
|
const fileName = diagnostic.fileName ? String(diagnostic.fileName) : null;
|
|
110
|
-
if (fileName &&
|
|
111
|
-
fileName !== currentSourcePath &&
|
|
112
|
-
fileName !== currentSourcePath.split('/').pop()) {
|
|
129
|
+
if (fileName && !currentSourcePaths.has(fileName)) {
|
|
113
130
|
return;
|
|
114
131
|
}
|
|
115
132
|
self.postMessage({
|
|
@@ -136,11 +153,19 @@ self.addEventListener('message', async (event) => {
|
|
|
136
153
|
compiler.clearSourceFiles?.();
|
|
137
154
|
compiler.clearInputClassFiles?.();
|
|
138
155
|
compiler.clearOutputFiles?.();
|
|
139
|
-
|
|
156
|
+
// TeaVM derives packages from source text but validates public types against the basename.
|
|
157
|
+
compiler.addSourceFile(sourceFileName, stdinInjection.transformedCode);
|
|
158
|
+
for (const file of sourceFiles) {
|
|
159
|
+
compiler.addSourceFile(file.path.split('/').pop() || file.path, file.content);
|
|
160
|
+
}
|
|
140
161
|
if (stdinInjection.usesStdin &&
|
|
141
162
|
stdinInjection.helperSourcePath &&
|
|
142
163
|
stdinInjection.helperSource) {
|
|
143
|
-
compiler.addSourceFile(stdinInjection.helperSourcePath
|
|
164
|
+
compiler.addSourceFile(stdinInjection.helperSourcePath.split('/').pop() ||
|
|
165
|
+
stdinInjection.helperSourcePath, stdinInjection.helperSource);
|
|
166
|
+
currentSourcePaths.add(stdinInjection.helperSourcePath);
|
|
167
|
+
currentSourcePaths.add(stdinInjection.helperSourcePath.split('/').pop() ||
|
|
168
|
+
stdinInjection.helperSourcePath);
|
|
144
169
|
}
|
|
145
170
|
const javacOk = compiler.compile();
|
|
146
171
|
if (!javacOk) {
|
|
@@ -166,12 +191,16 @@ self.addEventListener('message', async (event) => {
|
|
|
166
191
|
compiledStdin = stdinInjection.stdinCacheKey;
|
|
167
192
|
compiledMainClass = mainClass;
|
|
168
193
|
compiledWasm = new Uint8Array(compiler.getWebAssemblyOutputFile('app.wasm'));
|
|
194
|
+
compiledActivePath = sourcePath;
|
|
195
|
+
compiledWorkspaceFiles = sourceFiles.map((file) => ({ ...file }));
|
|
169
196
|
}
|
|
170
197
|
if (prepare) {
|
|
171
198
|
self.postMessage({ results: true });
|
|
172
199
|
return;
|
|
173
200
|
}
|
|
174
201
|
stdinBufferJava = new Int32Array(buffer);
|
|
202
|
+
stdinChunkJava = explicitStdin ? new Uint8Array(0) : new TextEncoder().encode(stdin);
|
|
203
|
+
stdinChunkOffsetJava = 0;
|
|
175
204
|
const workerGlobal = globalThis;
|
|
176
205
|
const previousWindow = workerGlobal.window;
|
|
177
206
|
workerGlobal.window = workerGlobal;
|
|
@@ -181,6 +210,8 @@ self.addEventListener('message', async (event) => {
|
|
|
181
210
|
if (stdinChunkOffsetJava < stdinChunkJava.length) {
|
|
182
211
|
return stdinChunkJava[stdinChunkOffsetJava++] ?? -1;
|
|
183
212
|
}
|
|
213
|
+
if (explicitStdin)
|
|
214
|
+
return -1;
|
|
184
215
|
const chunk = waitForBufferedStdin(stdinBufferJava, () => self.postMessage({ buffer: true }));
|
|
185
216
|
if (chunk === null) {
|
|
186
217
|
return -1;
|
|
@@ -200,6 +231,14 @@ self.addEventListener('message', async (event) => {
|
|
|
200
231
|
enabled: false
|
|
201
232
|
}
|
|
202
233
|
});
|
|
234
|
+
self.postMessage({
|
|
235
|
+
progress: {
|
|
236
|
+
kind: 'ready',
|
|
237
|
+
state: 'running',
|
|
238
|
+
reason: 'started',
|
|
239
|
+
label: 'Java program started'
|
|
240
|
+
}
|
|
241
|
+
});
|
|
203
242
|
module.exports.main(args);
|
|
204
243
|
flushStdout();
|
|
205
244
|
flushStderr();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|