Skip to content

Commit b4eebe2

Browse files
Remove unnecessary modifs
1 parent 5bbdab9 commit b4eebe2

7 files changed

Lines changed: 21 additions & 202 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
mkdir -p public/generated
4545
python -m multilingualprogramming compile src/automate_universel.ml > public/generated/automate_universel.py
4646
python -m multilingualprogramming build-wasm-bundle src/automate_packed_wasm.ml --out-dir public/generated/automate_packed
47-
python scripts/ensure_wasm_bundle.py public/generated/automate_packed
47+
cp public/generated/automate_packed/host_shim.js public/generated/automate_packed/host_shim.mjs
4848
4949
- name: Verifier les artefacts de compilation
5050
run: |

.github/workflows/monitor-multilingual.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
mkdir -p public/generated
7575
python -m multilingualprogramming compile src/automate_universel.ml > public/generated/automate_universel.py
7676
python -m multilingualprogramming build-wasm-bundle src/automate_packed_wasm.ml --out-dir public/generated/automate_packed
77-
python scripts/ensure_wasm_bundle.py public/generated/automate_packed
77+
cp public/generated/automate_packed/host_shim.js public/generated/automate_packed/host_shim.mjs
7878
7979
- name: Verifier la syntaxe JavaScript
8080
run: |

public/generated/automate_packed_runtime.mjs

Lines changed: 11 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,28 @@
1-
import * as hostShim from "./automate_packed/host_shim.mjs";
2-
3-
function createFallbackWasiImports(memoryRef = { current: null }, outputCallback = () => {}) {
4-
const textDecoder = new TextDecoder("utf-8");
5-
let stdoutBuffer = "";
6-
const writeOutput = () => {
7-
let newlineIndex;
8-
while ((newlineIndex = stdoutBuffer.indexOf("\n")) !== -1) {
9-
outputCallback(stdoutBuffer.slice(0, newlineIndex));
10-
stdoutBuffer = stdoutBuffer.slice(newlineIndex + 1);
11-
}
12-
};
13-
14-
return {
15-
wasi_snapshot_preview1: {
16-
fd_write(fd, iovsPtr, iovsLen, nwrittenPtr) {
17-
if (fd !== 1 && fd !== 2) return 8;
18-
const memory = memoryRef.current;
19-
if (!memory) return 8;
20-
const view = new DataView(memory.buffer);
21-
let written = 0;
22-
for (let index = 0; index < iovsLen; index += 1) {
23-
const ptr = view.getUint32(iovsPtr + index * 8, true);
24-
const len = view.getUint32(iovsPtr + index * 8 + 4, true);
25-
stdoutBuffer += textDecoder.decode(new Uint8Array(memory.buffer, ptr, len));
26-
written += len;
27-
}
28-
writeOutput();
29-
view.setUint32(nwrittenPtr, written, true);
30-
return 0;
31-
},
32-
fd_read(_fd, _iovsPtr, _iovsLen, nreadPtr) {
33-
const memory = memoryRef.current;
34-
if (memory) {
35-
new DataView(memory.buffer).setUint32(nreadPtr, 0, true);
36-
}
37-
return 0;
38-
},
39-
args_sizes_get(argcPtr, argvBufSizePtr) {
40-
const memory = memoryRef.current;
41-
if (!memory) return 8;
42-
const view = new DataView(memory.buffer);
43-
view.setUint32(argcPtr, 0, true);
44-
view.setUint32(argvBufSizePtr, 0, true);
45-
return 0;
46-
},
47-
args_get() {
48-
return 0;
49-
},
50-
},
51-
memoryRef,
52-
};
53-
}
54-
55-
function createFallbackDomImports(memoryRef = { current: null }, _exportsRef = { current: null }, outputCallback = () => {}) {
56-
const readString = (ptr, len) => {
57-
const memory = memoryRef.current;
58-
if (!memory || ptr <= 0 || len <= 0) return "";
59-
return new TextDecoder("utf-8").decode(new Uint8Array(memory.buffer, ptr, len));
60-
};
61-
62-
return {
63-
env: {
64-
print_str(ptr, len) {
65-
outputCallback(readString(ptr, len));
66-
},
67-
print_num(value) {
68-
outputCallback(String(value));
69-
},
70-
print(value) {
71-
outputCallback(String(value));
72-
},
73-
},
74-
};
75-
}
76-
77-
function createDefaultImport(entry) {
78-
if (entry.kind === "function") {
79-
return () => 0;
80-
}
81-
if (entry.kind === "memory") {
82-
return new WebAssembly.Memory({ initial: 16 });
83-
}
84-
if (entry.kind === "table") {
85-
return new WebAssembly.Table({ initial: 0, element: "anyfunc" });
86-
}
87-
if (entry.kind === "global") {
88-
return new WebAssembly.Global({ value: "i32", mutable: true }, 0);
89-
}
90-
return undefined;
91-
}
92-
93-
function completeImports(module, imports) {
94-
for (const entry of WebAssembly.Module.imports(module)) {
95-
if (!imports[entry.module]) {
96-
imports[entry.module] = {};
97-
}
98-
if (imports[entry.module][entry.name] === undefined) {
99-
imports[entry.module][entry.name] = createDefaultImport(entry);
100-
}
101-
}
102-
return imports;
103-
}
1+
import { createDomImports, createWasiImports } from "./automate_packed/host_shim.mjs";
1042

