aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-19 14:32:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-19 14:32:14 -0800
commit7654dfe43471b752c80f6cb2976ace95d60a1319 (patch)
treea5b59933fe6495f708e329683ed24dc8c28485eb
parentcaf16eda45a7abc0397fa3bf4044bda16b36a606 (diff)
support 0x... numbers in +X to X.0 correction for asm
-rw-r--r--tools/js-optimizer.js24
-rw-r--r--tools/test-js-optimizer-asm-last-output.js4
-rw-r--r--tools/test-js-optimizer-asm-last.js4
3 files changed, 24 insertions, 8 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 8cd357cd..c779b4e6 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -2154,13 +2154,26 @@ function prepDotZero(ast) {
traverse(ast, function(node, type) {
if (type == 'unary-prefix' && node[1] == '+') {
if (node[2][0] == 'num') {
- return ['call', ['name', 'DOT$ZERO'], [['num', node[2][1]]]];
+ return ['call', ['name', 'DOT$ZERO'], [node[2]]];
} else if (node[2][0] == 'unary-prefix' && node[2][1] == '-' && node[2][2][0] == 'num') {
- return ['call', ['name', 'DOT$ZERO'], [['num', -node[2][2][1]]]];
+ node[2][2][1] = -node[2][2][1];
+ return ['call', ['name', 'DOT$ZERO'], [node[2][2]]];
}
}
});
}
+function fixDotZero(js) {
+ return js.replace(/DOT\$ZERO\(((0x)?[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\)/g, function(m, num) {
+ if (num.substr(0, 2) == '0x') {
+ if (num[2] == '-') num = '-0x' + num.substr(3); // uglify generates 0x-8000 for some reason
+ return eval(num) + '.0';
+ }
+ if (num.indexOf('.') >= 0) return num;
+ var e = num.indexOf('e');
+ if (e < 0) return num + '.0';
+ return num.substr(0, e) + '.0' + num.substr(e);
+ });
+}
// Passes table
@@ -2204,12 +2217,7 @@ if (asm && last) {
}
var js = astToSrc(ast, compress), old;
if (asm && last) {
- js = js.replace(/DOT\$ZERO\(([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\)/g, function(m, num) {
- if (num.indexOf('.') >= 0) return num;
- var e = num.indexOf('e');
- if (e < 0) return num + '.0';
- return num.substr(0, e) + '.0' + num.substr(e);
- });
+ js = fixDotZero(js);
}
// remove unneeded newlines+spaces, and print
diff --git a/tools/test-js-optimizer-asm-last-output.js b/tools/test-js-optimizer-asm-last-output.js
index 5a87f3c4..405cd929 100644
--- a/tools/test-js-optimizer-asm-last-output.js
+++ b/tools/test-js-optimizer-asm-last-output.js
@@ -22,6 +22,10 @@ function finall(x) {
a = -44.9;
a = -1278.0e3;
a = -12.0e10;
+ a = 9223372036854776000.0;
+ a = -9223372036854776000.0;
+ a = -9223372036854776000.0;
+ a = -0x8000000000000000;
return 12.0e10;
}
diff --git a/tools/test-js-optimizer-asm-last.js b/tools/test-js-optimizer-asm-last.js
index 2b025d28..794e90c0 100644
--- a/tools/test-js-optimizer-asm-last.js
+++ b/tools/test-js-optimizer-asm-last.js
@@ -22,6 +22,10 @@ function finall(x) {
a = +-44.9;
a = +-12.78e5;
a = +-12e10;
+ a = +0x8000000000000000;
+ a = +-0x8000000000000000;
+ a = -+0x8000000000000000;
+ a = -0x8000000000000000;
return +12e10;
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["finall"]