diff options
author | kripken <alonzakai@gmail.com> | 2011-06-25 19:57:46 -0700 |
---|---|---|
committer | kripken <alonzakai@gmail.com> | 2011-06-25 19:57:46 -0700 |
commit | 196f9949ba69351a403017de49e3c8cd16879dd7 (patch) | |
tree | d0c0d4f70c24b8ee9c6468ba50dcca2d4c2d445f /src/jsifier.js | |
parent | 5595ad6270c335ec353d25f0a7ef2ab2319ae8c0 (diff) | |
parent | 0575efbfafda86bbc921b086167aefc59252ecde (diff) |
Merge pull request #32 from max99x/master
Basic dynamic loading support
Diffstat (limited to 'src/jsifier.js')
-rw-r--r-- | src/jsifier.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index d3a197b6..a0c6ec72 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, }); } } @@ -196,7 +200,10 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { processItem: function(item) { var ret = [item]; var shortident = item.ident.substr(1); - if (shortident in Library) { + if (BUILD_AS_SHARED_LIB) { + // Shared libraries reuse the runtime of their parents. + item.JS = ''; + } else if (Library.hasOwnProperty(shortident)) { function addFromLibrary(ident) { if (ident in addedLibraryItems) return ''; // Don't replace implemented functions with library ones (which can happen when we add dependencies). @@ -764,14 +771,17 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { // postamble // global_vars - var shellParts = read('shell.js').split('{{BODY}}'); + var shellFile = BUILD_AS_SHARED_LIB ? 'shell_sharedlib.js' : 'shell.js'; + var shellParts = read(shellFile).split('{{BODY}}'); print(shellParts[0]); - var pre = processMacros(preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()), CONSTANTS)); + var preFile = BUILD_AS_SHARED_LIB ? 'preamble_sharedlib.js' : 'preamble.js'; + var pre = processMacros(preprocess(read(preFile).replace('{{RUNTIME}}', getRuntime()), CONSTANTS)); print(pre); generated.forEach(function(item) { print(indentify(item.JS || '', 2)); }); print(Functions.generateIndexing()); - var postParts = processMacros(preprocess(read('postamble.js'), CONSTANTS)).split('{{GLOBAL_VARS}}'); + var postFile = BUILD_AS_SHARED_LIB ? 'postamble_sharedlib.js' : 'postamble.js'; + var postParts = processMacros(preprocess(read(postFile), CONSTANTS)).split('{{GLOBAL_VARS}}'); print(postParts[0]); itemsDict.GlobalVariable.forEach(function(item) { print(indentify(item.JS, 4)); }); itemsDict.GlobalVariablePostSet.forEach(function(item) { print(indentify(item.JS, 4)); }); |