diff options
author | Alon Zakai <azakai@mozilla.com> | 2010-12-30 21:42:06 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2010-12-30 21:42:06 -0800 |
commit | ff4341e7d5bfb82cc711146ab80e31635e5865b7 (patch) | |
tree | e8c25ce0f8d7fe869e48531c4c277ea7f95db7c4 /src | |
parent | 47f29aed8aa7905c24562188d2d7e2861972ebed (diff) |
simple django-style substitution/macros
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 20 | ||||
-rw-r--r-- | src/parseTools.js | 2 | ||||
-rw-r--r-- | src/preamble.js | 17 |
3 files changed, 19 insertions, 20 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index ba6cc232..3669f87f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -110,9 +110,10 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria value = indexizeFunctions(value); var offset = calcFastOffset(ptr, pos, noNeedFirst); if (SAFE_HEAP) { - return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', "' + safeQuote(type) + '")'; + if (type !== 'null') type = '"' + safeQuote(type) + '"'; + return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', ' + type + ');'; } else { - return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + '] = ' + value }).join('; '); + return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + '] = ' + value }).join('; ') + ';'; } } @@ -964,6 +965,15 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria // Final combiner function finalCombiner(items) { + // Does simple 'macro' substitution, using Django-like syntax, + // {{{ code }}} will be replaced with |eval(code)|. + function processMacros(text) { + return text.replace(/{{{[^}]+}}}/g, function(str) { + str = str.substr(3, str.length-6); + return eval(str).toString(); + }); + } + var ret = []; if (!functionsOnly) { ret = ret.concat(items.filter(function(item) { return item.intertype == 'type' })); @@ -982,8 +992,10 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria var body = preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()) + ret + read('postamble.js'), CONSTANTS); var globalVars = items.filter(function(item) { return item.intertype == 'GlobalVariable' }).map(function(item) { return item.JS }).join('\n'); var globalVarsPostSets = items.filter(function(item) { return item.intertype == 'GlobalVariablePostSet' }).map(function(item) { return item.JS }).join('\n'); - return read('shell.js').replace('{{BODY}}', indentify(body, 2)) - .replace('{{GLOBAL_VARS}}', indentify(globalVars+'\n\n\n'+globalVarsPostSets, 4)); + return processMacros( + read('shell.js').replace('{{BODY}}', indentify(body, 2)) + .replace('{{GLOBAL_VARS}}', indentify(globalVars+'\n\n\n'+globalVarsPostSets, 4)) + ); } // Data diff --git a/src/parseTools.js b/src/parseTools.js index e9ca3e34..12b531ea 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -2,7 +2,7 @@ // specific to Emscripten (and hence not in utility.js). // Simple #if/else/endif preprocessing for a file. Checks if the -// ident checked is true in our global. Also replaces some constants +// ident checked is true in our global. Also replaces some constants. function preprocess(text, constants) { for (constant in constants) { text = text.replace(eval('/' + constant + '/g'), constants[constant]); diff --git a/src/preamble.js b/src/preamble.js index c743dd49..ed6f1d62 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -138,21 +138,8 @@ function Pointer_make(slab, pos, allocator) { if (typeof curr === 'function') { curr = Runtime.getFunctionIndex(curr); } -#if SAFE_HEAP - SAFE_HEAP_STORE(ret + i, curr, null); -#else -#if USE_TYPED_ARRAYS - // TODO: Check - also in non-typedarray case - for functions, and if so add |.__index__| - if (typeof curr === 'number' || typeof curr === 'boolean') { - IHEAP[ret + i] = curr; // TODO: optimize. Can easily detect floats, but 1.0 might look like an int... - FHEAP[ret + i] = curr; - } else { - HEAP[ret + i] = curr; - } -#else - HEAP[ret + i] = curr; -#endif -#endif + + {{{ makeSetValue(0, 'ret+i', 'curr', null, 'null') }}} } return ret; |