vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
changeset 456 f2f769bafeef
parent 453 5aca91d00356
parent 446 5b3d5ed03014
child 457 b0e82dcf51fb
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Jan 15 09:46:21 2013 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Jan 15 11:53:07 2013 +0100
     1.3 @@ -494,7 +494,7 @@
     1.4                      emit(out, "@1 = @2;", lmapper.setD(3), smapper.popD());
     1.5                      break;
     1.6                  case opc_iadd:
     1.7 -                    emit(out, "@1 = (@1 + @2) | 0;", smapper.getI(1), smapper.popI());
     1.8 +                    emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
     1.9                      break;
    1.10                  case opc_ladd:
    1.11                      emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
    1.12 @@ -506,7 +506,7 @@
    1.13                      emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
    1.14                      break;
    1.15                  case opc_isub:
    1.16 -                    emit(out, "@1 = (@1 - @2) | 0;", smapper.getI(1), smapper.popI());
    1.17 +                    emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
    1.18                      break;
    1.19                  case opc_lsub:
    1.20                      emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
    1.21 @@ -518,7 +518,7 @@
    1.22                      emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
    1.23                      break;
    1.24                  case opc_imul:
    1.25 -                    emit(out, "@1 = (((@1 * (@2 >> 16)) << 16) + @1 * (@2 & 0xFFFF)) | 0;", smapper.getI(1), smapper.popI());
    1.26 +                    emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
    1.27                      break;
    1.28                  case opc_lmul:
    1.29                      emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
    1.30 @@ -675,9 +675,13 @@
    1.31                           smapper.popD(), smapper.pushL());
    1.32                      break;
    1.33                  case opc_i2b:
    1.34 +                    emit(out, "@1 = @1.toInt8();", smapper.getI(0));
    1.35 +                    break;
    1.36                  case opc_i2c:
    1.37 +                    out.append("{ /* number conversion */ }");
    1.38 +                    break;
    1.39                  case opc_i2s:
    1.40 -                    out.append("{ /* number conversion */ }");
    1.41 +                    emit(out, "@1 = @1.toInt16();", smapper.getI(0));
    1.42                      break;
    1.43                  case opc_aconst_null:
    1.44                      emit(out, "@1 = null;", smapper.pushA());
    1.45 @@ -921,7 +925,7 @@
    1.46                          case 11: jvmType = "[J"; break;
    1.47                          default: throw new IllegalStateException("Array type: " + atype);
    1.48                      }
    1.49 -                    emit(out, "@2 = new Array(@1).fillNulls().arrtype('@3');",
    1.50 +                    emit(out, "@2 = new Array(@1).initWith('@3', 0);",
    1.51                           smapper.popI(), smapper.pushA(), jvmType);
    1.52                      break;
    1.53                  case opc_anewarray: {
    1.54 @@ -933,7 +937,7 @@
    1.55                      } else {
    1.56                          typeName = "[L" + typeName + ";";
    1.57                      }
    1.58 -                    emit(out, "@2 = new Array(@1).fillNulls().arrtype('@3');",
    1.59 +                    emit(out, "@2 = new Array(@1).initWith('@3', null);",
    1.60                           smapper.popI(), smapper.pushA(), typeName);
    1.61                      break;
    1.62                  }
    1.63 @@ -943,7 +947,7 @@
    1.64                      String typeName = jc.getClassName(type);
    1.65                      int dim = readByte(byteCodes, ++i);
    1.66                      out.append("{ var a0 = new Array(").append(smapper.popI())
    1.67 -                       .append(").fillNulls().arrtype('").append(typeName).append("');");
    1.68 +                       .append(").initWith('").append(typeName).append("', null);");
    1.69                      for (int d = 1; d < dim; d++) {
    1.70                          typeName = typeName.substring(1);
    1.71                          out.append("\n  var l" + d).append(" = ")
    1.72 @@ -952,8 +956,8 @@
    1.73                              append(" < a" + (d - 1)).
    1.74                              append(".length; i" + d).append("++) {");
    1.75                          out.append("\n    var a" + d).
    1.76 -                            append (" = new Array(l" + d).append(").fillNulls().arrtype('")
    1.77 -                            .append(typeName).append("');");
    1.78 +                            append (" = new Array(l" + d).append(").initWith('")
    1.79 +                            .append(typeName).append("', null);");
    1.80                          out.append("\n    a" + (d - 1)).append("[i" + d).append("] = a" + d).
    1.81                              append(";");
    1.82                      }