1.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Mon Jan 14 09:52:51 2013 +0100
1.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Mon Jan 14 13:21:40 2013 +0100
1.3 @@ -1,9 +1,9 @@
1.4 // empty line needed here
1.5 -__add32 = function(x,y) { return (x + y) | 0; };
1.6 -__sub32 = function(x,y) { return (x - y) | 0; };
1.7 -__mul32 = function(x,y) {
1.8 - return (((x * (y >> 16)) << 16) + x * (y & 0xFFFF)) | 0;
1.9 +Number.prototype.add32 = function(x) { return (this + x) | 0; };
1.10 +Number.prototype.sub32 = function(x) { return (this - x) | 0; };
1.11 +Number.prototype.mul32 = function(x) {
1.12 + return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
1.13 };
1.14
1.15 -__toInt8 = function(x) { return (x << 24) >> 24; };
1.16 -__toInt16 = function(x) { return (x << 16) >> 16; };
1.17 \ No newline at end of file
1.18 +Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
1.19 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
1.20 \ No newline at end of file
2.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 14 09:52:51 2013 +0100
2.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jan 14 13:21:40 2013 +0100
2.3 @@ -491,7 +491,7 @@
2.4 emit(out, "@1 = @2;", lmapper.setD(3), smapper.popD());
2.5 break;
2.6 case opc_iadd:
2.7 - emit(out, "@1 = __add32(@1,@2);", smapper.getI(1), smapper.popI());
2.8 + emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
2.9 break;
2.10 case opc_ladd:
2.11 emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
2.12 @@ -503,7 +503,7 @@
2.13 emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
2.14 break;
2.15 case opc_isub:
2.16 - emit(out, "@1 = __sub32(@1,@2);", smapper.getI(1), smapper.popI());
2.17 + emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
2.18 break;
2.19 case opc_lsub:
2.20 emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
2.21 @@ -515,7 +515,7 @@
2.22 emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
2.23 break;
2.24 case opc_imul:
2.25 - emit(out, "@1 = __mul32(@1,@2);", smapper.getI(1), smapper.popI());
2.26 + emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
2.27 break;
2.28 case opc_lmul:
2.29 emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
2.30 @@ -672,13 +672,13 @@
2.31 smapper.popD(), smapper.pushL());
2.32 break;
2.33 case opc_i2b:
2.34 - emit(out, "@1 = __toInt8(@1);", smapper.getI(0));
2.35 + emit(out, "@1 = @1.toInt8();", smapper.getI(0));
2.36 break;
2.37 case opc_i2c:
2.38 out.append("{ /* number conversion */ }");
2.39 break;
2.40 case opc_i2s:
2.41 - emit(out, "@1 = __toInt16(@1);", smapper.getI(0));
2.42 + emit(out, "@1 = @1.toInt16();", smapper.getI(0));
2.43 break;
2.44 case opc_aconst_null:
2.45 emit(out, "@1 = null;", smapper.pushA());