aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-07-15 19:35:27 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-07-15 19:35:40 -0700
commit414f1dc84930595fa804023435267762e4f66be2 (patch)
tree2b8f6c3040bb5be129489353f4c4e94872639995 /src
parent51505880de541576c79ece8b93e73690290c6c5e (diff)
option to provide type info at run time
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js4
-rw-r--r--src/modules.js19
-rw-r--r--src/settings.js5
3 files changed, 28 insertions, 0 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 2babaa05..dfd1f08d 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -826,6 +826,10 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
var preFile = BUILD_AS_SHARED_LIB ? 'preamble_sharedlib.js' : 'preamble.js';
var pre = processMacros(preprocess(read(preFile).replace('{{RUNTIME}}', getRuntime()), CONSTANTS));
print(pre);
+ if (RUNTIME_TYPE_INFO) {
+ Types.cleanForRuntime();
+ print('Runtime.typeInfo = ' + JSON.stringify(Types.types));
+ }
generated.forEach(function(item) { print(indentify(item.JS || '', 2)); });
print(Functions.generateIndexing());
diff --git a/src/modules.js b/src/modules.js
index 0b00107c..f1f5f487 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -119,6 +119,25 @@ var Types = {
this.types = temp;
},
+ // Remove all data not needed during runtime (like line numbers, JS, etc.)
+ cleanForRuntime: function() {
+ values(this.types).forEach(function(type) {
+ delete type.intertype;
+ delete type.name_;
+ delete type.lineNum;
+ delete type.lines;
+ delete type.needsFlattening;
+ delete type.JS;
+ });
+ keys(this.types).forEach(function(longer) {
+ var shorter = longer.replace('%struct.', '').replace('%class.');
+ if (shorter === longer) return;
+ if (shorter in this.types) return;
+ this.types[shorter] = this.types[longer];
+ delete this.types[longer];
+ }, this);
+ },
+
needAnalysis: {} // Types noticed during parsing, that need analysis
};
diff --git a/src/settings.js b/src/settings.js
index 544cc7c2..226c30b2 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -116,6 +116,11 @@ SHOW_LABELS = 0; // Show labels in the generated code
BUILD_AS_SHARED_LIB = 0; // Whether to build the code as a shared library, which
// must be loaded dynamically using dlopen().
+RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run time. This
+ // increases the size of the generated script, but allows you
+ // to more easily perform operations from handwritten JS on
+ // objects with structures etc.
+
// Compiler debugging options
DEBUG_TAGS_SHOWING = [];
// Some useful items: