Integer arithmetic expressions extracted into simple functions.
1.1 --- a/emul/src/main/java/java/lang/Number.java Fri Jan 11 16:36:28 2013 +0100
1.2 +++ b/emul/src/main/java/java/lang/Number.java Sun Jan 13 23:07:54 2013 +0100
1.3 @@ -25,6 +25,8 @@
1.4
1.5 package java.lang;
1.6
1.7 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
1.8 +
1.9 /**
1.10 * The abstract class <code>Number</code> is the superclass of classes
1.11 * <code>BigDecimal</code>, <code>BigInteger</code>,
1.12 @@ -46,6 +48,10 @@
1.13 * @see java.lang.Short
1.14 * @since JDK1.0
1.15 */
1.16 +@ExtraJavaScript(
1.17 + resource="/org/apidesign/vm4brwsr/emul/java_lang_Number.js",
1.18 + processByteCode=true
1.19 +)
1.20 public abstract class Number implements java.io.Serializable {
1.21 /**
1.22 * Returns the value of the specified number as an <code>int</code>.
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Sun Jan 13 23:07:54 2013 +0100
2.3 @@ -0,0 +1,6 @@
2.4 +// empty line needed here
2.5 +__add32 = function(x,y) { return (x + y) | 0; };
2.6 +__sub32 = function(x,y) { return (x - y) | 0; };
2.7 +__mul32 = function(x,y) {
2.8 + return (((x * (y >> 16)) << 16) + x * (y & 0xFFFF)) | 0;
2.9 +};
3.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Jan 11 16:36:28 2013 +0100
3.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sun Jan 13 23:07:54 2013 +0100
3.3 @@ -491,7 +491,7 @@
3.4 emit(out, "@1 = @2;", lmapper.setD(3), smapper.popD());
3.5 break;
3.6 case opc_iadd:
3.7 - emit(out, "@1 = (@1 + @2) | 0;", smapper.getI(1), smapper.popI());
3.8 + emit(out, "@1 = __add32(@1,@2);", smapper.getI(1), smapper.popI());
3.9 break;
3.10 case opc_ladd:
3.11 emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
3.12 @@ -503,7 +503,7 @@
3.13 emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
3.14 break;
3.15 case opc_isub:
3.16 - emit(out, "@1 = (@1 - @2) | 0;", smapper.getI(1), smapper.popI());
3.17 + emit(out, "@1 = __sub32(@1,@2);", smapper.getI(1), smapper.popI());
3.18 break;
3.19 case opc_lsub:
3.20 emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
3.21 @@ -515,7 +515,7 @@
3.22 emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
3.23 break;
3.24 case opc_imul:
3.25 - emit(out, "@1 = (((@1 * (@2 >> 16)) << 16) + @1 * (@2 & 0xFFFF)) | 0;", smapper.getI(1), smapper.popI());
3.26 + emit(out, "@1 = __mul32(@1,@2);", smapper.getI(1), smapper.popI());
3.27 break;
3.28 case opc_lmul:
3.29 emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());