Launching WASM on the SimpleOne platform

Using WebAssembly modules can significantly enhance system capabilities.

I propose an example of potential usage: a big number calculator with a limit of only 10,000 digits.

The mathematical module was written in Rust and compiled into a WebAssembly module. To load the module into memory, it was converted to base64 format and directly embedded into the client-side script.

I specifically implemented it not as a widget but as a client-side script for use in forms and UI actions, though it would be straightforward to package it as a widget as well.

PS. One thing that didn’t work: I couldn’t run the module as a server-side script.

PPS. The attached archive also includes the original Rust source code. Please don’t be too harsh on it—the goal wasn’t to achieve 100% perfect accuracy, but it matches the results of a standard calculator for smaller numbers.

big-math-wasm.zip (68.0 KB)

4 Likes

Here is an example of server-side execution:

var wasmCode = new Uint8Array(
[0,97,115,109,1,0,0,0,1,134,128,128,128,0,1,96,1,127,1,127,3,130,128,128,128,0,1,0,4,132,128,128,128,0,1,112,0,0,5,131,128,128,128,0,1,0,1,6,129,128,128,128,0,0,7,144,128,128,128,0,2,6,109,101,109,111,114,121,2,0,3,102,105,98,0,0,10,203,128,128,128,0,1,197,128,128,128,0,1,1,127,2,64,32,0,65,1,106,34,1,65,3,79,13,0,32,1,65,2,116,65,12,106,40,2,0,15,11,2,64,32,0,65,1,72,13,0,32,0,65,127,106,16,0,32,0,65,126,106,16,0,106,15,11,32,0,65,2,106,16,0,32,1,16,0,107,11,11,146,128,128,128,0,1,0,65,12,11,12,1,0,0,0,0,0,0,0,1,0,0,0]);
var wasmModule = new WebAssembly.Module(wasmCode);
var wasmInstance = new WebAssembly.Instance(wasmModule, []);
print(wasmInstance.exports.fib(10)); //55
2 Likes