Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Note: Some Emscripten settings will significantly limit the speed of the generated code.
- // Note: Some Emscripten settings may limit the speed of the generated code.
- try {
- this['Module'] = Module;
- } catch(e) {
- this['Module'] = Module = {};
- }
- // The environment setup code below is customized to use Module.
- // *** Environment setup code ***
- var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
- var ENVIRONMENT_IS_WEB = typeof window === 'object';
- var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
- var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
- if (ENVIRONMENT_IS_NODE) {
- // Expose functionality in the same simple way that the shells work
- // Note that we pollute the global namespace here, otherwise we break in node
- Module['print'] = function(x) {
- process['stdout'].write(x + '\n');
- };
- Module['printErr'] = function(x) {
- process['stderr'].write(x + '\n');
- };
- var nodeFS = require('fs');
- var nodePath = require('path');
- Module['read'] = function(filename) {
- filename = nodePath['normalize'](filename);
- var ret = nodeFS['readFileSync'](filename).toString();
- // The path is absolute if the normalized version is the same as the resolved.
- if (!ret && filename != nodePath['resolve'](filename)) {
- filename = path.join(__dirname, '..', 'src', filename);
- ret = nodeFS['readFileSync'](filename).toString();
- }
- return ret;
- };
- Module['load'] = function(f) {
- globalEval(read(f));
- };
- if (!Module['arguments']) {
- Module['arguments'] = process['argv'].slice(2);
- }
- }
- if (ENVIRONMENT_IS_SHELL) {
- Module['print'] = print;
- if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
- // Polyfill over SpiderMonkey/V8 differences
- if (typeof read != 'undefined') {
- Module['read'] = read;
- } else {
- Module['read'] = function(f) { snarf(f) };
- }
- if (!Module['arguments']) {
- if (typeof scriptArgs != 'undefined') {
- Module['arguments'] = scriptArgs;
- } else if (typeof arguments != 'undefined') {
- Module['arguments'] = arguments;
- }
- }
- }
- if (ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER) {
- if (!Module['print']) {
- Module['print'] = function(x) {
- console.log(x);
- };
- }
- if (!Module['printErr']) {
- Module['printErr'] = function(x) {
- console.log(x);
- };
- }
- }
- if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
- Module['read'] = function(url) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, false);
- xhr.send(null);
- return xhr.responseText;
- };
- if (!Module['arguments']) {
- if (typeof arguments != 'undefined') {
- Module['arguments'] = arguments;
- }
- }
- }
- if (ENVIRONMENT_IS_WORKER) {
- // We can do very little here...
- var TRY_USE_DUMP = false;
- if (!Module['print']) {
- Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
- dump(x);
- }) : (function(x) {
- // self.postMessage(x); // enable this if you want stdout to be sent as messages
- }));
- }
- Module['load'] = importScripts;
- }
- if (!ENVIRONMENT_IS_WORKER && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_SHELL) {
- // Unreachable because SHELL is dependant on the others
- throw 'Unknown runtime environment. Where are we?';
- }
- function globalEval(x) {
- eval.call(null, x);
- }
- if (!Module['load'] == 'undefined' && Module['read']) {
- Module['load'] = function(f) {
- globalEval(Module['read'](f));
- };
- }
- if (!Module['print']) {
- Module['print'] = function(){};
- }
- if (!Module['printErr']) {
- Module['printErr'] = Module['print'];
- }
- if (!Module['arguments']) {
- Module['arguments'] = [];
- }
- // *** Environment setup code ***
- // Closure helpers
- Module.print = Module['print'];
- Module.printErr = Module['printErr'];
- // Callbacks
- if (!Module['preRun']) Module['preRun'] = [];
- if (!Module['postRun']) Module['postRun'] = [];
- // === Auto-generated preamble library stuff ===
- //========================================
- // Runtime code shared with compiler
- //========================================
- var Runtime = {
- stackSave: function () {
- return STACKTOP;
- },
- stackRestore: function (stackTop) {
- STACKTOP = stackTop;
- },
- forceAlign: function (target, quantum) {
- quantum = quantum || 4;
- if (quantum == 1) return target;
- if (isNumber(target) && isNumber(quantum)) {
- return Math.ceil(target/quantum)*quantum;
- } else if (isNumber(quantum) && isPowerOfTwo(quantum)) {
- var logg = log2(quantum);
- return '((((' +target + ')+' + (quantum-1) + ')>>' + logg + ')<<' + logg + ')';
- }
- return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
- },
- isNumberType: function (type) {
- return type in Runtime.INT_TYPES || type in Runtime.FLOAT_TYPES;
- },
- isPointerType: function isPointerType(type) {
- return type[type.length-1] == '*';
- },
- isStructType: function isStructType(type) {
- if (isPointerType(type)) return false;
- if (/^\[\d+\ x\ (.*)\]/.test(type)) return true; // [15 x ?] blocks. Like structs
- if (/<?{ ?[^}]* ?}>?/.test(type)) return true; // { i32, i8 } etc. - anonymous struct types
- // See comment in isStructPointerType()
- return type[0] == '%';
- },
- INT_TYPES: {"i1":0,"i8":0,"i16":0,"i32":0,"i64":0},
- FLOAT_TYPES: {"float":0,"double":0},
- BITSHIFT64_SHL: 0,
- BITSHIFT64_ASHR: 1,
- BITSHIFT64_LSHR: 2,
- bitshift64: function (low, high, op, bits) {
- var ret;
- var ander = Math.pow(2, bits)-1;
- if (bits < 32) {
- switch (op) {
- case Runtime.BITSHIFT64_SHL:
- ret = [low << bits, (high << bits) | ((low&(ander << (32 - bits))) >>> (32 - bits))];
- break;
- case Runtime.BITSHIFT64_ASHR:
- ret = [(((low >>> bits ) | ((high&ander) << (32 - bits))) >> 0) >>> 0, (high >> bits) >>> 0];
- break;
- case Runtime.BITSHIFT64_LSHR:
- ret = [((low >>> bits) | ((high&ander) << (32 - bits))) >>> 0, high >>> bits];
- break;
- }
- } else if (bits == 32) {
- switch (op) {
- case Runtime.BITSHIFT64_SHL:
- ret = [0, low];
- break;
- case Runtime.BITSHIFT64_ASHR:
- ret = [high, (high|0) < 0 ? ander : 0];
- break;
- case Runtime.BITSHIFT64_LSHR:
- ret = [high, 0];
- break;
- }
- } else { // bits > 32
- switch (op) {
- case Runtime.BITSHIFT64_SHL:
- ret = [0, low << (bits - 32)];
- break;
- case Runtime.BITSHIFT64_ASHR:
- ret = [(high >> (bits - 32)) >>> 0, (high|0) < 0 ? ander : 0];
- break;
- case Runtime.BITSHIFT64_LSHR:
- ret = [high >>> (bits - 32) , 0];
- break;
- }
- }
- assert(ret);
- HEAP32[tempDoublePtr>>2] = ret[0]; // cannot use utility functions since we are in runtime itself
- HEAP32[tempDoublePtr+4>>2] = ret[1];
- },
- or64: function (x, y) {
- var l = (x | 0) | (y | 0);
- var h = (Math.round(x / 4294967296) | Math.round(y / 4294967296)) * 4294967296;
- return l + h;
- },
- and64: function (x, y) {
- var l = (x | 0) & (y | 0);
- var h = (Math.round(x / 4294967296) & Math.round(y / 4294967296)) * 4294967296;
- return l + h;
- },
- xor64: function (x, y) {
- var l = (x | 0) ^ (y | 0);
- var h = (Math.round(x / 4294967296) ^ Math.round(y / 4294967296)) * 4294967296;
- return l + h;
- },
- getNativeTypeSize: function (type, quantumSize) {
- if (Runtime.QUANTUM_SIZE == 1) return 1;
- var size = {
- '%i1': 1,
- '%i8': 1,
- '%i16': 2,
- '%i32': 4,
- '%i64': 8,
- "%float": 4,
- "%double": 8
- }['%'+type]; // add '%' since float and double confuse Closure compiler as keys, and also spidermonkey as a compiler will remove 's from '_i8' etc
- if (!size) {
- if (type.charAt(type.length-1) == '*') {
- size = Runtime.QUANTUM_SIZE; // A pointer
- } else if (type[0] == 'i') {
- var bits = parseInt(type.substr(1));
- assert(bits % 8 == 0);
- size = bits/8;
- }
- }
- return size;
- },
- getNativeFieldSize: function (type) {
- return Math.max(Runtime.getNativeTypeSize(type), Runtime.QUANTUM_SIZE);
- },
- dedup: function dedup(items, ident) {
- var seen = {};
- if (ident) {
- return items.filter(function(item) {
- if (seen[item[ident]]) return false;
- seen[item[ident]] = true;
- return true;
- });
- } else {
- return items.filter(function(item) {
- if (seen[item]) return false;
- seen[item] = true;
- return true;
- });
- }
- },
- set: function set() {
- var args = typeof arguments[0] === 'object' ? arguments[0] : arguments;
- var ret = {};
- for (var i = 0; i < args.length; i++) {
- ret[args[i]] = 0;
- }
- return ret;
- },
- calculateStructAlignment: function calculateStructAlignment(type) {
- type.flatSize = 0;
- type.alignSize = 0;
- var diffs = [];
- var prev = -1;
- type.flatIndexes = type.fields.map(function(field) {
- var size, alignSize;
- if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
- size = Runtime.getNativeTypeSize(field); // pack char; char; in structs, also char[X]s.
- alignSize = size;
- } else if (Runtime.isStructType(field)) {
- size = Types.types[field].flatSize;
- alignSize = Types.types[field].alignSize;
- } else {
- throw 'Unclear type in struct: ' + field + ', in ' + type.name_ + ' :: ' + dump(Types.types[type.name_]);
- }
- alignSize = type.packed ? 1 : Math.min(alignSize, Runtime.QUANTUM_SIZE);
- type.alignSize = Math.max(type.alignSize, alignSize);
- var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
- type.flatSize = curr + size;
- if (prev >= 0) {
- diffs.push(curr-prev);
- }
- prev = curr;
- return curr;
- });
- type.flatSize = Runtime.alignMemory(type.flatSize, type.alignSize);
- if (diffs.length == 0) {
- type.flatFactor = type.flatSize;
- } else if (Runtime.dedup(diffs).length == 1) {
- type.flatFactor = diffs[0];
- }
- type.needsFlattening = (type.flatFactor != 1);
- return type.flatIndexes;
- },
- generateStructInfo: function (struct, typeName, offset) {
- var type, alignment;
- if (typeName) {
- offset = offset || 0;
- type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName];
- if (!type) return null;
- if (type.fields.length != struct.length) {
- printErr('Number of named fields must match the type for ' + typeName + ': possibly duplicate struct names. Cannot return structInfo');
- return null;
- }
- alignment = type.flatIndexes;
- } else {
- var type = { fields: struct.map(function(item) { return item[0] }) };
- alignment = Runtime.calculateStructAlignment(type);
- }
- var ret = {
- __size__: type.flatSize
- };
- if (typeName) {
- struct.forEach(function(item, i) {
- if (typeof item === 'string') {
- ret[item] = alignment[i] + offset;
- } else {
- // embedded struct
- var key;
- for (var k in item) key = k;
- ret[key] = Runtime.generateStructInfo(item[key], type.fields[i], alignment[i]);
- }
- });
- } else {
- struct.forEach(function(item, i) {
- ret[item[1]] = alignment[i];
- });
- }
- return ret;
- },
- dynCall: function (sig, ptr, args) {
- if (args && args.length) {
- assert(args.length == sig.length-1);
- return FUNCTION_TABLE[ptr].apply(null, args);
- } else {
- assert(sig.length == 1);
- return FUNCTION_TABLE[ptr]();
- }
- },
- addFunction: function (func, sig) {
- assert(sig);
- var table = FUNCTION_TABLE; // TODO: support asm
- var ret = table.length;
- table.push(func);
- table.push(0);
- return ret;
- },
- warnOnce: function (text) {
- if (!Runtime.warnOnce.shown) Runtime.warnOnce.shown = {};
- if (!Runtime.warnOnce.shown[text]) {
- Runtime.warnOnce.shown[text] = 1;
- Module.printErr(text);
- }
- },
- funcWrappers: {},
- getFuncWrapper: function (func, sig) {
- assert(sig);
- if (!Runtime.funcWrappers[func]) {
- Runtime.funcWrappers[func] = function() {
- Runtime.dynCall(sig, func, arguments);
- };
- }
- return Runtime.funcWrappers[func];
- },
- UTF8Processor: function () {
- var buffer = [];
- var needed = 0;
- this.processCChar = function (code) {
- code = code & 0xff;
- if (needed) {
- buffer.push(code);
- needed--;
- }
- if (buffer.length == 0) {
- if (code < 128) return String.fromCharCode(code);
- buffer.push(code);
- if (code > 191 && code < 224) {
- needed = 1;
- } else {
- needed = 2;
- }
- return '';
- }
- if (needed > 0) return '';
- var c1 = buffer[0];
- var c2 = buffer[1];
- var c3 = buffer[2];
- var ret;
- if (c1 > 191 && c1 < 224) {
- ret = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
- } else {
- ret = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- }
- buffer.length = 0;
- return ret;
- }
- this.processJSString = function(string) {
- string = unescape(encodeURIComponent(string));
- var ret = [];
- for (var i = 0; i < string.length; i++) {
- ret.push(string.charCodeAt(i));
- }
- return ret;
- }
- },
- stackAlloc: function stackAlloc(size) { var ret = STACKTOP;STACKTOP = (STACKTOP + size)|0;STACKTOP = ((((STACKTOP)+3)>>2)<<2);assert(STACKTOP|0 < STACK_MAX|0); return ret; },
- staticAlloc: function staticAlloc(size) { var ret = STATICTOP;STATICTOP = (STATICTOP + size)|0;STATICTOP = ((((STATICTOP)+3)>>2)<<2); if (STATICTOP >= TOTAL_MEMORY) enlargeMemory();; return ret; },
- alignMemory: function alignMemory(size,quantum) { var ret = size = Math.ceil((size)/(quantum ? quantum : 4))*(quantum ? quantum : 4); return ret; },
- makeBigInt: function makeBigInt(low,high,unsigned) { var ret = (unsigned ? (((low)>>>0)+(((high)>>>0)*4294967296)) : (((low)>>>0)+(((high)|0)*4294967296))); return ret; },
- QUANTUM_SIZE: 4,
- __dummy__: 0
- }
- var CorrectionsMonitor = {
- MAX_ALLOWED: 0, // XXX
- corrections: 0,
- sigs: {},
- note: function(type, succeed, sig) {
- if (!succeed) {
- this.corrections++;
- if (this.corrections >= this.MAX_ALLOWED) abort('\n\nToo many corrections!');
- }
- },
- print: function() {
- }
- };
- //========================================
- // Runtime essentials
- //========================================
- var __THREW__ = 0; // Used in checking for thrown exceptions.
- var setjmpId = 1; // Used in setjmp/longjmp
- var setjmpLabels = {};
- var ABORT = false;
- var undef = 0;
- // tempInt is used for 32-bit signed values or smaller. tempBigInt is used
- // for 32-bit unsigned values or more than 32 bits. TODO: audit all uses of tempInt
- var tempValue, tempInt, tempBigInt, tempInt2, tempBigInt2, tempPair, tempBigIntI, tempBigIntR, tempBigIntS, tempBigIntP, tempBigIntD;
- var tempI64, tempI64b;
- var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9;
- function abort(text) {
- Module.print(text + ':\n' + (new Error).stack);
- ABORT = true;
- throw "Assertion: " + text;
- }
- function assert(condition, text) {
- if (!condition) {
- abort('Assertion failed: ' + text);
- }
- }
- var globalScope = this;
- // C calling interface. A convenient way to call C functions (in C files, or
- // defined with extern "C").
- //
- // Note: LLVM optimizations can inline and remove functions, after which you will not be
- // able to call them. Closure can also do so. To avoid that, add your function to
- // the exports using something like
- //
- // -s EXPORTED_FUNCTIONS='["_main", "_myfunc"]'
- //
- // @param ident The name of the C function (note that C++ functions will be name-mangled - use extern "C")
- // @param returnType The return type of the function, one of the JS types 'number', 'string' or 'array' (use 'number' for any C pointer, and
- // 'array' for JavaScript arrays and typed arrays).
- // @param argTypes An array of the types of arguments for the function (if there are no arguments, this can be ommitted). Types are as in returnType,
- // except that 'array' is not possible (there is no way for us to know the length of the array)
- // @param args An array of the arguments to the function, as native JS values (as in returnType)
- // Note that string arguments will be stored on the stack (the JS string will become a C string on the stack).
- // @return The return value, as a native JS value (as in returnType)
- function ccall(ident, returnType, argTypes, args) {
- return ccallFunc(getCFunc(ident), returnType, argTypes, args);
- }
- Module["ccall"] = ccall;
- // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
- function getCFunc(ident) {
- try {
- var func = eval('_' + ident);
- } catch(e) {
- try {
- func = globalScope['Module']['_' + ident]; // closure exported function
- } catch(e) {}
- }
- assert(func, 'Cannot call unknown function ' + ident + ' (perhaps LLVM optimizations or closure removed it?)');
- return func;
- }
- // Internal function that does a C call using a function, not an identifier
- function ccallFunc(func, returnType, argTypes, args) {
- var stack = 0;
- function toC(value, type) {
- if (type == 'string') {
- if (value === null || value === undefined || value === 0) return 0; // null string
- if (!stack) stack = Runtime.stackSave();
- var ret = Runtime.stackAlloc(value.length+1);
- writeStringToMemory(value, ret);
- return ret;
- } else if (type == 'array') {
- if (!stack) stack = Runtime.stackSave();
- var ret = Runtime.stackAlloc(value.length);
- writeArrayToMemory(value, ret);
- return ret;
- }
- return value;
- }
- function fromC(value, type) {
- if (type == 'string') {
- return Pointer_stringify(value);
- }
- assert(type != 'array');
- return value;
- }
- var i = 0;
- var cArgs = args ? args.map(function(arg) {
- return toC(arg, argTypes[i++]);
- }) : [];
- var ret = fromC(func.apply(null, cArgs), returnType);
- if (stack) Runtime.stackRestore(stack);
- return ret;
- }
- // Returns a native JS wrapper for a C function. This is similar to ccall, but
- // returns a function you can call repeatedly in a normal way. For example:
- //
- // var my_function = cwrap('my_c_function', 'number', ['number', 'number']);
- // alert(my_function(5, 22));
- // alert(my_function(99, 12));
- //
- function cwrap(ident, returnType, argTypes) {
- var func = getCFunc(ident);
- return function() {
- return ccallFunc(func, returnType, argTypes, Array.prototype.slice.call(arguments));
- }
- }
- Module["cwrap"] = cwrap;
- // Sets a value in memory in a dynamic way at run-time. Uses the
- // type data. This is the same as makeSetValue, except that
- // makeSetValue is done at compile-time and generates the needed
- // code then, whereas this function picks the right code at
- // run-time.
- // Note that setValue and getValue only do *aligned* writes and reads!
- // Note that ccall uses JS types as for defining types, while setValue and
- // getValue need LLVM types ('i8', 'i32') - this is a lower-level operation
- function setValue(ptr, value, type, noSafe) {
- type = type || 'i8';
- if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
- switch(type) {
- case 'i1': HEAP8[(ptr)]=value; break;
- case 'i8': HEAP8[(ptr)]=value; break;
- case 'i16': HEAP16[((ptr)>>1)]=value; break;
- case 'i32': HEAP32[((ptr)>>2)]=value; break;
- case 'i64': (tempI64 = [value>>>0,Math.min(Math.floor((value)/4294967296), 4294967295)>>>0],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break;
- case 'float': HEAPF32[((ptr)>>2)]=value; break;
- case 'double': (HEAPF64[(tempDoublePtr)>>3]=value,HEAP32[((ptr)>>2)]=HEAP32[((tempDoublePtr)>>2)],HEAP32[(((ptr)+(4))>>2)]=HEAP32[(((tempDoublePtr)+(4))>>2)]); break;
- default: abort('invalid type for setValue: ' + type);
- }
- }
- Module['setValue'] = setValue;
- // Parallel to setValue.
- function getValue(ptr, type, noSafe) {
- type = type || 'i8';
- if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
- switch(type) {
- case 'i1': return HEAP8[(ptr)];
- case 'i8': return HEAP8[(ptr)];
- case 'i16': return HEAP16[((ptr)>>1)];
- case 'i32': return HEAP32[((ptr)>>2)];
- case 'i64': return HEAP32[((ptr)>>2)];
- case 'float': return HEAPF32[((ptr)>>2)];
- case 'double': return (HEAP32[((tempDoublePtr)>>2)]=HEAP32[((ptr)>>2)],HEAP32[(((tempDoublePtr)+(4))>>2)]=HEAP32[(((ptr)+(4))>>2)],HEAPF64[(tempDoublePtr)>>3]);
- default: abort('invalid type for setValue: ' + type);
- }
- return null;
- }
- Module['getValue'] = getValue;
- var ALLOC_NORMAL = 0; // Tries to use _malloc()
- var ALLOC_STACK = 1; // Lives for the duration of the current function call
- var ALLOC_STATIC = 2; // Cannot be freed
- var ALLOC_NONE = 3; // Do not allocate
- Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
- Module['ALLOC_STACK'] = ALLOC_STACK;
- Module['ALLOC_STATIC'] = ALLOC_STATIC;
- Module['ALLOC_NONE'] = ALLOC_NONE;
- // Simple unoptimized memset - necessary during startup
- var _memset = function(ptr, value, num) {
- var stop = ptr + num;
- while (ptr < stop) {
- HEAP8[(ptr++)]=value;
- }
- }
- // allocate(): This is for internal use. You can use it yourself as well, but the interface
- // is a little tricky (see docs right below). The reason is that it is optimized
- // for multiple syntaxes to save space in generated code. So you should
- // normally not use allocate(), and instead allocate memory using _malloc(),
- // initialize it with setValue(), and so forth.
- // @slab: An array of data, or a number. If a number, then the size of the block to allocate,
- // in *bytes* (note that this is sometimes confusing: the next parameter does not
- // affect this!)
- // @types: Either an array of types, one for each byte (or 0 if no type at that position),
- // or a single type which is used for the entire block. This only matters if there
- // is initial data - if @slab is a number, then this does not matter at all and is
- // ignored.
- // @allocator: How to allocate memory, see ALLOC_*
- function allocate(slab, types, allocator, ptr) {
- var zeroinit, size;
- if (typeof slab === 'number') {
- zeroinit = true;
- size = slab;
- } else {
- zeroinit = false;
- size = slab.length;
- }
- var singleType = typeof types === 'string' ? types : null;
- var ret;
- if (allocator == ALLOC_NONE) {
- ret = ptr;
- } else {
- ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length));
- }
- if (zeroinit) {
- _memset(ret, 0, size);
- return ret;
- }
- if (singleType === 'i8') {
- HEAPU8.set(new Uint8Array(slab), ret);
- return ret;
- }
- var i = 0, type;
- while (i < size) {
- var curr = slab[i];
- if (typeof curr === 'function') {
- curr = Runtime.getFunctionIndex(curr);
- }
- type = singleType || types[i];
- if (type === 0) {
- i++;
- continue;
- }
- assert(type, 'Must know what type to store in allocate!');
- if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
- setValue(ret+i, curr, type);
- i += Runtime.getNativeTypeSize(type);
- }
- return ret;
- }
- Module['allocate'] = allocate;
- function Pointer_stringify(ptr, /* optional */ length) {
- var utf8 = new Runtime.UTF8Processor();
- var nullTerminated = typeof(length) == "undefined";
- var ret = "";
- var i = 0;
- var t;
- while (1) {
- assert(i < TOTAL_MEMORY);
- t = HEAPU8[((ptr)+(i))];
- if (nullTerminated && t == 0) break;
- ret += utf8.processCChar(t);
- i += 1;
- if (!nullTerminated && i == length) break;
- }
- return ret;
- }
- Module['Pointer_stringify'] = Pointer_stringify;
- function Array_stringify(array) {
- var ret = "";
- for (var i = 0; i < array.length; i++) {
- ret += String.fromCharCode(array[i]);
- }
- return ret;
- }
- Module['Array_stringify'] = Array_stringify;
- // Memory management
- var PAGE_SIZE = 4096;
- function alignMemoryPage(x) {
- return ((x+4095)>>12)<<12;
- }
- var HEAP;
- var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
- var STACK_ROOT, STACKTOP, STACK_MAX;
- var STATICTOP;
- function enlargeMemory() {
- abort('Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.');
- }
- var TOTAL_STACK = Module['TOTAL_STACK'] || 5242880;
- var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;
- var FAST_MEMORY = Module['FAST_MEMORY'] || 2097152;
- // Initialize the runtime's memory
- // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
- assert(!!Int32Array && !!Float64Array && !!(new Int32Array(1)['subarray']) && !!(new Int32Array(1)['set']),
- 'Cannot fallback to non-typed array case: Code is too specialized');
- var buffer = new ArrayBuffer(TOTAL_MEMORY);
- HEAP8 = new Int8Array(buffer);
- HEAP16 = new Int16Array(buffer);
- HEAP32 = new Int32Array(buffer);
- HEAPU8 = new Uint8Array(buffer);
- HEAPU16 = new Uint16Array(buffer);
- HEAPU32 = new Uint32Array(buffer);
- HEAPF32 = new Float32Array(buffer);
- HEAPF64 = new Float64Array(buffer);
- // Endianness check (note: assumes compiler arch was little-endian)
- HEAP32[0] = 255;
- assert(HEAPU8[0] === 255 && HEAPU8[3] === 0, 'Typed arrays 2 must be run on a little-endian system');
- Module['HEAP'] = HEAP;
- Module['HEAP8'] = HEAP8;
- Module['HEAP16'] = HEAP16;
- Module['HEAP32'] = HEAP32;
- Module['HEAPU8'] = HEAPU8;
- Module['HEAPU16'] = HEAPU16;
- Module['HEAPU32'] = HEAPU32;
- Module['HEAPF32'] = HEAPF32;
- Module['HEAPF64'] = HEAPF64;
- STACK_ROOT = STACKTOP = Runtime.alignMemory(1);
- STACK_MAX = TOTAL_STACK; // we lose a little stack here, but TOTAL_STACK is nice and round so use that as the max
- var tempDoublePtr = Runtime.alignMemory(allocate(12, 'i8', ALLOC_STACK), 8);
- assert(tempDoublePtr % 8 == 0);
- function copyTempFloat(ptr) { // functions, because inlining this code is increases code size too much
- HEAP8[tempDoublePtr] = HEAP8[ptr];
- HEAP8[tempDoublePtr+1] = HEAP8[ptr+1];
- HEAP8[tempDoublePtr+2] = HEAP8[ptr+2];
- HEAP8[tempDoublePtr+3] = HEAP8[ptr+3];
- }
- function copyTempDouble(ptr) {
- HEAP8[tempDoublePtr] = HEAP8[ptr];
- HEAP8[tempDoublePtr+1] = HEAP8[ptr+1];
- HEAP8[tempDoublePtr+2] = HEAP8[ptr+2];
- HEAP8[tempDoublePtr+3] = HEAP8[ptr+3];
- HEAP8[tempDoublePtr+4] = HEAP8[ptr+4];
- HEAP8[tempDoublePtr+5] = HEAP8[ptr+5];
- HEAP8[tempDoublePtr+6] = HEAP8[ptr+6];
- HEAP8[tempDoublePtr+7] = HEAP8[ptr+7];
- }
- STATICTOP = STACK_MAX;
- assert(STATICTOP < TOTAL_MEMORY); // Stack must fit in TOTAL_MEMORY; allocations from here on may enlarge TOTAL_MEMORY
- var nullString = allocate(intArrayFromString('(null)'), 'i8', ALLOC_STACK);
- function callRuntimeCallbacks(callbacks) {
- while(callbacks.length > 0) {
- var callback = callbacks.shift();
- var func = callback.func;
- if (typeof func === 'number') {
- if (callback.arg === undefined) {
- Runtime.dynCall('v', func);
- } else {
- Runtime.dynCall('vi', func, [callback.arg]);
- }
- } else {
- func(callback.arg === undefined ? null : callback.arg);
- }
- }
- }
- var __ATINIT__ = []; // functions called during startup
- var __ATMAIN__ = []; // functions called when main() is to be run
- var __ATEXIT__ = []; // functions called during shutdown
- function initRuntime() {
- callRuntimeCallbacks(__ATINIT__);
- }
- function preMain() {
- callRuntimeCallbacks(__ATMAIN__);
- }
- function exitRuntime() {
- callRuntimeCallbacks(__ATEXIT__);
- // Print summary of correction activity
- CorrectionsMonitor.print();
- }
- // Tools
- // This processes a JS string into a C-line array of numbers, 0-terminated.
- // For LLVM-originating strings, see parser.js:parseLLVMString function
- function intArrayFromString(stringy, dontAddNull, length /* optional */) {
- var ret = (new Runtime.UTF8Processor()).processJSString(stringy);
- if (length) {
- ret.length = length;
- }
- if (!dontAddNull) {
- ret.push(0);
- }
- return ret;
- }
- Module['intArrayFromString'] = intArrayFromString;
- function intArrayToString(array) {
- var ret = [];
- for (var i = 0; i < array.length; i++) {
- var chr = array[i];
- if (chr > 0xFF) {
- assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
- chr &= 0xFF;
- }
- ret.push(String.fromCharCode(chr));
- }
- return ret.join('');
- }
- Module['intArrayToString'] = intArrayToString;
- // Write a Javascript array to somewhere in the heap
- function writeStringToMemory(string, buffer, dontAddNull) {
- var array = intArrayFromString(string, dontAddNull);
- var i = 0;
- while (i < array.length) {
- var chr = array[i];
- HEAP8[((buffer)+(i))]=chr
- i = i + 1;
- }
- }
- Module['writeStringToMemory'] = writeStringToMemory;
- function writeArrayToMemory(array, buffer) {
- for (var i = 0; i < array.length; i++) {
- HEAP8[((buffer)+(i))]=array[i];
- }
- }
- Module['writeArrayToMemory'] = writeArrayToMemory;
- function unSign(value, bits, ignore, sig) {
- if (value >= 0) {
- return value;
- }
- return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts
- : Math.pow(2, bits) + value;
- // TODO: clean up previous line
- }
- function reSign(value, bits, ignore, sig) {
- if (value <= 0) {
- return value;
- }
- var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32
- : Math.pow(2, bits-1);
- if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that
- // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors
- // TODO: In i64 mode 1, resign the two parts separately and safely
- value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
- }
- return value;
- }
- // A counter of dependencies for calling run(). If we need to
- // do asynchronous work before running, increment this and
- // decrement it. Incrementing must happen in a place like
- // PRE_RUN_ADDITIONS (used by emcc to add file preloading).
- // Note that you can add dependencies in preRun, even though
- // it happens right before run - run will be postponed until
- // the dependencies are met.
- var runDependencies = 0;
- var runDependencyTracking = {};
- var calledRun = false;
- var runDependencyWatcher = null;
- function addRunDependency(id) {
- runDependencies++;
- if (Module['monitorRunDependencies']) {
- Module['monitorRunDependencies'](runDependencies);
- }
- if (id) {
- assert(!runDependencyTracking[id]);
- runDependencyTracking[id] = 1;
- if (runDependencyWatcher === null && typeof setInterval !== 'undefined') {
- // Check for missing dependencies every few seconds
- runDependencyWatcher = setInterval(function() {
- var shown = false;
- for (var dep in runDependencyTracking) {
- if (!shown) {
- shown = true;
- Module.printErr('still waiting on run dependencies:');
- }
- Module.printErr('dependency: ' + dep);
- }
- if (shown) {
- Module.printErr('(end of list)');
- }
- }, 6000);
- }
- } else {
- Module.printErr('warning: run dependency added without ID');
- }
- }
- Module['addRunDependency'] = addRunDependency;
- function removeRunDependency(id) {
- runDependencies--;
- if (Module['monitorRunDependencies']) {
- Module['monitorRunDependencies'](runDependencies);
- }
- if (id) {
- assert(runDependencyTracking[id]);
- delete runDependencyTracking[id];
- } else {
- Module.printErr('warning: run dependency removed without ID');
- }
- if (runDependencies == 0) {
- if (runDependencyWatcher !== null) {
- clearInterval(runDependencyWatcher);
- runDependencyWatcher = null;
- }
- // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
- if (!calledRun && shouldRunNow) run();
- }
- }
- Module['removeRunDependency'] = removeRunDependency;
- Module["preloadedImages"] = {}; // maps url to image data
- Module["preloadedAudios"] = {}; // maps url to audio data
- // === Body ===
- var _sqrt=Math.sqrt;
- function _memcpy(dest, src, num) {
- dest = dest|0; src = src|0; num = num|0;
- var ret = 0;
- ret = dest|0;
- if ((dest&3) == (src&3)) {
- while (dest & 3) {
- if ((num|0) == 0) return ret|0;
- HEAP8[(dest)]=HEAP8[(src)];
- dest = (dest+1)|0;
- src = (src+1)|0;
- num = (num-1)|0;
- }
- while ((num|0) >= 4) {
- HEAP32[((dest)>>2)]=HEAP32[((src)>>2)];
- dest = (dest+4)|0;
- src = (src+4)|0;
- num = (num-4)|0;
- }
- }
- while ((num|0) > 0) {
- HEAP8[(dest)]=HEAP8[(src)];
- dest = (dest+1)|0;
- src = (src+1)|0;
- num = (num-1)|0;
- }
- return ret|0;
- }
- function _memset(ptr, value, num) {
- ptr = ptr|0; value = value|0; num = num|0;
- var stop = 0, value4 = 0, stop4 = 0, unaligned = 0;
- stop = (ptr + num)|0;
- if (num|0 >= 20) {
- // This is unaligned, but quite large, so work hard to get to aligned settings
- unaligned = ptr & 3;
- value4 = value | (value << 8) | (value << 16) | (value << 24);
- stop4 = stop & ~3;
- if (unaligned) {
- unaligned = (ptr + 4 - unaligned)|0;
- while ((ptr|0) < (unaligned|0)) { // no need to check for stop, since we have large num
- HEAP8[(ptr)]=value;
- ptr = (ptr+1)|0;
- }
- }
- while ((ptr|0) < (stop4|0)) {
- HEAP32[((ptr)>>2)]=value4;
- ptr = (ptr+4)|0;
- }
- }
- while ((ptr|0) < (stop|0)) {
- HEAP8[(ptr)]=value;
- ptr = (ptr+1)|0;
- }
- }
- function _malloc(bytes) {
- /* Over-allocate to make sure it is byte-aligned by 8.
- * This will leak memory, but this is only the dummy
- * implementation (replaced by dlmalloc normally) so
- * not an issue.
- */
- var ptr = Runtime.staticAlloc(bytes + 8);
- return (ptr+8) & 0xFFFFFFF8;
- }
- function _free(){}
- var Browser={mainLoop:{scheduler:null,shouldPause:false,paused:false,queue:[],pause:function () {
- Browser.mainLoop.shouldPause = true;
- },resume:function () {
- if (Browser.mainLoop.paused) {
- Browser.mainLoop.paused = false;
- Browser.mainLoop.scheduler();
- }
- Browser.mainLoop.shouldPause = false;
- },updateStatus:function () {
- if (Module['setStatus']) {
- var message = Module['statusMessage'] || 'Please wait...';
- var remaining = Browser.mainLoop.remainingBlockers;
- var expected = Browser.mainLoop.expectedBlockers;
- if (remaining) {
- if (remaining < expected) {
- Module['setStatus'](message + ' (' + (expected - remaining) + '/' + expected + ')');
- } else {
- Module['setStatus'](message);
- }
- } else {
- Module['setStatus']('');
- }
- }
- }},pointerLock:false,moduleContextCreatedCallbacks:[],workers:[],ensureObjects:function () {
- if (Browser.ensured) return;
- Browser.ensured = true;
- try {
- new Blob();
- Browser.hasBlobConstructor = true;
- } catch(e) {
- Browser.hasBlobConstructor = false;
- console.log("warning: no blob constructor, cannot create blobs with mimetypes");
- }
- Browser.BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : (!Browser.hasBlobConstructor ? console.log("warning: no BlobBuilder") : null));
- Browser.URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : console.log("warning: cannot create object URLs");
- // Support for plugins that can process preloaded files. You can add more of these to
- // your app by creating and appending to Module.preloadPlugins.
- //
- // Each plugin is asked if it can handle a file based on the file's name. If it can,
- // it is given the file's raw data. When it is done, it calls a callback with the file's
- // (possibly modified) data. For example, a plugin might decompress a file, or it
- // might create some side data structure for use later (like an Image element, etc.).
- function getMimetype(name) {
- return {
- 'jpg': 'image/jpeg',
- 'png': 'image/png',
- 'bmp': 'image/bmp',
- 'ogg': 'audio/ogg',
- 'wav': 'audio/wav',
- 'mp3': 'audio/mpeg'
- }[name.substr(-3)];
- return ret;
- }
- if (!Module["preloadPlugins"]) Module["preloadPlugins"] = [];
- var imagePlugin = {};
- imagePlugin['canHandle'] = function(name) {
- return name.substr(-4) in { '.jpg': 1, '.png': 1, '.bmp': 1 };
- };
- imagePlugin['handle'] = function(byteArray, name, onload, onerror) {
- var b = null;
- if (Browser.hasBlobConstructor) {
- try {
- b = new Blob([byteArray], { type: getMimetype(name) });
- } catch(e) {
- Runtime.warnOnce('Blob constructor present but fails: ' + e + '; falling back to blob builder');
- }
- }
- if (!b) {
- var bb = new Browser.BlobBuilder();
- bb.append((new Uint8Array(byteArray)).buffer); // we need to pass a buffer, and must copy the array to get the right data range
- b = bb.getBlob();
- }
- var url = Browser.URLObject.createObjectURL(b);
- assert(typeof url == 'string', 'createObjectURL must return a url as a string');
- var img = new Image();
- img.onload = function() {
- assert(img.complete, 'Image ' + name + ' could not be decoded');
- var canvas = document.createElement('canvas');
- canvas.width = img.width;
- canvas.height = img.height;
- var ctx = canvas.getContext('2d');
- ctx.drawImage(img, 0, 0);
- Module["preloadedImages"][name] = canvas;
- Browser.URLObject.revokeObjectURL(url);
- if (onload) onload(byteArray);
- };
- img.onerror = function(event) {
- console.log('Image ' + url + ' could not be decoded');
- if (onerror) onerror();
- };
- img.src = url;
- };
- Module['preloadPlugins'].push(imagePlugin);
- var audioPlugin = {};
- audioPlugin['canHandle'] = function(name) {
- return name.substr(-4) in { '.ogg': 1, '.wav': 1, '.mp3': 1 };
- };
- audioPlugin['handle'] = function(byteArray, name, onload, onerror) {
- var done = false;
- function finish(audio) {
- if (done) return;
- done = true;
- Module["preloadedAudios"][name] = audio;
- if (onload) onload(byteArray);
- }
- function fail() {
- if (done) return;
- done = true;
- Module["preloadedAudios"][name] = new Audio(); // empty shim
- if (onerror) onerror();
- }
- if (Browser.hasBlobConstructor) {
- try {
- var b = new Blob([byteArray], { type: getMimetype(name) });
- } catch(e) {
- return fail();
- }
- var url = Browser.URLObject.createObjectURL(b); // XXX we never revoke this!
- assert(typeof url == 'string', 'createObjectURL must return a url as a string');
- var audio = new Audio();
- audio.addEventListener('canplaythrough', function() { finish(audio) }, false); // use addEventListener due to chromium bug 124926
- audio.onerror = function(event) {
- if (done) return;
- console.log('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
- function encode64(data) {
- var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- var PAD = '=';
- var ret = '';
- var leftchar = 0;
- var leftbits = 0;
- for (var i = 0; i < data.length; i++) {
- leftchar = (leftchar << 8) | data[i];
- leftbits += 8;
- while (leftbits >= 6) {
- var curr = (leftchar >> (leftbits-6)) & 0x3f;
- leftbits -= 6;
- ret += BASE[curr];
- }
- }
- if (leftbits == 2) {
- ret += BASE[(leftchar&3) << 4];
- ret += PAD + PAD;
- } else if (leftbits == 4) {
- ret += BASE[(leftchar&0xf) << 2];
- ret += PAD;
- }
- return ret;
- }
- audio.src = 'data:audio/x-' + name.substr(-3) + ';base64,' + encode64(byteArray);
- finish(audio); // we don't wait for confirmation this worked - but it's worth trying
- };
- audio.src = url;
- // workaround for chrome bug 124926 - we do not always get oncanplaythrough or onerror
- setTimeout(function() {
- finish(audio); // try to use it even though it is not necessarily ready to play
- }, 10000);
- } else {
- return fail();
- }
- };
- Module['preloadPlugins'].push(audioPlugin);
- },createContext:function (canvas, useWebGL, setInModule) {
- try {
- var ctx = canvas.getContext(useWebGL ? 'experimental-webgl' : '2d');
- if (!ctx) throw ':(';
- } catch (e) {
- Module.print('Could not create canvas - ' + e);
- return null;
- }
- if (useWebGL) {
- // Set the background of the WebGL canvas to black
- canvas.style.backgroundColor = "black";
- // Warn on context loss
- canvas.addEventListener('webglcontextlost', function(event) {
- alert('WebGL context lost. You will need to reload the page.');
- }, false);
- }
- if (setInModule) {
- Module.ctx = ctx;
- Module.useWebGL = useWebGL;
- Browser.moduleContextCreatedCallbacks.forEach(function(callback) { callback() });
- }
- return ctx;
- },requestFullScreen:function () {
- var canvas = Module['canvas'];
- function fullScreenChange() {
- var isFullScreen = false;
- if ((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
- document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
- document['fullScreenElement'] || document['fullscreenElement']) === canvas) {
- canvas.requestPointerLock = canvas['requestPointerLock'] ||
- canvas['mozRequestPointerLock'] ||
- canvas['webkitRequestPointerLock'];
- canvas.requestPointerLock();
- isFullScreen = true;
- }
- if (Module['onFullScreen']) Module['onFullScreen'](isFullScreen);
- }
- document.addEventListener('fullscreenchange', fullScreenChange, false);
- document.addEventListener('mozfullscreenchange', fullScreenChange, false);
- document.addEventListener('webkitfullscreenchange', fullScreenChange, false);
- function pointerLockChange() {
- Browser.pointerLock = document['pointerLockElement'] === canvas ||
- document['mozPointerLockElement'] === canvas ||
- document['webkitPointerLockElement'] === canvas;
- }
- document.addEventListener('pointerlockchange', pointerLockChange, false);
- document.addEventListener('mozpointerlockchange', pointerLockChange, false);
- document.addEventListener('webkitpointerlockchange', pointerLockChange, false);
- canvas.requestFullScreen = canvas['requestFullScreen'] ||
- canvas['mozRequestFullScreen'] ||
- (canvas['webkitRequestFullScreen'] ? function() { canvas['webkitRequestFullScreen'](Element['ALLOW_KEYBOARD_INPUT']) } : null);
- canvas.requestFullScreen();
- },requestAnimationFrame:function (func) {
- if (!window.requestAnimationFrame) {
- window.requestAnimationFrame = window['requestAnimationFrame'] ||
- window['mozRequestAnimationFrame'] ||
- window['webkitRequestAnimationFrame'] ||
- window['msRequestAnimationFrame'] ||
- window['oRequestAnimationFrame'] ||
- window['setTimeout'];
- }
- window.requestAnimationFrame(func);
- },getMovementX:function (event) {
- return event['movementX'] ||
- event['mozMovementX'] ||
- event['webkitMovementX'] ||
- 0;
- },getMovementY:function (event) {
- return event['movementY'] ||
- event['mozMovementY'] ||
- event['webkitMovementY'] ||
- 0;
- },xhrLoad:function (url, onload, onerror) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.responseType = 'arraybuffer';
- xhr.onload = function() {
- if (xhr.status == 200) {
- onload(xhr.response);
- } else {
- onerror();
- }
- };
- xhr.onerror = onerror;
- xhr.send(null);
- },asyncLoad:function (url, onload, onerror, noRunDep) {
- Browser.xhrLoad(url, function(arrayBuffer) {
- assert(arrayBuffer, 'Loading data file "' + url + '" failed (no arrayBuffer).');
- onload(new Uint8Array(arrayBuffer));
- if (!noRunDep) removeRunDependency('al ' + url);
- }, function(event) {
- if (onerror) {
- onerror();
- } else {
- throw 'Loading data file "' + url + '" failed.';
- }
- });
- if (!noRunDep) addRunDependency('al ' + url);
- },resizeListeners:[],updateResizeListeners:function () {
- var canvas = Module['canvas'];
- Browser.resizeListeners.forEach(function(listener) {
- listener(canvas.width, canvas.height);
- });
- },setCanvasSize:function (width, height, noUpdates) {
- var canvas = Module['canvas'];
- canvas.width = width;
- canvas.height = height;
- if (!noUpdates) Browser.updateResizeListeners();
- }};
- Module["requestFullScreen"] = function() { Browser.requestFullScreen() };
- Module["requestAnimationFrame"] = function(func) { Browser.requestAnimationFrame(func) };
- Module["pauseMainLoop"] = function() { Browser.mainLoop.pause() };
- Module["resumeMainLoop"] = function() { Browser.mainLoop.resume() };
- var FUNCTION_TABLE = [0, 0];
- function _int_sqrt($x) {
- var label = 0;
- var $1;
- $1=$x;
- var $2=$1;
- var $3=(($2)|0);
- var $4=Math.sqrt($3);
- var $5=(($4)&-1);
- return $5;
- }
- Module["_int_sqrt"] = _int_sqrt;
- // Warning: printing of i64 values may be slightly rounded! No deep i64 math used, so precise i64 code not included
- var i64Math = null;
- // === Auto-generated postamble setup entry stuff ===
- Module.callMain = function callMain(args) {
- var argc = args.length+1;
- function pad() {
- for (var i = 0; i < 4-1; i++) {
- argv.push(0);
- }
- }
- var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_STATIC) ];
- pad();
- for (var i = 0; i < argc-1; i = i + 1) {
- argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_STATIC));
- pad();
- }
- argv.push(0);
- argv = allocate(argv, 'i32', ALLOC_STATIC);
- var ret;
- ret = Module['_main'](argc, argv, 0);
- return ret;
- }
- function run(args) {
- args = args || Module['arguments'];
- if (runDependencies > 0) {
- Module.printErr('run() called, but dependencies remain, so not running');
- return 0;
- }
- if (Module['preRun']) {
- if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
- var toRun = Module['preRun'];
- Module['preRun'] = [];
- for (var i = toRun.length-1; i >= 0; i--) {
- toRun[i]();
- }
- if (runDependencies > 0) {
- // a preRun added a dependency, run will be called later
- return 0;
- }
- }
- function doRun() {
- var ret = 0;
- calledRun = true;
- if (Module['_main']) {
- preMain();
- ret = Module.callMain(args);
- if (!Module['noExitRuntime']) {
- exitRuntime();
- }
- }
- if (Module['postRun']) {
- if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
- while (Module['postRun'].length > 0) {
- Module['postRun'].pop()();
- }
- }
- return ret;
- }
- if (Module['setStatus']) {
- Module['setStatus']('Running...');
- setTimeout(function() {
- setTimeout(function() {
- Module['setStatus']('');
- }, 1);
- doRun();
- }, 1);
- return 0;
- } else {
- return doRun();
- }
- }
- Module['run'] = Module.run = run;
- // {{PRE_RUN_ADDITIONS}}
- (function() {
- function assert(check, msg) {
- if (!check) throw msg + new Error().stack;
- }
- Module['FS_createDataFile']('/', 'gizmo.webm', [26, 69, 223, ...]), true, true); //<-- cut for size reasons
- })();
- if (Module['preInit']) {
- if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
- while (Module['preInit'].length > 0) {
- Module['preInit'].pop()();
- }
- }
- initRuntime();
- var shouldRunNow = true;
- if (Module['noInitialRun']) {
- shouldRunNow = false;
- }
- if (shouldRunNow) {
- var ret = run();
- }
- // {{POST_RUN_ADDITIONS}}
- // {{MODULE_ADDITIONS}}
- // EMSCRIPTEN_GENERATED_FUNCTIONS: ["_int_sqrt"]
Add Comment
Please, Sign In to add comment