aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-13 14:43:40 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-13 14:43:40 -0800
commit2e55061621e16964e244906c3236797408aee119 (patch)
tree676342deb4e9562880527556e8dcccd6ee0c637a /src
parentc4978b6c248bc076850743df2ba6b9a6d9af24bb (diff)
emit numeric constants for global variables, using our knowledge of the fixed value of GLOBAL_BASE
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js7
-rw-r--r--src/parseTools.js3
2 files changed, 5 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 5cea1dfa..7568c088 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1353,12 +1353,11 @@ function JSify(data, functionsOnly, givenFunctions) {
if (phase == 'pre' && !Variables.generatedGlobalBase) {
Variables.generatedGlobalBase = true;
if (Variables.nextIndexedOffset > 0) {
- // Variables have been calculated, get to base generation before we print them
- print('var GLOBAL_BASE = STATICTOP; assert(GLOBAL_BASE == STACK_MAX); \n');
+ // Variables have been calculated, get to base stuff before we print them
+ // GLOBAL_BASE is statically known to be equal to STACK_MAX and to TOTAL_STACK, assert on this
+ print('assert(STATICTOP == STACK_MAX); assert(STACK_MAX == TOTAL_STACK);\n');
print('STATICTOP += ' + Variables.nextIndexedOffset + ';\n');
print('assert(STATICTOP < TOTAL_MEMORY);\n');
- } else {
- print('var GLOBAL_BASE = 0;\n');
}
}
var generated = itemsDict.function.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.GlobalVariable).concat(itemsDict.GlobalVariablePostSet);
diff --git a/src/parseTools.js b/src/parseTools.js
index 1a7746e7..8bd8b796 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -414,7 +414,8 @@ function makeGlobalDef(ident) {
}
function makeGlobalUse(ident) {
- if (!NAMED_GLOBALS && isIndexableGlobal(ident)) return '(' + getFastValue('GLOBAL_BASE', '+', Variables.indexedGlobals[ident]) + ')';
+ // We assert on TOTAL_STACK being equal to GLOBAL_BASE
+ if (!NAMED_GLOBALS && isIndexableGlobal(ident)) return (TOTAL_STACK + Variables.indexedGlobals[ident]).toString();
return ident;
}