aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-05 17:57:54 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-05 17:57:54 -0800
commit0591fabb67954257cfa3a024b78f46a392fd4a31 (patch)
treef987a75683a7fd3ec726ab3182ff84872d14bbd8 /src
parentb2c5374402ae4e952c652772e9907a8f1c0efec9 (diff)
support for external variables in runtime linking
Diffstat (limited to 'src')
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js9
-rw-r--r--src/settings.js5
3 files changed, 8 insertions, 8 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 4d85b8a5..19eb658e 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -488,6 +488,7 @@ function intertyper(data, sidePass, baseLineNums) {
} else {
// variable
var ident = item.tokens[0].text;
+ var private_ = findTokenText(item, 'private') >= 0;
cleanOutTokens(LLVM.GLOBAL_MODIFIERS, item.tokens, [2, 3]);
var external = false;
if (item.tokens[2].text === 'external') {
@@ -500,6 +501,7 @@ function intertyper(data, sidePass, baseLineNums) {
ident: toNiceIdent(ident),
type: item.tokens[2].text,
external: external,
+ private_: private_,
lineNum: item.lineNum
};
Types.needAnalysis[ret.type] = 0;
diff --git a/src/jsifier.js b/src/jsifier.js
index f4e0ef50..a2ca03eb 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -321,10 +321,10 @@ function JSify(data, functionsOnly, givenFunctions) {
if (item.ident in EXPORTED_GLOBALS) {
js += '\nModule["' + item.ident + '"] = ' + item.ident + ';';
}
- // TODO: Support exporting BUILD_AS_SHARED_LIB == 2 globals. The problem now is that they override the main file's globals.
- //if (BUILD_AS_SHARED_LIB == 2) {
- // js += 'if (globalScope) globalScope["' + item.ident + '"] = ' + item.ident + ';'; // XXX: assert not overriding
- //}
+ if (BUILD_AS_SHARED_LIB == 2 && !item.private_) {
+ // TODO: make the assert conditional on ASSERTIONS
+ js += 'if (globalScope) { assert(!globalScope["' + item.ident + '"]); globalScope["' + item.ident + '"] = ' + item.ident + ' }';
+ }
return ret.concat({
intertype: 'GlobalVariable',
JS: js,
@@ -620,6 +620,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
if (BUILD_AS_SHARED_LIB == 2) {
+ // TODO: make the assert conditional on ASSERTIONS
func.JS += 'if (globalScope) { assert(!globalScope["' + func.ident + '"]); globalScope["' + func.ident + '"] = ' + func.ident + ' }';
}
diff --git a/src/settings.js b/src/settings.js
index 5aa647b2..0964d4bb 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -179,10 +179,7 @@ var BUILD_AS_SHARED_LIB = 0; // Whether to build the code as a shared library, w
// 1 means this is a normal shared lib.
// 2 means this is a shared lib that will be linked at runtime,
// which means it will insert its functions into
- // the global namespace. See STATIC_LIBS_TO_LOAD. Note
- // that only functions are exported, not globals, since
- // in a naive implementation they can easily override main's
- // symbols (for example, the global strings, _str1 etc.).
+ // the global namespace. See STATIC_LIBS_TO_LOAD.
var RUNTIME_LINKED_LIBS = []; // If this is a main file (BUILD_AS_SHARED_LIB == 0), then
// we will link these at runtime. They must have been built with
// BUILD_AS_SHARED_LIB == 2.