Skip to content

Instantly share code, notes, and snippets.

@meddulla
Forked from thatisuday/calc.asm.js
Created November 9, 2020 16:24
Show Gist options
  • Save meddulla/0d01531b7152e6dbedd5375b520ebb43 to your computer and use it in GitHub Desktop.
Save meddulla/0d01531b7152e6dbedd5375b520ebb43 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