1053
export async function loadAutomaginariumPacked(options = {}) {
1064
const wasmUrl = options.wasmUrl || new URL("./automate_packed/module.wasm", import.meta.url);
1075
const memoryRef = { current: null };
1086
const exportsRef = { current: null };
109-
const createWasiImports = hostShim.createWasiImports || createFallbackWasiImports;
110-
const createDomImports = hostShim.createDomImports || createFallbackDomImports;
111-
const baseImports = {
7+
const imports = {
1128
...createWasiImports(memoryRef, options.outputCallback || (() => {})),
113-
...createDomImports(memoryRef, exportsRef, options.outputCallback || (() => {})),
9+
...createDomImports(memoryRef, exportsRef),
11410
};
11511

116-
let module;
12+
let instance;
11713
if (options.bytes) {
118-
module = await WebAssembly.compile(options.bytes);
14+
const result = await WebAssembly.instantiate(options.bytes, imports);
15+
instance = result.instance;
16+
} else if (typeof WebAssembly.instantiateStreaming === "function") {
17+
const result = await WebAssembly.instantiateStreaming(fetch(wasmUrl), imports);
18+
instance = result.instance;
11919
} else {
12020
const response = await fetch(wasmUrl);
12121
const bytes = await response.arrayBuffer();
122-
module = await WebAssembly.compile(bytes);
22+
const result = await WebAssembly.instantiate(bytes, imports);
23+
instance = result.instance;
12324
}
12425

125-
const imports = completeImports(module, baseImports);
126-
const instance = await WebAssembly.instantiate(module, imports);
12726
exportsRef.current = instance.exports;
12827
memoryRef.current = instance.exports.memory || memoryRef.current;
12928
return instance.exports;

scripts/build-stage4.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ $compiled | Out-File -Encoding utf8 public\generated\automate_universel.py
99

1010
multilingual build-wasm-bundle src\automate_packed_wasm.ml --out-dir public\generated\automate_packed
1111
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
12-
13-
python scripts\ensure_wasm_bundle.py public\generated\automate_packed
14-
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
12+
Copy-Item -Force public\generated\automate_packed\host_shim.js public\generated\automate_packed\host_shim.mjs
1513

1614
Write-Host "Stage 4 generated artifacts refreshed."

scripts/ensure_wasm_bundle.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/automate_packed_wasm.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ def sortie_table_code(code_sortie, taille_alphabet):
8484

8585
def validation_mode_regle(code_mode):
8686
# 0=table, 1=totalistique, 2=aleatoire
87-
retour 1 si code_mode == 0 ou code_mode == 1 ou code_mode == 2 sinon 0
87+
si code_mode == 0:
88+
retour 1
89+
si code_mode == 1:
90+
retour 1
91+
si code_mode == 2:
92+
retour 1
93+
retour 0

tests/stage5-static.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ function testRuntimeLoaderIsCommitted() {
3333
const loader = read("public/generated/automate_packed_runtime.mjs");
3434
assert(loader.includes("./automate_packed/module.wasm"));
3535
assert(loader.includes("./automate_packed/host_shim.mjs"));
36-
assert(loader.includes("import * as hostShim"));
37-
assert(loader.includes("createFallbackDomImports"));
38-
assert(loader.includes("print_str"));
39-
assert(loader.includes("WebAssembly.Module.imports"));
40-
assert(loader.includes("createDefaultImport"));
4136
}
4237

4338
testPagesEntrypoints();

0 commit comments

Comments
 (0)