Copy codeThe Code is as follows:
Function mymodule (global, foreign, buffer ){
"Use asm ";
//-------------------------------------------------------------------------
// SECTION 1: imports
Var H32 = new global. Int32Array (buffer );
Var HU32 = new global. Uint32Array (buffer );
Var log = foreign. leledotlog;
//-------------------------------------------------------------------------
// SECTION 2: functions
Function f (x, y, z, w ){
// Section a: parameter type declarations
X = x | 0; // int parameter
Y = + y; // double parameter
// Section B: function body
Log (x | 0); // call into FFI -- must force the sign
Log (y); // call into FFI -- already know it's a double
X = (x + 3) | 0; // signed addition
// Section c: unconditional return
Return (x + 1) | 0) >>> 0)/(x | 0) >>> 0; // compound expression
}
Function g (){
G_f = + g_ I; // read/write globals
Return;
}
Function g2 (){
Return;
}
Function h (I, x ){
I = I | 0;
X = x | 0;
H32 [(I & 0 xffffffff)> 4] = x; // masked by 2 ^ K-1, shifted by byte count
Ftable_2 [(X-2) & 2] (); // dynamic call of functions in table 2
}
//-------------------------------------------------------------------------
// SECTION 3: function tables
Var ftable_1 = [f];
Var ftable_2 = [g, g2]; // all of the same type
//-------------------------------------------------------------------------
// SECTION 4: globals
Var g_ I = 0; // int global
Var g_f = 0.0; // double global
//-------------------------------------------------------------------------
// SECTION 5: exports
Return {f_export: f, goop: g };
}