aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-13 16:03:40 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-13 16:03:40 -0800
commit595191902fc7ac0d64b1a65182189873f7b47dfe (patch)
treee2f437e99b1df72712e0dee6114ada5077a6b463 /src
parent0cef1b4432d180e747c88a75680d9ece78bcc50a (diff)
treat externals as globals in asm
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js14
-rw-r--r--src/parseTools.js3
2 files changed, 14 insertions, 3 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 7568c088..9c3109ad 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -277,7 +277,7 @@ function JSify(data, functionsOnly, givenFunctions) {
item.JS = makeGlobalDef(item.ident);
}
- if (item.external) {
+ if (item.external && !ASM_JS) { // ASM_JS considers externs to be globals
// Import external global variables from the library if available.
var shortident = item.ident.slice(1);
if (LibraryManager.library[shortident] &&
@@ -307,7 +307,17 @@ function JSify(data, functionsOnly, givenFunctions) {
index = makeGlobalUse(item.ident); // index !== null indicates we are indexing this
allocator = 'ALLOC_NONE';
}
- constant = parseConst(item.value, item.type, item.ident);
+ if (item.external) {
+ assert(ASM_JS);
+ if (Runtime.isNumberType(item.type) || isPointerType(item.type)) {
+ constant = zeros(Runtime.getNativeFieldSize(item.type));
+ } else {
+ constant = makeEmptyStruct(item.type);
+ }
+ constant = JSON.stringify(constant);
+ } else {
+ constant = parseConst(item.value, item.type, item.ident);
+ }
if (typeof constant === 'string' && constant[0] != '[') {
constant = [constant]; // A single item. We may need a postset for it.
}
diff --git a/src/parseTools.js b/src/parseTools.js
index 8bd8b796..e8aeee1e 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -405,7 +405,8 @@ function isIndexableGlobal(ident) {
if (!(ident in Variables.globals)) return false;
if (ident in UNINDEXABLE_GLOBALS) return false;
var data = Variables.globals[ident];
- return !data.alias && !data.external;
+ // in asm.js, externals are just globals
+ return !data.alias && (ASM_JS || !data.external);
}
function makeGlobalDef(ident) {