diff options
author | max99x <max99x@gmail.com> | 2011-06-25 10:27:49 +0300 |
---|---|---|
committer | max99x <max99x@gmail.com> | 2011-06-25 10:27:49 +0300 |
commit | 2f3bd046bb52234771dce5c689141626370e26ce (patch) | |
tree | 8c6297a73e97d0473359480aade22a6207f0ed37 | |
parent | c9b968a4467fc1c004da69dc2f0000728fbf108e (diff) |
Added support for exporting (non-function) global variables.
-rw-r--r-- | src/compiler.js | 1 | ||||
-rw-r--r-- | src/jsifier.js | 6 | ||||
-rw-r--r-- | src/settings.js | 4 |
3 files changed, 10 insertions, 1 deletions
diff --git a/src/compiler.js b/src/compiler.js index e5e8a755..4fe68e88 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -42,6 +42,7 @@ if (SAFE_HEAP >= 2) { } EXPORTED_FUNCTIONS = set(EXPORTED_FUNCTIONS); +EXPORTED_GLOBALS = set(EXPORTED_GLOBALS); // Settings sanity checks diff --git a/src/jsifier.js b/src/jsifier.js index 2344b21f..71797daa 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -178,9 +178,13 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { } constant = makePointer(constant, null, 'ALLOC_STATIC', item.type); + var js = item.ident + '=' + constant + ';'; + if (item.ident in EXPORTED_GLOBALS) { + js += '\nModule["' + item.ident + '"] = ' + item.ident + ';'; + } return ret.concat({ intertype: 'GlobalVariable', - JS: item.ident + '=' + constant + ';', + JS: js, }); } } diff --git a/src/settings.js b/src/settings.js index f2dd9065..f3ed4d06 100644 --- a/src/settings.js +++ b/src/settings.js @@ -101,6 +101,10 @@ AUTO_OPTIMIZE = 0; // When run with the CHECK_* options, will not fail on errors EXPORTED_FUNCTIONS = ['_main']; // Functions that are explicitly exported, so they are guaranteed to // be accessible outside of the generated code. +EXPORTED_GLOBALS = []; // Global non-function variables that are explicitly + // exported, so they are guaranteed to be + // accessible outside of the generated code. + SHOW_LABELS = 0; // Show labels in the generated code // Compiler debugging options |