WebAssembly test

JavaScript code
const asm = new WebAssembly.Instance(module); const mem = asm.exports.memory.buffer; const memoffset = asm.exports.getMemory(); const memlen = asm.exports.getMemorySize(); var data = new Uint32Array(mem, memoffset, memlen); print("mem len: " + data.length); for (var i = 0; i < data.length; i++) { data[i] = i + 1; print("set [" + i + "] = " + (i + 1)); } print("calc: " + asm.exports.calc());
Output on the browser
C code
#define SIZE 10 int mem[SIZE]; int* getMemory() { return mem; } int getMemorySize() { return SIZE; } int calc() { int sum = 0; for (int i = 0; i < SIZE; i++) { sum += mem[i]; } return sum; }
API: WebAssembly / wasm
APP: CC BY fukuno.jig.jp