Skip to content

Instantly share code, notes, and snippets.

@thatisuday
Created January 11, 2020 10:22
Show Gist options
  • Save thatisuday/3f9fc710fc29c5022ef0254de021c862 to your computer and use it in GitHub Desktop.
Save thatisuday/3f9fc710fc29c5022ef0254de021c862 to your computer and use it in GitHub Desktop.
A simple asm.js module
function Calc(stdlib, foreign, heap) {
"use asm";
function add(a, b) {
a = a|0;
b = b|0;
return (a + b)|0;
}
return {
add: add
};
}
var stdlib = null;
var foreign = null;
var heap = new ArrayBuffer(1000); // 1kb
// create module instance
var calc = Calc( stdlib, foreign, heap );
// call `add` function
var result = calc.add( 1, 2 );
console.log( result );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment