diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/intertyper.js | 1 | ||||
-rw-r--r-- | src/jsifier.js | 8 | ||||
-rw-r--r-- | src/library.js | 4 | ||||
-rw-r--r-- | src/library_gl.js | 5 | ||||
-rw-r--r-- | src/parseTools.js | 22 | ||||
-rw-r--r-- | src/preamble.js | 2 |
6 files changed, 36 insertions, 6 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index 7db1a2fe..1d18c3cf 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -919,6 +919,7 @@ function intertyper(data, sidePass, baseLineNums) { processItem: function(item) { return [{ intertype: 'resume', + ident: toNiceIdent(item.tokens[2].text), lineNum: item.lineNum }]; } diff --git a/src/jsifier.js b/src/jsifier.js index aaa827bb..4192cd3f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -633,7 +633,7 @@ function JSify(data, functionsOnly, givenFunctions) { } // otherwise, should have been set before! if (func.setjmpTable) { var setjmpTable = {}; - ret += indent + 'var setjmped = false;'; // set to true if we setjmp in this invocation + ret += indent + 'var mySetjmpIds = {};\n'; ret += indent + 'var setjmpTable = {'; func.setjmpTable.forEach(function(triple) { // original label, label we created for right after the setjmp, variable setjmp result goes into ret += '"' + getLabelId(triple[0]) + '": ' + 'function(value) { label = ' + getLabelId(triple[1]) + '; ' + triple[2] + ' = value },'; @@ -652,7 +652,7 @@ function JSify(data, functionsOnly, givenFunctions) { }).join('\n'); ret += '\n' + indent + ' default: assert(0, "bad label: " + label);\n' + indent + '}'; if (func.setjmpTable) { - ret += ' } catch(e) { if (!setjmped) throw(e); if (!e.longjmp) throw(e); setjmpTable[e.label](e.value) }'; + ret += ' } catch(e) { if (!e.longjmp || !(e.id in mySetjmpIds)) throw(e); setjmpTable[setjmpLabels[e.id]](e.value) }'; } } else { ret += (SHOW_LABELS ? indent + '/* ' + block.entries[0] + ' */' : '') + '\n' + getLabelLines(block.labels[0], indent); @@ -1049,8 +1049,10 @@ function JSify(data, functionsOnly, givenFunctions) { return ret + ';'; }); makeFuncLineActor('resume', function(item) { + // If there is no current exception, set this one as it (during a resume, the current exception can be wiped out) return (EXCEPTION_DEBUG ? 'Module.print("Resuming exception");' : '') + - 'throw ' + makeGetValue('_llvm_eh_exception.buf', '0', 'void*') + ';'; + 'if (' + makeGetValue('_llvm_eh_exception.buf', 0, 'void*') + ' == 0) { ' + makeSetValue('_llvm_eh_exception.buf', 0, item.ident + '.f0', 'void*') + ' } ' + + 'throw ' + item.ident + '.f0;'; }); makeFuncLineActor('invoke', function(item) { // Wrapping in a function lets us easily return values if we are diff --git a/src/library.js b/src/library.js index 5a8a9ae7..1bdd840d 100644 --- a/src/library.js +++ b/src/library.js @@ -5940,11 +5940,11 @@ LibraryManager.library = { setjmp__inline: function(env) { // Save the label - return '(setjmped = true, ' + makeSetValue(env, '0', 'label', 'i32') + ', 0)'; + return '(tempInt = setjmpId++, mySetjmpIds[tempInt] = 1, setjmpLabels[tempInt] = label,' + makeSetValue(env, '0', 'tempInt', 'i32') + ', 0)'; }, longjmp: function(env, value) { - throw { longjmp: true, label: {{{ makeGetValue('env', '0', 'i32') }}}, value: value || 1 }; + throw { longjmp: true, id: {{{ makeGetValue('env', '0', 'i32') }}}, value: value || 1 }; }, // ========================================================================== diff --git a/src/library_gl.js b/src/library_gl.js index b4098813..0f28a6a0 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -2099,6 +2099,11 @@ var LibraryGL = { }, glColor4f: function(r, g, b, a) { + r = Math.max(Math.min(r, 1), 0); + g = Math.max(Math.min(g, 1), 0); + b = Math.max(Math.min(b, 1), 0); + a = Math.max(Math.min(a, 1), 0); + // TODO: make ub the default, not f, save a few mathops if (GL.immediate.mode) { var start = GL.immediate.vertexCounter << 2; diff --git a/src/parseTools.js b/src/parseTools.js index 4a76a9a2..b2093da3 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1328,7 +1328,27 @@ function makePointer(slab, pos, allocator, type, ptr) { types = de[0]; } } - return 'allocate(' + slab + ', ' + JSON.stringify(types) + (allocator ? ', ' + allocator : '') + (allocator == 'ALLOC_NONE' ? ', ' + ptr : '') + ')'; + // JS engines sometimes say array initializers are too large. Work around that by chunking and calling concat to combine at runtime + var chunkSize = 10240; + function chunkify(array) { + // break very large slabs into parts + var ret = ''; + var index = 0; + while (index < array.length) { + ret = (ret ? ret + '.concat(' : '') + '[' + array.slice(index, index + chunkSize).map(JSON.stringify) + ']' + (ret ? ')' : ''); + index += chunkSize; + } + return ret; + } + if (typeof slab == 'string' && evaled && evaled.length > chunkSize) { + slab = chunkify(evaled); + } + if (typeof types != 'string' && types.length > chunkSize) { + types = chunkify(types); + } else { + types = JSON.stringify(types); + } + return 'allocate(' + slab + ', ' + types + (allocator ? ', ' + allocator : '') + (allocator == 'ALLOC_NONE' ? ', ' + ptr : '') + ')'; } function makeGetSlabs(ptr, type, allowMultiple, unsigned) { diff --git a/src/preamble.js b/src/preamble.js index 9342bf2b..0917f977 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -276,6 +276,8 @@ Module['printProfiling'] = printProfiling; //======================================== var __THREW__ = false; // Used in checking for thrown exceptions. +var setjmpId = 1; // Used in setjmp/longjmp +var setjmpLabels = {}; var ABORT = false; |