aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js2
-rw-r--r--src/parseTools.js11
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);