vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
branchemul
changeset 695 dbcd1a21f3f8
parent 666 8338ab1991e6
parent 679 ee595aae8353
child 711 333326d65bf9
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Feb 05 08:27:42 2013 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Thu Feb 07 13:07:22 2013 +0100
     1.3 @@ -521,7 +521,7 @@
     1.4                      emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
     1.5                      break;
     1.6                  case opc_ladd:
     1.7 -                    emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
     1.8 +                    emit(out, "@1 = @1.add64(@2);", smapper.getL(1), smapper.popL());
     1.9                      break;
    1.10                  case opc_fadd:
    1.11                      emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
    1.12 @@ -533,7 +533,7 @@
    1.13                      emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
    1.14                      break;
    1.15                  case opc_lsub:
    1.16 -                    emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
    1.17 +                    emit(out, "@1 = @1.sub64(@2);", smapper.getL(1), smapper.popL());
    1.18                      break;
    1.19                  case opc_fsub:
    1.20                      emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
    1.21 @@ -545,7 +545,7 @@
    1.22                      emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
    1.23                      break;
    1.24                  case opc_lmul:
    1.25 -                    emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
    1.26 +                    emit(out, "@1 = @1.mul64(@2);", smapper.getL(1), smapper.popL());
    1.27                      break;
    1.28                  case opc_fmul:
    1.29                      emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
    1.30 @@ -558,7 +558,7 @@
    1.31                           smapper.getI(1), smapper.popI());
    1.32                      break;
    1.33                  case opc_ldiv:
    1.34 -                    emit(out, "@1 = Math.floor(@1 / @2);",
    1.35 +                    emit(out, "@1 = @1.div64(@2);",
    1.36                           smapper.getL(1), smapper.popL());
    1.37                      break;
    1.38                  case opc_fdiv:
    1.39 @@ -571,7 +571,8 @@
    1.40                      emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
    1.41                      break;
    1.42                  case opc_lrem:
    1.43 -                    emit(out, "@1 %= @2;", smapper.getL(1), smapper.popL());
    1.44 +                    emit(out, "@1 = @1.mod64(@2);",
    1.45 +                         smapper.getL(1), smapper.popL());
    1.46                      break;
    1.47                  case opc_frem:
    1.48                      emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
    1.49 @@ -583,25 +584,25 @@
    1.50                      emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
    1.51                      break;
    1.52                  case opc_land:
    1.53 -                    emit(out, "@1 &= @2;", smapper.getL(1), smapper.popL());
    1.54 +                    emit(out, "@1 = @1.and64(@2);", smapper.getL(1), smapper.popL());
    1.55                      break;
    1.56                  case opc_ior:
    1.57                      emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
    1.58                      break;
    1.59                  case opc_lor:
    1.60 -                    emit(out, "@1 |= @2;", smapper.getL(1), smapper.popL());
    1.61 +                    emit(out, "@1 = @1.or64(@2);", smapper.getL(1), smapper.popL());
    1.62                      break;
    1.63                  case opc_ixor:
    1.64                      emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
    1.65                      break;
    1.66                  case opc_lxor:
    1.67 -                    emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
    1.68 +                    emit(out, "@1 = @1.xor64(@2);", smapper.getL(1), smapper.popL());
    1.69                      break;
    1.70                  case opc_ineg:
    1.71                      emit(out, "@1 = -@1;", smapper.getI(0));
    1.72                      break;
    1.73                  case opc_lneg:
    1.74 -                    emit(out, "@1 = -@1;", smapper.getL(0));
    1.75 +                    emit(out, "@1 = @1.neg64();", smapper.getL(0));
    1.76                      break;
    1.77                  case opc_fneg:
    1.78                      emit(out, "@1 = -@1;", smapper.getF(0));
    1.79 @@ -613,19 +614,19 @@
    1.80                      emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
    1.81                      break;
    1.82                  case opc_lshl:
    1.83 -                    emit(out, "@1 <<= @2;", smapper.getL(1), smapper.popI());
    1.84 +                    emit(out, "@1 = @1.shl64(@2);", smapper.getL(1), smapper.popI());
    1.85                      break;
    1.86                  case opc_ishr:
    1.87                      emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
    1.88                      break;
    1.89                  case opc_lshr:
    1.90 -                    emit(out, "@1 >>= @2;", smapper.getL(1), smapper.popI());
    1.91 +                    emit(out, "@1 = @1.shr64(@2);", smapper.getL(1), smapper.popI());
    1.92                      break;
    1.93                  case opc_iushr:
    1.94                      emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
    1.95                      break;
    1.96                  case opc_lushr:
    1.97 -                    emit(out, "@1 >>>= @2;", smapper.getL(1), smapper.popI());
    1.98 +                    emit(out, "@1 = @1.ushr64(@2);", smapper.getL(1), smapper.popI());
    1.99                      break;
   1.100                  case opc_iinc: {
   1.101                      ++i;
   1.102 @@ -672,14 +673,14 @@
   1.103                      emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
   1.104                      break;
   1.105                  case opc_l2i:
   1.106 -                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushI());
   1.107 +                    emit(out, "var @2 = @1.toInt32();", smapper.popL(), smapper.pushI());
   1.108                      break;
   1.109                      // max int check?
   1.110                  case opc_l2f:
   1.111 -                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushF());
   1.112 +                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushF());
   1.113                      break;
   1.114                  case opc_l2d:
   1.115 -                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushD());
   1.116 +                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushD());
   1.117                      break;
   1.118                  case opc_f2d:
   1.119                      emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
   1.120 @@ -692,7 +693,7 @@
   1.121                           smapper.popF(), smapper.pushI());
   1.122                      break;
   1.123                  case opc_f2l:
   1.124 -                    emit(out, "var @2 = Math.floor(@1);",
   1.125 +                    emit(out, "var @2 = Math.floor(@1).toLong();",
   1.126                           smapper.popF(), smapper.pushL());
   1.127                      break;
   1.128                  case opc_d2i:
   1.129 @@ -700,7 +701,7 @@
   1.130                           smapper.popD(), smapper.pushI());
   1.131                      break;
   1.132                  case opc_d2l:
   1.133 -                    emit(out, "var @2 = Math.floor(@1);",
   1.134 +                    emit(out, "var @2 = Math.floor(@1).toLong();",
   1.135                           smapper.popD(), smapper.pushL());
   1.136                      break;
   1.137                  case opc_i2b:
   1.138 @@ -770,11 +771,19 @@
   1.139                      i += 2;
   1.140                      String v = encodeConstant(indx);
   1.141                      int type = VarType.fromConstantType(jc.getTag(indx));
   1.142 -                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
   1.143 +                    if (type == VarType.LONG) {
   1.144 +                        final Long lv = new Long(v);
   1.145 +                        final int low = (int)(lv.longValue() & 0xFFFFFFFF);
   1.146 +                        final int hi = (int)(lv.longValue() >> 32);
   1.147 +                        emit(out, "var @1 = 0x@3.next32(0x@2);", smapper.pushL(), 
   1.148 +                                Integer.toHexString(low), Integer.toHexString(hi));
   1.149 +                    } else {
   1.150 +                        emit(out, "var @1 = @2;", smapper.pushT(type), v);
   1.151 +                    }
   1.152                      break;
   1.153                  }
   1.154                  case opc_lcmp:
   1.155 -                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   1.156 +                    emit(out, "var @3 = @2.compare64(@1);",
   1.157                           smapper.popL(), smapper.popL(), smapper.pushI());
   1.158                      break;
   1.159                  case opc_fcmpl: