Hi,
So I am attempting to add WASM to my Github Page. Started with this simple test library:
library test;
uses sysutils;
procedure hello;
begin
writeln(Format('hello world from FPC %s for %s', [ {$I %FPCVERSION%}, {$I %FPCTARGETCPU%} ]));
writeln(Format('compiled on %s %s', [ {$I %DATE%}, {$I %TIME%} ]));
end;
exports
hello;
end.
Compiled with WASI Preview 1 (target "OS") + WASM32 (target platform) cross-compiler.
The browser instead throws this error: WebAssembly.instantiate(): Import #0 "wasi_snapshot_preview1": module is not an object or function.
The JavaScript part (I think the second parameter is not really correct):
const res = fetch("test.wasm");
await WebAssembly.instantiateStreaming(res, {
test: {
hello: () => {
console.log("?");
}
},
});
Edit: I know that one can use Pas2JS to create an environment that can be used to load WASM, but is there any other way? Pas2JS returned this error:
C:\fpcupdeluxe\fpcsrc\rtl\win64\windows.pp(19,13) Error: Illegal compiler directive "PackSet"
Its config file is:
-vwnh
-Sc
-FuC:\fpcupdeluxe\fpcsrc\rtl\win\
-FuC:\fpcupdeluxe\fpcsrc\rtl\win64\
-FuC:\fpcupdeluxe\fpcsrc\packages\*\src
-JiC:\fpcupdeluxe\fpcsrc\utils\pas2js\dist\rtl.js
Edit 2: Fixed Pas2JS errors. Turns out it uses a separate set of units and RTL.