diff options
Diffstat (limited to 'src/preamble.js')
-rw-r--r-- | src/preamble.js | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/preamble.js b/src/preamble.js index 0917f977..e24c2957 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -275,7 +275,7 @@ Module['printProfiling'] = printProfiling; // Runtime essentials //======================================== -var __THREW__ = false; // Used in checking for thrown exceptions. +var __THREW__ = 0; // Used in checking for thrown exceptions. var setjmpId = 1; // Used in setjmp/longjmp var setjmpLabels = {}; @@ -287,6 +287,7 @@ var undef = 0; var tempValue, tempInt, tempBigInt, tempInt2, tempBigInt2, tempPair, tempBigIntI, tempBigIntR, tempBigIntS, tempBigIntP, tempBigIntD; #if USE_TYPED_ARRAYS == 2 var tempI64, tempI64b; +var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9; #endif function abort(text) { @@ -577,9 +578,6 @@ Module['Array_stringify'] = Array_stringify; // Memory management -var FUNCTION_TABLE; // XXX: In theory the indexes here can be equal to pointers to stacked or malloced memory. Such comparisons should - // be false, but can turn out true. We should probably set the top bit to prevent such issues. - var PAGE_SIZE = 4096; function alignMemoryPage(x) { return ((x+4095)>>12)<<12; @@ -699,47 +697,47 @@ Module['HEAPF64'] = HEAPF64; #endif STACK_ROOT = STACKTOP = Runtime.alignMemory(1); -STACK_MAX = STACK_ROOT + TOTAL_STACK; +STACK_MAX = TOTAL_STACK; // we lose a little stack here, but TOTAL_STACK is nice and round so use that as the max #if USE_TYPED_ARRAYS == 2 -var tempDoublePtr = Runtime.alignMemory(STACK_MAX, 8); -var tempDoubleI8 = HEAP8.subarray(tempDoublePtr); -var tempDoubleI32 = HEAP32.subarray(tempDoublePtr >> 2); -var tempDoubleF32 = HEAPF32.subarray(tempDoublePtr >> 2); -var tempDoubleF64 = HEAPF64.subarray(tempDoublePtr >> 3); +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 - tempDoubleI8[0] = HEAP8[ptr]; - tempDoubleI8[1] = HEAP8[ptr+1]; - tempDoubleI8[2] = HEAP8[ptr+2]; - tempDoubleI8[3] = HEAP8[ptr+3]; + 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) { - tempDoubleI8[0] = HEAP8[ptr]; - tempDoubleI8[1] = HEAP8[ptr+1]; - tempDoubleI8[2] = HEAP8[ptr+2]; - tempDoubleI8[3] = HEAP8[ptr+3]; - tempDoubleI8[4] = HEAP8[ptr+4]; - tempDoubleI8[5] = HEAP8[ptr+5]; - tempDoubleI8[6] = HEAP8[ptr+6]; - tempDoubleI8[7] = HEAP8[ptr+7]; + 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]; } -STACK_MAX = tempDoublePtr + 8; #endif -STATICTOP = alignMemoryPage(STACK_MAX); - +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_STATIC); +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') { - func = FUNCTION_TABLE[func]; + if (callback.arg === undefined) { + Runtime.dynCall('v', func); + } else { + Runtime.dynCall('vi', func, [callback.arg]); + } + } else { + func(callback.arg === undefined ? null : callback.arg); } - func(callback.arg === undefined ? null : callback.arg); } } |