Merging Lubo's elimination of the 'var' block at the beginning of each function
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 18 Jan 2013 16:45:51 +0100
changeset 478509e3d4f477c
parent 459 a2871a3fd4c5
parent 474 859cc3a0b8f0
child 488 9288ecf9657c
Merging Lubo's elimination of the 'var' block at the beginning of each function
     1.1 --- a/javap/src/main/java/org/apidesign/javap/StackMapIterator.java	Tue Jan 15 12:44:33 2013 +0100
     1.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapIterator.java	Fri Jan 18 16:45:51 2013 +0100
     1.3 @@ -123,7 +123,7 @@
     1.4          }
     1.5  
     1.6          final int length = methodSignature.length();
     1.7 -        int skipType = 0;
     1.8 +        boolean skipType = false;
     1.9          int argType;
    1.10          for (int i = 1; i < length; ++i) {
    1.11              switch (methodSignature.charAt(i)) {
    1.12 @@ -156,10 +156,10 @@
    1.13                      // not interested in the return value type
    1.14                      return argTypes;
    1.15                  case '[':
    1.16 -                    if (skipType == 0) {
    1.17 +                    if (!skipType) {
    1.18                          argTypes.add(ITEM_Object);
    1.19 +                        skipType = true;
    1.20                      }
    1.21 -                    ++skipType;
    1.22                      continue;
    1.23  
    1.24                  default:
    1.25 @@ -167,10 +167,10 @@
    1.26                                    "Invalid method signature");
    1.27              }
    1.28  
    1.29 -            if (skipType == 0) {
    1.30 +            if (!skipType) {
    1.31                  argTypes.add(argType);
    1.32              } else {
    1.33 -                --skipType;
    1.34 +                skipType = false;
    1.35              }
    1.36          }
    1.37  
     2.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Jan 15 12:44:33 2013 +0100
     2.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Fri Jan 18 16:45:51 2013 +0100
     2.3 @@ -264,37 +264,10 @@
     2.4  
     2.5          final StackMapper smapper = new StackMapper();
     2.6  
     2.7 -        final int maxLocals = m.getMaxLocals();
     2.8 -        if (maxLocals > 0) {
     2.9 -            // TODO: generate only used local variables
    2.10 -            for (int j = 0; j <= VarType.LAST; ++j) {
    2.11 -                out.append("\n  var ").append(Variable.getLocalVariable(j, 0));
    2.12 -                for (int i = 1; i < maxLocals; ++i) {
    2.13 -                    out.append(", ");
    2.14 -                    out.append(Variable.getLocalVariable(j, i));
    2.15 -                }
    2.16 -                out.append(';');
    2.17 -            }
    2.18 -        }
    2.19          if (!m.isStatic()) {
    2.20              out.append("  var ").append(" lcA0 = this;\n");
    2.21          }
    2.22  
    2.23 -        // maxStack includes two stack positions for every pushed long / double
    2.24 -        // so this might generate more stack variables than we need
    2.25 -        final int maxStack = m.getMaxStack();
    2.26 -        if (maxStack > 0) {
    2.27 -            // TODO: generate only used stack variables
    2.28 -            for (int j = 0; j <= VarType.LAST; ++j) {
    2.29 -                out.append("\n  var ").append(Variable.getStackVariable(j, 0));
    2.30 -                for (int i = 1; i < maxStack; ++i) {
    2.31 -                    out.append(", ");
    2.32 -                    out.append(Variable.getStackVariable(j, i));
    2.33 -                }
    2.34 -                out.append(';');
    2.35 -            }
    2.36 -        }
    2.37 -
    2.38          int lastStackFrame = -1;
    2.39          TrapData[] previousTrap = null;
    2.40          
    2.41 @@ -325,174 +298,184 @@
    2.42              final int c = readByte(byteCodes, i);
    2.43              switch (c) {
    2.44                  case opc_aload_0:
    2.45 -                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(0));
    2.46 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(0));
    2.47                      break;
    2.48                  case opc_iload_0:
    2.49 -                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(0));
    2.50 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(0));
    2.51                      break;
    2.52                  case opc_lload_0:
    2.53 -                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(0));
    2.54 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(0));
    2.55                      break;
    2.56                  case opc_fload_0:
    2.57 -                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(0));
    2.58 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(0));
    2.59                      break;
    2.60                  case opc_dload_0:
    2.61 -                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(0));
    2.62 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(0));
    2.63                      break;
    2.64                  case opc_aload_1:
    2.65 -                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(1));
    2.66 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(1));
    2.67                      break;
    2.68                  case opc_iload_1:
    2.69 -                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(1));
    2.70 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(1));
    2.71                      break;
    2.72                  case opc_lload_1:
    2.73 -                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(1));
    2.74 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(1));
    2.75                      break;
    2.76                  case opc_fload_1:
    2.77 -                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(1));
    2.78 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(1));
    2.79                      break;
    2.80                  case opc_dload_1:
    2.81 -                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(1));
    2.82 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(1));
    2.83                      break;
    2.84                  case opc_aload_2:
    2.85 -                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(2));
    2.86 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(2));
    2.87                      break;
    2.88                  case opc_iload_2:
    2.89 -                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(2));
    2.90 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(2));
    2.91                      break;
    2.92                  case opc_lload_2:
    2.93 -                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(2));
    2.94 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(2));
    2.95                      break;
    2.96                  case opc_fload_2:
    2.97 -                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(2));
    2.98 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(2));
    2.99                      break;
   2.100                  case opc_dload_2:
   2.101 -                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(2));
   2.102 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(2));
   2.103                      break;
   2.104                  case opc_aload_3:
   2.105 -                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(3));
   2.106 +                    emit(out, "var @1 = @2;", smapper.pushA(), lmapper.getA(3));
   2.107                      break;
   2.108                  case opc_iload_3:
   2.109 -                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(3));
   2.110 +                    emit(out, "var @1 = @2;", smapper.pushI(), lmapper.getI(3));
   2.111                      break;
   2.112                  case opc_lload_3:
   2.113 -                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(3));
   2.114 +                    emit(out, "var @1 = @2;", smapper.pushL(), lmapper.getL(3));
   2.115                      break;
   2.116                  case opc_fload_3:
   2.117 -                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(3));
   2.118 +                    emit(out, "var @1 = @2;", smapper.pushF(), lmapper.getF(3));
   2.119                      break;
   2.120                  case opc_dload_3:
   2.121 -                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(3));
   2.122 +                    emit(out, "var @1 = @2;", smapper.pushD(), lmapper.getD(3));
   2.123                      break;
   2.124                  case opc_iload: {
   2.125                      final int indx = readByte(byteCodes, ++i);
   2.126 -                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(indx));
   2.127 +                    emit(out, "var @1 = @2;",
   2.128 +                         smapper.pushI(), lmapper.getI(indx));
   2.129                      break;
   2.130                  }
   2.131                  case opc_lload: {
   2.132                      final int indx = readByte(byteCodes, ++i);
   2.133 -                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(indx));
   2.134 +                    emit(out, "var @1 = @2;",
   2.135 +                         smapper.pushL(), lmapper.getL(indx));
   2.136                      break;
   2.137                  }
   2.138                  case opc_fload: {
   2.139                      final int indx = readByte(byteCodes, ++i);
   2.140 -                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(indx));
   2.141 +                    emit(out, "var @1 = @2;",
   2.142 +                         smapper.pushF(), lmapper.getF(indx));
   2.143                      break;
   2.144                  }
   2.145                  case opc_dload: {
   2.146                      final int indx = readByte(byteCodes, ++i);
   2.147 -                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(indx));
   2.148 +                    emit(out, "var @1 = @2;",
   2.149 +                         smapper.pushD(), lmapper.getD(indx));
   2.150                      break;
   2.151                  }
   2.152                  case opc_aload: {
   2.153                      final int indx = readByte(byteCodes, ++i);
   2.154 -                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(indx));
   2.155 +                    emit(out, "var @1 = @2;",
   2.156 +                         smapper.pushA(), lmapper.getA(indx));
   2.157                      break;
   2.158                  }
   2.159                  case opc_istore: {
   2.160                      final int indx = readByte(byteCodes, ++i);
   2.161 -                    emit(out, "@1 = @2;", lmapper.setI(indx), smapper.popI());
   2.162 +                    emit(out, "var @1 = @2;",
   2.163 +                         lmapper.setI(indx), smapper.popI());
   2.164                      break;
   2.165                  }
   2.166                  case opc_lstore: {
   2.167                      final int indx = readByte(byteCodes, ++i);
   2.168 -                    emit(out, "@1 = @2;", lmapper.setL(indx), smapper.popL());
   2.169 +                    emit(out, "var @1 = @2;",
   2.170 +                         lmapper.setL(indx), smapper.popL());
   2.171                      break;
   2.172                  }
   2.173                  case opc_fstore: {
   2.174                      final int indx = readByte(byteCodes, ++i);
   2.175 -                    emit(out, "@1 = @2;", lmapper.setF(indx), smapper.popF());
   2.176 +                    emit(out, "var @1 = @2;",
   2.177 +                         lmapper.setF(indx), smapper.popF());
   2.178                      break;
   2.179                  }
   2.180                  case opc_dstore: {
   2.181                      final int indx = readByte(byteCodes, ++i);
   2.182 -                    emit(out, "@1 = @2;", lmapper.setD(indx), smapper.popD());
   2.183 +                    emit(out, "var @1 = @2;",
   2.184 +                         lmapper.setD(indx), smapper.popD());
   2.185                      break;
   2.186                  }
   2.187                  case opc_astore: {
   2.188                      final int indx = readByte(byteCodes, ++i);
   2.189 -                    emit(out, "@1 = @2;", lmapper.setA(indx), smapper.popA());
   2.190 +                    emit(out, "var @1 = @2;",
   2.191 +                         lmapper.setA(indx), smapper.popA());
   2.192                      break;
   2.193                  }
   2.194                  case opc_astore_0:
   2.195 -                    emit(out, "@1 = @2;", lmapper.setA(0), smapper.popA());
   2.196 +                    emit(out, "var @1 = @2;", lmapper.setA(0), smapper.popA());
   2.197                      break;
   2.198                  case opc_istore_0:
   2.199 -                    emit(out, "@1 = @2;", lmapper.setI(0), smapper.popI());
   2.200 +                    emit(out, "var @1 = @2;", lmapper.setI(0), smapper.popI());
   2.201                      break;
   2.202                  case opc_lstore_0:
   2.203 -                    emit(out, "@1 = @2;", lmapper.setL(0), smapper.popL());
   2.204 +                    emit(out, "var @1 = @2;", lmapper.setL(0), smapper.popL());
   2.205                      break;
   2.206                  case opc_fstore_0:
   2.207 -                    emit(out, "@1 = @2;", lmapper.setF(0), smapper.popF());
   2.208 +                    emit(out, "var @1 = @2;", lmapper.setF(0), smapper.popF());
   2.209                      break;
   2.210                  case opc_dstore_0:
   2.211 -                    emit(out, "@1 = @2;", lmapper.setD(0), smapper.popD());
   2.212 +                    emit(out, "var @1 = @2;", lmapper.setD(0), smapper.popD());
   2.213                      break;
   2.214                  case opc_astore_1:
   2.215 -                    emit(out, "@1 = @2;", lmapper.setA(1), smapper.popA());
   2.216 +                    emit(out, "var @1 = @2;", lmapper.setA(1), smapper.popA());
   2.217                      break;
   2.218                  case opc_istore_1:
   2.219 -                    emit(out, "@1 = @2;", lmapper.setI(1), smapper.popI());
   2.220 +                    emit(out, "var @1 = @2;", lmapper.setI(1), smapper.popI());
   2.221                      break;
   2.222                  case opc_lstore_1:
   2.223 -                    emit(out, "@1 = @2;", lmapper.setL(1), smapper.popL());
   2.224 +                    emit(out, "var @1 = @2;", lmapper.setL(1), smapper.popL());
   2.225                      break;
   2.226                  case opc_fstore_1:
   2.227 -                    emit(out, "@1 = @2;", lmapper.setF(1), smapper.popF());
   2.228 +                    emit(out, "var @1 = @2;", lmapper.setF(1), smapper.popF());
   2.229                      break;
   2.230                  case opc_dstore_1:
   2.231 -                    emit(out, "@1 = @2;", lmapper.setD(1), smapper.popD());
   2.232 +                    emit(out, "var @1 = @2;", lmapper.setD(1), smapper.popD());
   2.233                      break;
   2.234                  case opc_astore_2:
   2.235 -                    emit(out, "@1 = @2;", lmapper.setA(2), smapper.popA());
   2.236 +                    emit(out, "var @1 = @2;", lmapper.setA(2), smapper.popA());
   2.237                      break;
   2.238                  case opc_istore_2:
   2.239 -                    emit(out, "@1 = @2;", lmapper.setI(2), smapper.popI());
   2.240 +                    emit(out, "var @1 = @2;", lmapper.setI(2), smapper.popI());
   2.241                      break;
   2.242                  case opc_lstore_2:
   2.243 -                    emit(out, "@1 = @2;", lmapper.setL(2), smapper.popL());
   2.244 +                    emit(out, "var @1 = @2;", lmapper.setL(2), smapper.popL());
   2.245                      break;
   2.246                  case opc_fstore_2:
   2.247 -                    emit(out, "@1 = @2;", lmapper.setF(2), smapper.popF());
   2.248 +                    emit(out, "var @1 = @2;", lmapper.setF(2), smapper.popF());
   2.249                      break;
   2.250                  case opc_dstore_2:
   2.251 -                    emit(out, "@1 = @2;", lmapper.setD(2), smapper.popD());
   2.252 +                    emit(out, "var @1 = @2;", lmapper.setD(2), smapper.popD());
   2.253                      break;
   2.254                  case opc_astore_3:
   2.255 -                    emit(out, "@1 = @2;", lmapper.setA(3), smapper.popA());
   2.256 +                    emit(out, "var @1 = @2;", lmapper.setA(3), smapper.popA());
   2.257                      break;
   2.258                  case opc_istore_3:
   2.259 -                    emit(out, "@1 = @2;", lmapper.setI(3), smapper.popI());
   2.260 +                    emit(out, "var @1 = @2;", lmapper.setI(3), smapper.popI());
   2.261                      break;
   2.262                  case opc_lstore_3:
   2.263 -                    emit(out, "@1 = @2;", lmapper.setL(3), smapper.popL());
   2.264 +                    emit(out, "var @1 = @2;", lmapper.setL(3), smapper.popL());
   2.265                      break;
   2.266                  case opc_fstore_3:
   2.267 -                    emit(out, "@1 = @2;", lmapper.setF(3), smapper.popF());
   2.268 +                    emit(out, "var @1 = @2;", lmapper.setF(3), smapper.popF());
   2.269                      break;
   2.270                  case opc_dstore_3:
   2.271 -                    emit(out, "@1 = @2;", lmapper.setD(3), smapper.popD());
   2.272 +                    emit(out, "var @1 = @2;", lmapper.setD(3), smapper.popD());
   2.273                      break;
   2.274                  case opc_iadd:
   2.275                      emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
   2.276 @@ -635,105 +618,105 @@
   2.277                      emit(out, "return @1;", smapper.popA());
   2.278                      break;
   2.279                  case opc_i2l:
   2.280 -                    emit(out, "@2 = @1;", smapper.popI(), smapper.pushL());
   2.281 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushL());
   2.282                      break;
   2.283                  case opc_i2f:
   2.284 -                    emit(out, "@2 = @1;", smapper.popI(), smapper.pushF());
   2.285 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushF());
   2.286                      break;
   2.287                  case opc_i2d:
   2.288 -                    emit(out, "@2 = @1;", smapper.popI(), smapper.pushD());
   2.289 +                    emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
   2.290                      break;
   2.291                  case opc_l2i:
   2.292 -                    emit(out, "@2 = @1;", smapper.popL(), smapper.pushI());
   2.293 +                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushI());
   2.294                      break;
   2.295                      // max int check?
   2.296                  case opc_l2f:
   2.297 -                    emit(out, "@2 = @1;", smapper.popL(), smapper.pushF());
   2.298 +                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushF());
   2.299                      break;
   2.300                  case opc_l2d:
   2.301 -                    emit(out, "@2 = @1;", smapper.popL(), smapper.pushD());
   2.302 +                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushD());
   2.303                      break;
   2.304                  case opc_f2d:
   2.305 -                    emit(out, "@2 = @1;", smapper.popF(), smapper.pushD());
   2.306 +                    emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
   2.307                      break;
   2.308                  case opc_d2f:
   2.309 -                    emit(out, "@2 = @1;", smapper.popD(), smapper.pushF());
   2.310 +                    emit(out, "var @2 = @1;", smapper.popD(), smapper.pushF());
   2.311                      break;
   2.312                  case opc_f2i:
   2.313 -                    emit(out, "@2 = Math.floor(@1);",
   2.314 +                    emit(out, "var @2 = Math.floor(@1);",
   2.315                           smapper.popF(), smapper.pushI());
   2.316                      break;
   2.317                  case opc_f2l:
   2.318 -                    emit(out, "@2 = Math.floor(@1);",
   2.319 +                    emit(out, "var @2 = Math.floor(@1);",
   2.320                           smapper.popF(), smapper.pushL());
   2.321                      break;
   2.322                  case opc_d2i:
   2.323 -                    emit(out, "@2 = Math.floor(@1);",
   2.324 +                    emit(out, "var @2 = Math.floor(@1);",
   2.325                           smapper.popD(), smapper.pushI());
   2.326                      break;
   2.327                  case opc_d2l:
   2.328 -                    emit(out, "@2 = Math.floor(@1);",
   2.329 +                    emit(out, "var @2 = Math.floor(@1);",
   2.330                           smapper.popD(), smapper.pushL());
   2.331                      break;
   2.332                  case opc_i2b:
   2.333 -                    emit(out, "@1 = @1.toInt8();", smapper.getI(0));
   2.334 +                    emit(out, "var @1 = @1.toInt8();", smapper.getI(0));
   2.335                      break;
   2.336                  case opc_i2c:
   2.337                      out.append("{ /* number conversion */ }");
   2.338                      break;
   2.339                  case opc_i2s:
   2.340 -                    emit(out, "@1 = @1.toInt16();", smapper.getI(0));
   2.341 +                    emit(out, "var @1 = @1.toInt16();", smapper.getI(0));
   2.342                      break;
   2.343                  case opc_aconst_null:
   2.344 -                    emit(out, "@1 = null;", smapper.pushA());
   2.345 +                    emit(out, "var @1 = null;", smapper.pushA());
   2.346                      break;
   2.347                  case opc_iconst_m1:
   2.348 -                    emit(out, "@1 = -1;", smapper.pushI());
   2.349 +                    emit(out, "var @1 = -1;", smapper.pushI());
   2.350                      break;
   2.351                  case opc_iconst_0:
   2.352 -                    emit(out, "@1 = 0;", smapper.pushI());
   2.353 +                    emit(out, "var @1 = 0;", smapper.pushI());
   2.354                      break;
   2.355                  case opc_dconst_0:
   2.356 -                    emit(out, "@1 = 0;", smapper.pushD());
   2.357 +                    emit(out, "var @1 = 0;", smapper.pushD());
   2.358                      break;
   2.359                  case opc_lconst_0:
   2.360 -                    emit(out, "@1 = 0;", smapper.pushL());
   2.361 +                    emit(out, "var @1 = 0;", smapper.pushL());
   2.362                      break;
   2.363                  case opc_fconst_0:
   2.364 -                    emit(out, "@1 = 0;", smapper.pushF());
   2.365 +                    emit(out, "var @1 = 0;", smapper.pushF());
   2.366                      break;
   2.367                  case opc_iconst_1:
   2.368 -                    emit(out, "@1 = 1;", smapper.pushI());
   2.369 +                    emit(out, "var @1 = 1;", smapper.pushI());
   2.370                      break;
   2.371                  case opc_lconst_1:
   2.372 -                    emit(out, "@1 = 1;", smapper.pushL());
   2.373 +                    emit(out, "var @1 = 1;", smapper.pushL());
   2.374                      break;
   2.375                  case opc_fconst_1:
   2.376 -                    emit(out, "@1 = 1;", smapper.pushF());
   2.377 +                    emit(out, "var @1 = 1;", smapper.pushF());
   2.378                      break;
   2.379                  case opc_dconst_1:
   2.380 -                    emit(out, "@1 = 1;", smapper.pushD());
   2.381 +                    emit(out, "var @1 = 1;", smapper.pushD());
   2.382                      break;
   2.383                  case opc_iconst_2:
   2.384 -                    emit(out, "@1 = 2;", smapper.pushI());
   2.385 +                    emit(out, "var @1 = 2;", smapper.pushI());
   2.386                      break;
   2.387                  case opc_fconst_2:
   2.388 -                    emit(out, "@1 = 2;", smapper.pushF());
   2.389 +                    emit(out, "var @1 = 2;", smapper.pushF());
   2.390                      break;
   2.391                  case opc_iconst_3:
   2.392 -                    emit(out, "@1 = 3;", smapper.pushI());
   2.393 +                    emit(out, "var @1 = 3;", smapper.pushI());
   2.394                      break;
   2.395                  case opc_iconst_4:
   2.396 -                    emit(out, "@1 = 4;", smapper.pushI());
   2.397 +                    emit(out, "var @1 = 4;", smapper.pushI());
   2.398                      break;
   2.399                  case opc_iconst_5:
   2.400 -                    emit(out, "@1 = 5;", smapper.pushI());
   2.401 +                    emit(out, "var @1 = 5;", smapper.pushI());
   2.402                      break;
   2.403                  case opc_ldc: {
   2.404                      int indx = readByte(byteCodes, ++i);
   2.405                      String v = encodeConstant(indx);
   2.406                      int type = VarType.fromConstantType(jc.getTag(indx));
   2.407 -                    emit(out, "@1 = @2;", smapper.pushT(type), v);
   2.408 +                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
   2.409                      break;
   2.410                  }
   2.411                  case opc_ldc_w:
   2.412 @@ -742,21 +725,21 @@
   2.413                      i += 2;
   2.414                      String v = encodeConstant(indx);
   2.415                      int type = VarType.fromConstantType(jc.getTag(indx));
   2.416 -                    emit(out, "@1 = @2;", smapper.pushT(type), v);
   2.417 +                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
   2.418                      break;
   2.419                  }
   2.420                  case opc_lcmp:
   2.421 -                    emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   2.422 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   2.423                           smapper.popL(), smapper.popL(), smapper.pushI());
   2.424                      break;
   2.425                  case opc_fcmpl:
   2.426                  case opc_fcmpg:
   2.427 -                    emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   2.428 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   2.429                           smapper.popF(), smapper.popF(), smapper.pushI());
   2.430                      break;
   2.431                  case opc_dcmpl:
   2.432                  case opc_dcmpg:
   2.433 -                    emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   2.434 +                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   2.435                           smapper.popD(), smapper.popD(), smapper.pushI());
   2.436                      break;
   2.437                  case opc_if_acmpeq:
   2.438 @@ -906,7 +889,7 @@
   2.439                  case opc_new: {
   2.440                      int indx = readIntArg(byteCodes, i);
   2.441                      String ci = jc.getClassName(indx);
   2.442 -                    emit(out, "@1 = new @2;",
   2.443 +                    emit(out, "var @1 = new @2;",
   2.444                           smapper.pushA(), accessClass(ci.replace('/', '_')));
   2.445                      addReference(ci);
   2.446                      i += 2;
   2.447 @@ -926,7 +909,7 @@
   2.448                          case 11: jvmType = "[J"; break;
   2.449                          default: throw new IllegalStateException("Array type: " + atype);
   2.450                      }
   2.451 -                    emit(out, "@2 = new Array(@1).initWith('@3', 0);",
   2.452 +                    emit(out, "var @2 = new Array(@1).initWith('@3', 0);",
   2.453                           smapper.popI(), smapper.pushA(), jvmType);
   2.454                      break;
   2.455                  case opc_anewarray: {
   2.456 @@ -938,7 +921,7 @@
   2.457                      } else {
   2.458                          typeName = "[L" + typeName + ";";
   2.459                      }
   2.460 -                    emit(out, "@2 = new Array(@1).initWith('@3', null);",
   2.461 +                    emit(out, "var @2 = new Array(@1).initWith('@3', null);",
   2.462                           smapper.popI(), smapper.pushA(), typeName);
   2.463                      break;
   2.464                  }
   2.465 @@ -966,11 +949,13 @@
   2.466                      for (int d = 1; d < dim; d++) {
   2.467                          out.append("\n  }");
   2.468                      }
   2.469 -                    out.append("\n").append(smapper.pushA()).append(" = a0; }");
   2.470 +                    out.append("\nvar ").append(smapper.pushA())
   2.471 +                                        .append(" = a0; }");
   2.472                      break;
   2.473                  }
   2.474                  case opc_arraylength:
   2.475 -                    emit(out, "@2 = @1.length;", smapper.popA(), smapper.pushI());
   2.476 +                    emit(out, "var @2 = @1.length;",
   2.477 +                         smapper.popA(), smapper.pushI());
   2.478                      break;
   2.479                  case opc_lastore:
   2.480                      emit(out, "@3.at(@2, @1);",
   2.481 @@ -996,26 +981,26 @@
   2.482                           smapper.popI(), smapper.popI(), smapper.popA());
   2.483                      break;
   2.484                  case opc_laload:
   2.485 -                    emit(out, "@3 = @2.at(@1);",
   2.486 +                    emit(out, "var @3 = @2.at(@1);",
   2.487                           smapper.popI(), smapper.popA(), smapper.pushL());
   2.488                      break;
   2.489                  case opc_faload:
   2.490 -                    emit(out, "@3 = @2.at(@1);",
   2.491 +                    emit(out, "var @3 = @2.at(@1);",
   2.492                           smapper.popI(), smapper.popA(), smapper.pushF());
   2.493                      break;
   2.494                  case opc_daload:
   2.495 -                    emit(out, "@3 = @2.at(@1);",
   2.496 +                    emit(out, "var @3 = @2.at(@1);",
   2.497                           smapper.popI(), smapper.popA(), smapper.pushD());
   2.498                      break;
   2.499                  case opc_aaload:
   2.500 -                    emit(out, "@3 = @2.at(@1);",
   2.501 +                    emit(out, "var @3 = @2.at(@1);",
   2.502                           smapper.popI(), smapper.popA(), smapper.pushA());
   2.503                      break;
   2.504                  case opc_iaload:
   2.505                  case opc_baload:
   2.506                  case opc_caload:
   2.507                  case opc_saload:
   2.508 -                    emit(out, "@3 = @2.at(@1);",
   2.509 +                    emit(out, "var @3 = @2.at(@1);",
   2.510                           smapper.popI(), smapper.popA(), smapper.pushI());
   2.511                      break;
   2.512                  case opc_pop:
   2.513 @@ -1025,17 +1010,18 @@
   2.514                      break;
   2.515                  case opc_dup: {
   2.516                      final Variable v = smapper.get(0);
   2.517 -                    emit(out, "@1 = @2;", smapper.pushT(v.getType()), v);
   2.518 +                    emit(out, "var @1 = @2;", smapper.pushT(v.getType()), v);
   2.519                      break;
   2.520                  }
   2.521                  case opc_dup2: {
   2.522                      if (smapper.get(0).isCategory2()) {
   2.523                          final Variable v = smapper.get(0);
   2.524 -                        emit(out, "@1 = @2;", smapper.pushT(v.getType()), v);
   2.525 +                        emit(out, "var @1 = @2;",
   2.526 +                             smapper.pushT(v.getType()), v);
   2.527                      } else {
   2.528                          final Variable v1 = smapper.get(0);
   2.529                          final Variable v2 = smapper.get(1);
   2.530 -                        emit(out, "{ @1 = @2; @3 = @4; }",
   2.531 +                        emit(out, "var @1 = @2, @3 = @4;",
   2.532                               smapper.pushT(v2.getType()), v2,
   2.533                               smapper.pushT(v1.getType()), v1);
   2.534                      }
   2.535 @@ -1048,7 +1034,7 @@
   2.536                      final Variable vo2 = smapper.pushT(vi2.getType());
   2.537                      final Variable vo1 = smapper.pushT(vi1.getType());
   2.538  
   2.539 -                    emit(out, "{ @1 = @2; @3 = @4; @5 = @6; }",
   2.540 +                    emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
   2.541                           vo1, vi1, vo2, vi2, vo3, vo1);
   2.542                      break;
   2.543                  }
   2.544 @@ -1060,7 +1046,7 @@
   2.545                          final Variable vo2 = smapper.pushT(vi2.getType());
   2.546                          final Variable vo1 = smapper.pushT(vi1.getType());
   2.547  
   2.548 -                        emit(out, "{ @1 = @2; @3 = @4; @5 = @6; }",
   2.549 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6;",
   2.550                               vo1, vi1, vo2, vi2, vo3, vo1);
   2.551                      } else {
   2.552                          final Variable vi1 = smapper.pop();
   2.553 @@ -1071,17 +1057,17 @@
   2.554                          final Variable vo2 = smapper.pushT(vi2.getType());
   2.555                          final Variable vo1 = smapper.pushT(vi1.getType());
   2.556  
   2.557 -                        emit(out, "{ @1 = @2; @3 = @4; @5 = @6; @7 = @8; }",
   2.558 +                        emit(out, "var @1 = @2, @3 = @4, @5 = @6, @7 = @8;",
   2.559                               vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
   2.560                      }
   2.561                      break;
   2.562                  }
   2.563                  case opc_bipush:
   2.564 -                    emit(out, "@1 = @2;",
   2.565 +                    emit(out, "var @1 = @2;",
   2.566                           smapper.pushI(), Integer.toString(byteCodes[++i]));
   2.567                      break;
   2.568                  case opc_sipush:
   2.569 -                    emit(out, "@1 = @2;",
   2.570 +                    emit(out, "var @1 = @2;",
   2.571                           smapper.pushI(),
   2.572                           Integer.toString(readIntArg(byteCodes, i)));
   2.573                      i += 2;
   2.574 @@ -1090,7 +1076,7 @@
   2.575                      int indx = readIntArg(byteCodes, i);
   2.576                      String[] fi = jc.getFieldInfoName(indx);
   2.577                      final int type = VarType.fromFieldType(fi[2].charAt(0));
   2.578 -                    emit(out, "@2 = @1.fld_@3;",
   2.579 +                    emit(out, "var @2 = @1.fld_@3;",
   2.580                           smapper.popA(), smapper.pushT(type), fi[1]);
   2.581                      i += 2;
   2.582                      break;
   2.583 @@ -1099,7 +1085,7 @@
   2.584                      int indx = readIntArg(byteCodes, i);
   2.585                      String[] fi = jc.getFieldInfoName(indx);
   2.586                      final int type = VarType.fromFieldType(fi[2].charAt(0));
   2.587 -                    emit(out, "@1 = @2(false).constructor.@3;",
   2.588 +                    emit(out, "var @1 = @2(false).constructor.@3;",
   2.589                           smapper.pushT(type),
   2.590                           accessClass(fi[0].replace('/', '_')), fi[1]);
   2.591                      i += 2;
   2.592 @@ -1142,7 +1128,7 @@
   2.593                  case opc_instanceof: {
   2.594                      int indx = readIntArg(byteCodes, i);
   2.595                      final String type = jc.getClassName(indx);
   2.596 -                    emit(out, "@2 = @1.$instOf_@3 ? 1 : 0;",
   2.597 +                    emit(out, "var @2 = @1.$instOf_@3 ? 1 : 0;",
   2.598                           smapper.popA(), smapper.pushI(),
   2.599                           type.replace('/', '_'));
   2.600                      i += 2;
   2.601 @@ -1152,7 +1138,7 @@
   2.602                      final Variable v = smapper.popA();
   2.603                      smapper.clear();
   2.604  
   2.605 -                    emit(out, "{ @1 = @2; throw @2; }",
   2.606 +                    emit(out, "{ var @1 = @2; throw @2; }",
   2.607                           smapper.pushA(), v);
   2.608                      break;
   2.609                  }
   2.610 @@ -1352,7 +1338,8 @@
   2.611          }
   2.612  
   2.613          if (returnType[0] != 'V') {
   2.614 -            out.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
   2.615 +            out.append("var ")
   2.616 +               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
   2.617                 .append(" = ");
   2.618          }
   2.619  
   2.620 @@ -1396,7 +1383,8 @@
   2.621          }
   2.622  
   2.623          if (returnType[0] != 'V') {
   2.624 -            out.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
   2.625 +            out.append("var ")
   2.626 +               .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
   2.627                 .append(" = ");
   2.628          }
   2.629  
   2.630 @@ -1628,15 +1616,15 @@
   2.631                  addReference(classInternalName);
   2.632                  if ("java/lang/Throwable".equals(classInternalName)) {
   2.633                      out.append("if (e.$instOf_java_lang_Throwable) {");
   2.634 -                    out.append("  stA0 = e;");
   2.635 +                    out.append("  var stA0 = e;");
   2.636                      out.append("} else {");
   2.637 -                    out.append("  stA0 = vm.java_lang_Throwable(true);");
   2.638 +                    out.append("  var stA0 = vm.java_lang_Throwable(true);");
   2.639                      out.append("  vm.java_lang_Throwable.cons__VLjava_lang_String_2.call(stA0, e.toString());");
   2.640                      out.append("}");
   2.641                      out.append("gt=" + e.handler_pc + "; continue;");
   2.642                  } else {
   2.643                      out.append("if (e.$instOf_" + classInternalName.replace('/', '_') + ") {");
   2.644 -                    out.append("gt=" + e.handler_pc + "; stA0 = e; continue;");
   2.645 +                    out.append("gt=" + e.handler_pc + "; var stA0 = e; continue;");
   2.646                      out.append("}\n");
   2.647                  }
   2.648              } else {
   2.649 @@ -1646,7 +1634,7 @@
   2.650          if (finallyPC == -1) {
   2.651              out.append("throw e;");
   2.652          } else {
   2.653 -            out.append("gt=" + finallyPC + "; stA0 = e; continue;");
   2.654 +            out.append("gt=" + finallyPC + "; var stA0 = e; continue;");
   2.655          }
   2.656          out.append("\n}");
   2.657      }