Created
January 14, 2022 22:55
-
-
Save DanielRapp/f798e3e0f21d640f4e8fe3dce8c5acc0 to your computer and use it in GitHub Desktop.
minimal wasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script type="module"> | |
const res = await fetch('main.wasm'); | |
const buffer = await res.arrayBuffer(); | |
const compiled = await WebAssembly.compile(buffer); | |
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 }); | |
const prog = new WebAssembly.Instance(compiled, {env: { memory }}); | |
const wasm_func = prog.exports.double; | |
console.log( wasm_func(4) ); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// emcc main.c -s WASM=1 -s SIDE_MODULE=1 -O1 -o main.wasm | |
int double(int x) { | |
return 2 * x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment