aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-05 17:16:27 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-05 17:16:27 -0800
commitb2c5374402ae4e952c652772e9907a8f1c0efec9 (patch)
treed13c468bc4b60e25d3b5fa02ae085dcdbcba7cce
parent9b375268703182c08c3f64433d3f0cb7a17880bc (diff)
initial work on annotating the generated code for closure compiler
-rw-r--r--src/jsifier.js18
-rw-r--r--src/settings.js3
2 files changed, 19 insertions, 2 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index feebbe5a..f4e0ef50 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -483,7 +483,18 @@ function JSify(data, functionsOnly, givenFunctions) {
if (IGNORED_FUNCTIONS.indexOf(func.ident) >= 0) return null;
- func.JS = '\nfunction ' + func.ident + '(' + func.paramIdents.join(', ') + ') {\n';
+ func.JS = '\n';
+
+ if (CLOSURE_ANNOTATIONS) {
+ func.JS += '/**\n';
+ func.paramIdents.forEach(function(param) {
+ func.JS += ' * @param {number} ' + param + '\n';
+ });
+ func.JS += ' * @return {number}\n'
+ func.JS += ' */\n';
+ }
+
+ func.JS += 'function ' + func.ident + '(' + func.paramIdents.join(', ') + ') {\n';
if (PROFILE) {
func.JS += ' if (PROFILING) { '
@@ -515,6 +526,7 @@ function JSify(data, functionsOnly, givenFunctions) {
if (LABEL_DEBUG) func.JS += " print(INDENT + ' Entering: " + func.ident + "'); INDENT += ' ';\n";
if (true) { // TODO: optimize away when not needed
+ if (CLOSURE_ANNOTATIONS) func.JS += '/** @type {number} */';
func.JS += ' var __label__;\n';
}
if (func.needsLastLabel) {
@@ -659,7 +671,9 @@ function JSify(data, functionsOnly, givenFunctions) {
});
substrate.addActor('AssignReintegrator', makeReintegrator(function(item, child) {
// 'var', since this is SSA - first assignment is the only assignment, and where it is defined
- item.JS = (item.overrideSSA ? '' : 'var ') + toNiceIdent(item.ident);
+ item.JS = '';
+ if (CLOSURE_ANNOTATIONS) item.JS += '/** @type {number} */ ';
+ item.JS += (item.overrideSSA ? '' : 'var ') + toNiceIdent(item.ident);
var type = item.value.type;
var value = parseNumerical(item.value.JS);
diff --git a/src/settings.js b/src/settings.js
index b3442c01..5aa647b2 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -66,6 +66,9 @@ var EMULATE_UNALIGNED_ACCESSES = 1; // If set, the compiler will 'emulate' loads
// need for this option.)
// Currently this only works for integers, not doubles and floats.
+var CLOSURE_ANNOTATIONS = 0; // If set, the generated code will be annotated for the closure
+ // compiler. This potentially lets closure optimize the code better.
+
var SKIP_STACK_IN_SMALL = 1; // When enabled, does not push/pop the stack at all in
// functions that have no basic stack usage. But, they
// may allocate stack later, and in a loop, this can be