Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
LLJS example output
if(!Math.imul) {
Math.imul = function(x, y) { return x * y; };
}
var MB = 1024 * 1024;
var SIZE = 256 * MB;
var STACK_SIZE = 2 * MB;
var HEAP_SIZE = SIZE - STACK_SIZE;
var buffer = new ArrayBuffer(SIZE);
var asm = (function (global, env, buffer) {
"use asm";
var stackSize = env.STACK_SIZE|0;
var heapSize = env.HEAP_SIZE|0;
var totalSize = env.TOTAL_SIZE|0;
var assertEqual = env.assertEqual;
var print = env.print;
var start = env.start;
var end = env.end;
var U1 = new global.Uint8Array(buffer);
var I1 = new global.Int8Array(buffer);
var U2 = new global.Uint16Array(buffer);
var I2 = new global.Int16Array(buffer);
var U4 = new global.Uint32Array(buffer);
var I4 = new global.Int32Array(buffer);
var F4 = new global.Float32Array(buffer);
var F8 = new global.Float64Array(buffer);
var acos = global.Math.acos;
var asin = global.Math.asin;
var atan = global.Math.atan;
var cos = global.Math.cos;
var sin = global.Math.sin;
var tan = global.Math.tan;
var ceil = global.Math.ceil;
var floor = global.Math.floor;
var exp = global.Math.exp;
var log = global.Math.log;
var sqrt = global.Math.sqrt;
var abs = global.Math.abs;
var atan2 = global.Math.atan2;
var pow = global.Math.pow;
var imul = global.Math.imul;
function Point$Point(thisPtr, x, y) {
thisPtr = thisPtr | 0;
x = +x;
y = +y;
var $SP = 0;
F8[(thisPtr) >> 3] = x;
F8[((thisPtr) + 8 | 0) >> 3] = y;
}
function length(p) {
p = p | 0;
var $SP = 0;
return +(+sqrt(+F8[(p) >> 3] * +F8[(p) >> 3] + +F8[((p) + 8 | 0) >> 3] * +F8[((p) + 8 | 0) >> 3]));
}
function main() {
var p = 0, l = 0.0, $SP = 0;
U4[1] = totalSize;
U4[0] = 4;
U4[1] = (U4[1] | 0) - 16;
$SP = U4[1] | 0;
(Point$Point(($SP), 1.2, 3.4), F8[($SP) >> 3]);
assertEqual(+F8[(($SP)) >> 3], 1.2);
assertEqual(+F8[((($SP)) + 8 | 0) >> 3], 3.4);
l = length(($SP));
assertEqual(+l, 3.605551275463989);
assertEqual(~~l, 3);
U4[1] = (U4[1] | 0) + 16;
return 0.0;
}
return { main: main };
})({ Uint8Array: Uint8Array,
Int8Array: Int8Array,
Uint16Array: Uint16Array,
Int16Array: Int16Array,
Uint32Array: Uint32Array,
Int32Array: Int32Array,
Float32Array: Float32Array,
Float64Array: Float64Array,
Math: Math },
{ HEAP_SIZE: HEAP_SIZE,
STACK_SIZE: STACK_SIZE,
TOTAL_SIZE: SIZE,
assertEqual: assertEqual,
print: _print,
start: start,
end: end },
buffer);
function assertEqual(val1, val2) {
var err = true;
var msg;
if(val1 | 0 !== val1) {
if(Math.abs(val1 - val2) < .00000001) {
err = false;
}
else {
msg = 'eps';
}
}
else if(val1 === val2) {
err = false;
}
if(err) {
throw new Error(val1 + ' does not equal ' + val2);
}
}
function _print(/* arg1, arg2, ..., argN */) {
var func = ((typeof console !== 'undefined' && console.log) || print);
func.apply(null, arguments);
}
var _time;
function start() {
_time = Date.now();
}
function end() {
return Date.now() - _time;
}
asm.main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment