aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-10-10 19:08:28 -0400
committerAlon Zakai <alonzakai@gmail.com>2013-10-10 19:08:28 -0400
commit894db65d7dd8d6bef9595b1e2e49f069b857c5b8 (patch)
tree96a18c11793279ac5e7bf143334ddb2a46142095
parent1c9032b9b8b4c32dbeca31691447ad574a75f815 (diff)
do not emit postSets for function indexing etc., bake them into the memory initializer
-rw-r--r--src/jsifier.js6
-rw-r--r--src/parseTools.js5
-rw-r--r--tests/test_core.py7
3 files changed, 16 insertions, 2 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 1219bbae..a126994b 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -234,8 +234,8 @@ function JSify(data, functionsOnly, givenFunctions) {
function globalVariableHandler(item) {
function needsPostSet(value) {
if (typeof value !== 'string') return false;
- return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW'
- || value.substr(0, 6) === 'GLOBAL';
+ // (' is ok, as it is something we can indexize later into a concrete int: ('{{ FI_ ...
+ return /^([(_][^']|CHECK_OVERFLOW|GLOBAL).*/.test(value);
}
item.intertype = 'GlobalVariableStub';
@@ -308,6 +308,8 @@ function JSify(data, functionsOnly, givenFunctions) {
JS: makeSetValue(makeGlobalUse(item.ident), i, value, structTypes[i], false, true) + ';' // ignore=true, since e.g. rtti and statics cause lots of safe_heap errors
});
constant[i] = '0';
+ } else {
+ if (typeof value === 'string') constant[i] = deParenCarefully(value);
}
});
diff --git a/src/parseTools.js b/src/parseTools.js
index 1f875584..0ea8bc8d 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -2574,6 +2574,11 @@ function deParen(text) {
return text;
}
+function deParenCarefully(text) {
+ if (text[0] === '(' && text.indexOf('(', 1) < 0 && text[text.length-1] === ')') return text.substr(1, text.length-2);
+ return text;
+}
+
function addVariable(ident, type, funcData) {
funcData = funcData || Framework.currItem.funcData;
assert(type);
diff --git a/tests/test_core.py b/tests/test_core.py
index 576cb8c7..66f9b8e4 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -8616,6 +8616,13 @@ void*:16
assert ' & 255]()' not in original, 'big function table does not exist'
assert ' & 255]()' in final, 'big function table exists'
+ assert 'asm1' in test_modes
+ if self.run_name == 'asm1':
+ generated = open('src.cpp.o.js').read()
+ main = generated[generated.find('function runPostSets'):]
+ main = main[:main.find('\n}')]
+ assert main.count('\n') == 7, 'must not emit too many postSets: %d' % main.count('\n')
+
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this