diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-11-03 16:07:11 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-11-03 16:07:11 -0700 |
commit | d0712e1e913ff078bd32979cffc8e21fb098767c (patch) | |
tree | 63b6666c9387829b297115a1c00e3773bdc067ce /src | |
parent | a2449f950efe0fb00dc5732d9a82f5baa4187865 (diff) |
refactor getFastValue
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | src/parseTools.js | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index d8ed589e..23d9274a 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -784,7 +784,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { case VAR_NATIVIZED: { return value; // We have the actual value here } - case VAR_EMULATED: return makeGetValue(value, null, item.type, 0, item.unsigned); + case VAR_EMULATED: return makeGetValue(value, 0, item.type, 0, item.unsigned); default: throw "unknown [load] impl: " + impl; } }); diff --git a/src/parseTools.js b/src/parseTools.js index 05f12f61..89b5ac98 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -900,12 +900,17 @@ function makeCopyValues(dest, src, num, type, modifier) { // Given two values and an operation, returns the result of that operation. // Tries to do as much as possible at compile time. function getFastValue(a, op, b) { + a = a.toString(); + b = b.toString(); if (isNumber(a) && isNumber(b)) { return eval(a + op + b).toString(); } + if (op in set('+', '*') && isNumber(a)) { // if one of them is a number, keep it last + var c = b; + b = a; + a = c; + } if (op in set('*', '/')) { - if (!a) a = '1'; - if (!b) b = '1'; if (op == '*') { if (a == 0 || b == 0) { return '0'; @@ -922,8 +927,6 @@ function getFastValue(a, op, b) { } } } else if (op in set('+', '-')) { - if (!a) a = '0'; - if (!b) b = '0'; if (b[0] == '-') { op = op == '+' ? '-' : '+'; b = b.substr(1); |