vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 14 Jan 2013 11:30:56 +0100
branchUseFunctionCall
changeset 443 9359b006782b
parent 442 b107ed66f2e7
child 448 ac05de5a8786
permissions -rw-r--r--
Using 'this' in @JavaScriptBody instance methods
jaroslav@106
     1
/**
jaroslav@106
     2
 * Back 2 Browser Bytecode Translator
jaroslav@106
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@106
     4
 *
jaroslav@106
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@106
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@106
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@106
     8
 *
jaroslav@106
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@106
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@106
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@106
    12
 * GNU General Public License for more details.
jaroslav@106
    13
 *
jaroslav@106
    14
 * You should have received a copy of the GNU General Public License
jaroslav@106
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@106
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@106
    17
 */
jaroslav@22
    18
package org.apidesign.vm4brwsr;
jaroslav@0
    19
jaroslav@0
    20
import java.io.IOException;
jaroslav@0
    21
import java.io.InputStream;
jtulach@167
    22
import org.apidesign.javap.AnnotationParser;
jtulach@167
    23
import org.apidesign.javap.ClassData;
jtulach@167
    24
import org.apidesign.javap.FieldData;
jtulach@167
    25
import org.apidesign.javap.MethodData;
lubomir@221
    26
import org.apidesign.javap.StackMapIterator;
jtulach@167
    27
import static org.apidesign.javap.RuntimeConstants.*;
tzezula@287
    28
import org.apidesign.javap.TrapData;
jaroslav@288
    29
import org.apidesign.javap.TrapDataIterator;
jaroslav@0
    30
jaroslav@0
    31
/** Translator of the code inside class files to JavaScript.
jaroslav@0
    32
 *
jaroslav@0
    33
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@0
    34
 */
jaroslav@298
    35
abstract class ByteCodeToJavaScript {
jtulach@162
    36
    private ClassData jc;
jaroslav@272
    37
    final Appendable out;
jaroslav@0
    38
jtulach@162
    39
    protected ByteCodeToJavaScript(Appendable out) {
jaroslav@0
    40
        this.out = out;
jaroslav@0
    41
    }
jtulach@162
    42
    
jtulach@162
    43
    /* Collects additional required resources.
jtulach@162
    44
     * 
jtulach@162
    45
     * @param internalClassName classes that were referenced and should be loaded in order the
jtulach@162
    46
     *   generated JavaScript code works properly. The names are in internal 
jtulach@162
    47
     *   JVM form so String is <code>java/lang/String</code>. 
jtulach@162
    48
     */
jtulach@162
    49
    protected abstract boolean requireReference(String internalClassName);
jtulach@162
    50
    
jtulach@162
    51
    /*
jtulach@162
    52
     * @param resourcePath name of resources to read
jtulach@162
    53
     */
jtulach@162
    54
    protected abstract void requireScript(String resourcePath);
jaroslav@213
    55
    
jaroslav@213
    56
    /** Allows subclasses to redefine what field a function representing a
jaroslav@213
    57
     * class gets assigned. By default it returns the suggested name followed
jaroslav@213
    58
     * by <code>" = "</code>;
jaroslav@213
    59
     * 
jaroslav@213
    60
     * @param className suggested name of the class
jaroslav@213
    61
     */
jaroslav@274
    62
    /* protected */ String assignClass(String className) {
jaroslav@213
    63
        return className + " = ";
jaroslav@213
    64
    }
jaroslav@274
    65
    /* protected */ String accessClass(String classOperation) {
jaroslav@274
    66
        return classOperation;
jaroslav@274
    67
    }
jaroslav@399
    68
    
jaroslav@399
    69
    /** Prints out a debug message. 
jaroslav@399
    70
     * 
jaroslav@399
    71
     * @param msg the message
jaroslav@399
    72
     * @return true if the message has been printed
jaroslav@399
    73
     * @throws IOException 
jaroslav@399
    74
     */
jaroslav@399
    75
    boolean debug(String msg) throws IOException {
jaroslav@399
    76
        out.append(msg);
jaroslav@399
    77
        return true;
jaroslav@399
    78
    }
jaroslav@18
    79
jaroslav@18
    80
    /**
jaroslav@18
    81
     * Converts a given class file to a JavaScript version.
jaroslav@18
    82
     *
jaroslav@0
    83
     * @param classFile input stream with code of the .class file
jaroslav@97
    84
     * @return the initialization code for this class, if any. Otherwise <code>null</code>
jaroslav@91
    85
     * 
jaroslav@0
    86
     * @throws IOException if something goes wrong during read or write or translating
jaroslav@0
    87
     */
jaroslav@18
    88
    
jtulach@162
    89
    public String compile(InputStream classFile) throws IOException {
jtulach@162
    90
        this.jc = new ClassData(classFile);
jaroslav@324
    91
        if (jc.getMajor_version() < 50) {
jaroslav@324
    92
            throw new IOException("Can't compile " + jc.getClassName() + ". Class file version " + jc.getMajor_version() + "."
jaroslav@324
    93
                + jc.getMinor_version() + " - recompile with -target 1.6 (at least)."
jaroslav@324
    94
            );
jaroslav@324
    95
        }
jaroslav@152
    96
        byte[] arrData = jc.findAnnotationData(true);
jaroslav@170
    97
        String[] arr = findAnnotation(arrData, jc, 
jaroslav@170
    98
            "org.apidesign.bck2brwsr.core.ExtraJavaScript", 
jaroslav@170
    99
            "resource", "processByteCode"
jaroslav@170
   100
        );
jaroslav@152
   101
        if (arr != null) {
jtulach@162
   102
            requireScript(arr[0]);
jaroslav@152
   103
            if ("0".equals(arr[1])) {
jaroslav@97
   104
                return null;
jaroslav@91
   105
            }
jaroslav@91
   106
        }
jaroslav@239
   107
        String[] proto = findAnnotation(arrData, jc, 
jaroslav@239
   108
            "org.apidesign.bck2brwsr.core.JavaScriptPrototype", 
jaroslav@239
   109
            "container", "prototype"
jaroslav@239
   110
        );
jtulach@162
   111
        StringArray toInitilize = new StringArray();
jaroslav@151
   112
        final String className = className(jc);
jaroslav@213
   113
        out.append("\n\n").append(assignClass(className));
jaroslav@213
   114
        out.append("function CLS() {");
jaroslav@213
   115
        out.append("\n  if (!CLS.prototype.$instOf_").append(className).append(") {");
jtulach@191
   116
        for (FieldData v : jc.getFields()) {
jtulach@191
   117
            if (v.isStatic()) {
jaroslav@213
   118
                out.append("\n  CLS.").append(v.getName()).append(initField(v));
jtulach@191
   119
            }
jtulach@191
   120
        }
jaroslav@239
   121
        if (proto == null) {
jaroslav@239
   122
            String sc = jc.getSuperClassName(); // with _
jaroslav@230
   123
            out.append("\n    var pp = ").
jaroslav@274
   124
                append(accessClass(sc.replace('/', '_'))).append("(true);");
jaroslav@230
   125
            out.append("\n    var p = CLS.prototype = pp;");
jaroslav@239
   126
            out.append("\n    var c = p;");
jaroslav@230
   127
            out.append("\n    var sprcls = pp.constructor.$class;");
jtulach@130
   128
        } else {
jaroslav@240
   129
            out.append("\n    var p = CLS.prototype = ").append(proto[1]).append(";");
jaroslav@316
   130
            if (proto[0] == null) {
jaroslav@316
   131
                proto[0] = "p";
jaroslav@316
   132
            }
jaroslav@239
   133
            out.append("\n    var c = ").append(proto[0]).append(";");
jaroslav@230
   134
            out.append("\n    var sprcls = null;");
jaroslav@13
   135
        }
jaroslav@151
   136
        for (MethodData m : jc.getMethods()) {
jaroslav@240
   137
            byte[] onlyArr = m.findAnnotationData(true);
jaroslav@240
   138
            String[] only = findAnnotation(onlyArr, jc, 
jaroslav@240
   139
                "org.apidesign.bck2brwsr.core.JavaScriptOnly", 
jaroslav@240
   140
                "name", "value"
jaroslav@240
   141
            );
jaroslav@240
   142
            if (only != null) {
jaroslav@240
   143
                if (only[0] != null && only[1] != null) {
jaroslav@240
   144
                    out.append("\n    p.").append(only[0]).append(" = ")
jaroslav@240
   145
                        .append(only[1]).append(";");
jaroslav@240
   146
                }
jaroslav@240
   147
                continue;
jaroslav@240
   148
            }
jaroslav@397
   149
            String prefix;
jaroslav@266
   150
            String mn;
jaroslav@203
   151
            if (m.isStatic()) {
jaroslav@397
   152
                prefix = "\n    c.";
jaroslav@397
   153
                mn = generateStaticMethod(prefix, m, toInitilize);
jaroslav@203
   154
            } else {
jaroslav@397
   155
                if (m.isConstructor()) {
jaroslav@397
   156
                    prefix = "\n    CLS.";
jaroslav@397
   157
                    mn = generateInstanceMethod(prefix, m);
jaroslav@397
   158
                } else {
jaroslav@397
   159
                    prefix = "\n    c.";
jaroslav@397
   160
                    mn = generateInstanceMethod(prefix, m);
jaroslav@397
   161
                }
jaroslav@266
   162
            }
jaroslav@266
   163
            byte[] runAnno = m.findAnnotationData(false);
jaroslav@266
   164
            if (runAnno != null) {
jaroslav@397
   165
                out.append(prefix).append(mn).append(".anno = {");
jaroslav@266
   166
                generateAnno(jc, out, runAnno);
jaroslav@266
   167
                out.append("\n    };");
jaroslav@38
   168
            }
jaroslav@397
   169
            out.append(prefix).append(mn).append(".access = " + m.getAccess()).append(";");
jaroslav@38
   170
        }
jaroslav@239
   171
        out.append("\n    c.constructor = CLS;");
jaroslav@239
   172
        out.append("\n    c.$instOf_").append(className).append(" = true;");
jaroslav@151
   173
        for (String superInterface : jc.getSuperInterfaces()) {
jaroslav@239
   174
            out.append("\n    c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
jaroslav@40
   175
        }
jaroslav@274
   176
        out.append("\n    CLS.$class = ");
jaroslav@274
   177
        out.append(accessClass("java_lang_Class(true);"));
jaroslav@225
   178
        out.append("\n    CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
jaroslav@230
   179
        out.append("\n    CLS.$class.superclass = sprcls;");
jaroslav@355
   180
        out.append("\n    CLS.$class.access = ").append(jc.getAccessFlags()+";");
jaroslav@231
   181
        out.append("\n    CLS.$class.cnstr = CLS;");
jaroslav@235
   182
        byte[] classAnno = jc.findAnnotationData(false);
jaroslav@235
   183
        if (classAnno != null) {
jaroslav@235
   184
            out.append("\n    CLS.$class.anno = {");
jaroslav@235
   185
            generateAnno(jc, out, classAnno);
jaroslav@235
   186
            out.append("\n    };");
jaroslav@235
   187
        }
jaroslav@204
   188
        out.append("\n  }");
jaroslav@205
   189
        out.append("\n  if (arguments.length === 0) {");
jaroslav@226
   190
        out.append("\n    if (!(this instanceof CLS)) {");
jaroslav@226
   191
        out.append("\n      return new CLS();");
jaroslav@226
   192
        out.append("\n    }");
jaroslav@205
   193
        for (FieldData v : jc.getFields()) {
jaroslav@240
   194
            byte[] onlyArr = v.findAnnotationData(true);
jaroslav@240
   195
            String[] only = findAnnotation(onlyArr, jc, 
jaroslav@240
   196
                "org.apidesign.bck2brwsr.core.JavaScriptOnly", 
jaroslav@240
   197
                "name", "value"
jaroslav@240
   198
            );
jaroslav@240
   199
            if (only != null) {
jaroslav@240
   200
                if (only[0] != null && only[1] != null) {
jaroslav@240
   201
                    out.append("\n    p.").append(only[0]).append(" = ")
jaroslav@240
   202
                        .append(only[1]).append(";");
jaroslav@240
   203
                }
jaroslav@240
   204
                continue;
jaroslav@240
   205
            }
jaroslav@205
   206
            if (!v.isStatic()) {
jaroslav@205
   207
                out.append("\n    this.fld_").
jaroslav@205
   208
                    append(v.getName()).append(initField(v));
jaroslav@205
   209
            }
jaroslav@205
   210
        }
jaroslav@205
   211
        out.append("\n    return this;");
jaroslav@205
   212
        out.append("\n  }");
jaroslav@224
   213
        out.append("\n  return arguments[0] ? new CLS() : CLS.prototype;");
jaroslav@98
   214
        out.append("\n}");
jaroslav@97
   215
        StringBuilder sb = new StringBuilder();
jtulach@162
   216
        for (String init : toInitilize.toArray()) {
jaroslav@97
   217
            sb.append("\n").append(init).append("();");
jaroslav@21
   218
        }
jaroslav@97
   219
        return sb.toString();
jaroslav@0
   220
    }
jaroslav@266
   221
    private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
jaroslav@266
   222
        String jsb = javaScriptBody(prefix, m, true);
jaroslav@266
   223
        if (jsb != null) {
jaroslav@266
   224
            return jsb;
jaroslav@94
   225
        }
lubomir@307
   226
        final String mn = findMethodName(m, new StringBuilder());
jaroslav@248
   227
        if (mn.equals("class__V")) {
jaroslav@274
   228
            toInitilize.add(accessClass(className(jc)) + "(false)." + mn);
jaroslav@21
   229
        }
lubomir@307
   230
        generateMethod(prefix, mn, m);
jaroslav@266
   231
        return mn;
jaroslav@10
   232
    }
lubomir@307
   233
jaroslav@266
   234
    private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
jaroslav@266
   235
        String jsb = javaScriptBody(prefix, m, false);
jaroslav@266
   236
        if (jsb != null) {
jaroslav@266
   237
            return jsb;
jaroslav@94
   238
        }
lubomir@307
   239
        final String mn = findMethodName(m, new StringBuilder());
lubomir@307
   240
        generateMethod(prefix, mn, m);
jaroslav@266
   241
        return mn;
jaroslav@0
   242
    }
jaroslav@0
   243
lubomir@307
   244
    private void generateMethod(String prefix, String name, MethodData m)
lubomir@307
   245
            throws IOException {
lubomir@307
   246
        final StackMapIterator stackMapIterator = m.createStackMapIterator();
jaroslav@376
   247
        TrapDataIterator trap = m.getTrapDataIterator();
lubomir@307
   248
        final LocalsMapper lmapper =
lubomir@307
   249
                new LocalsMapper(stackMapIterator.getArguments());
lubomir@307
   250
lubomir@307
   251
        out.append(prefix).append(name).append(" = function(");
jaroslav@442
   252
        lmapper.outputArguments(out, m.isStatic());
lubomir@307
   253
        out.append(") {").append("\n");
lubomir@307
   254
lubomir@221
   255
        final byte[] byteCodes = m.getCode();
lubomir@307
   256
        if (byteCodes == null) {
lubomir@307
   257
            out.append("  throw 'no code found for ")
jaroslav@424
   258
               .append(jc.getClassName()).append('.')
jaroslav@424
   259
               .append(m.getName()).append("';\n");
lubomir@307
   260
            out.append("};");
lubomir@307
   261
            return;
lubomir@307
   262
        }
lubomir@307
   263
lubomir@307
   264
        final StackMapper smapper = new StackMapper();
lubomir@307
   265
lubomir@307
   266
        final int maxLocals = m.getMaxLocals();
lubomir@307
   267
        if (maxLocals > 0) {
lubomir@307
   268
            // TODO: generate only used local variables
lubomir@307
   269
            for (int j = 0; j <= VarType.LAST; ++j) {
lubomir@307
   270
                out.append("\n  var ").append(Variable.getLocalVariable(j, 0));
lubomir@307
   271
                for (int i = 1; i < maxLocals; ++i) {
lubomir@307
   272
                    out.append(", ");
lubomir@307
   273
                    out.append(Variable.getLocalVariable(j, i));
lubomir@307
   274
                }
lubomir@307
   275
                out.append(';');
lubomir@307
   276
            }
lubomir@307
   277
        }
jaroslav@442
   278
        if (!m.isStatic()) {
jaroslav@442
   279
            out.append("  var ").append(" lcA0 = this;\n");
jaroslav@442
   280
        }
lubomir@221
   281
lubomir@221
   282
        // maxStack includes two stack positions for every pushed long / double
lubomir@221
   283
        // so this might generate more stack variables than we need
lubomir@221
   284
        final int maxStack = m.getMaxStack();
lubomir@221
   285
        if (maxStack > 0) {
lubomir@281
   286
            // TODO: generate only used stack variables
lubomir@307
   287
            for (int j = 0; j <= VarType.LAST; ++j) {
lubomir@281
   288
                out.append("\n  var ").append(Variable.getStackVariable(j, 0));
lubomir@281
   289
                for (int i = 1; i < maxStack; ++i) {
lubomir@281
   290
                    out.append(", ");
lubomir@281
   291
                    out.append(Variable.getStackVariable(j, i));
lubomir@281
   292
                }
lubomir@281
   293
                out.append(';');
lubomir@221
   294
            }
lubomir@221
   295
        }
lubomir@221
   296
lubomir@221
   297
        int lastStackFrame = -1;
jaroslav@398
   298
        TrapData[] previousTrap = null;
jaroslav@398
   299
        
jaroslav@10
   300
        out.append("\n  var gt = 0;\n  for(;;) switch(gt) {\n");
jaroslav@0
   301
        for (int i = 0; i < byteCodes.length; i++) {
jaroslav@272
   302
            int prev = i;
lubomir@221
   303
            stackMapIterator.advanceTo(i);
jaroslav@398
   304
            boolean changeInCatch = trap.advanceTo(i);
jaroslav@398
   305
            if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) {
jaroslav@398
   306
                if (previousTrap != null) {
jaroslav@398
   307
                    generateCatch(previousTrap);
jaroslav@398
   308
                    previousTrap = null;
jaroslav@398
   309
                }
jaroslav@398
   310
            }
lubomir@221
   311
            if (lastStackFrame != stackMapIterator.getFrameIndex()) {
lubomir@221
   312
                lastStackFrame = stackMapIterator.getFrameIndex();
lubomir@307
   313
                lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
lubomir@307
   314
                smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
jaroslav@376
   315
                out.append("    case " + i).append(": ");            
jaroslav@398
   316
                changeInCatch = true;
lubomir@221
   317
            } else {
jaroslav@399
   318
                debug("    /* " + i + " */ ");
lubomir@221
   319
            }
jaroslav@398
   320
            if (changeInCatch && trap.useTry()) {
tzezula@285
   321
                out.append("try {");
jaroslav@398
   322
                previousTrap = trap.current();
tzezula@285
   323
            }
jtulach@128
   324
            final int c = readByte(byteCodes, i);
jaroslav@0
   325
            switch (c) {
jaroslav@151
   326
                case opc_aload_0:
lubomir@307
   327
                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(0));
lubomir@281
   328
                    break;
jaroslav@151
   329
                case opc_iload_0:
lubomir@307
   330
                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(0));
lubomir@281
   331
                    break;
jaroslav@151
   332
                case opc_lload_0:
lubomir@307
   333
                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(0));
lubomir@281
   334
                    break;
jaroslav@151
   335
                case opc_fload_0:
lubomir@307
   336
                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(0));
lubomir@281
   337
                    break;
jaroslav@151
   338
                case opc_dload_0:
lubomir@307
   339
                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(0));
jaroslav@0
   340
                    break;
jaroslav@151
   341
                case opc_aload_1:
lubomir@307
   342
                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(1));
lubomir@281
   343
                    break;
jaroslav@151
   344
                case opc_iload_1:
lubomir@307
   345
                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(1));
lubomir@281
   346
                    break;
jaroslav@151
   347
                case opc_lload_1:
lubomir@307
   348
                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(1));
lubomir@281
   349
                    break;
jaroslav@151
   350
                case opc_fload_1:
lubomir@307
   351
                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(1));
lubomir@281
   352
                    break;
jaroslav@151
   353
                case opc_dload_1:
lubomir@307
   354
                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(1));
jaroslav@0
   355
                    break;
jaroslav@151
   356
                case opc_aload_2:
lubomir@307
   357
                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(2));
lubomir@281
   358
                    break;
jaroslav@151
   359
                case opc_iload_2:
lubomir@307
   360
                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(2));
lubomir@281
   361
                    break;
jaroslav@151
   362
                case opc_lload_2:
lubomir@307
   363
                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(2));
lubomir@281
   364
                    break;
jaroslav@151
   365
                case opc_fload_2:
lubomir@307
   366
                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(2));
lubomir@281
   367
                    break;
jaroslav@151
   368
                case opc_dload_2:
lubomir@307
   369
                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(2));
jaroslav@2
   370
                    break;
jaroslav@151
   371
                case opc_aload_3:
lubomir@307
   372
                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(3));
lubomir@281
   373
                    break;
jaroslav@151
   374
                case opc_iload_3:
lubomir@307
   375
                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(3));
lubomir@281
   376
                    break;
jaroslav@151
   377
                case opc_lload_3:
lubomir@307
   378
                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(3));
lubomir@281
   379
                    break;
jaroslav@151
   380
                case opc_fload_3:
lubomir@307
   381
                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(3));
lubomir@281
   382
                    break;
jaroslav@151
   383
                case opc_dload_3:
lubomir@307
   384
                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(3));
jaroslav@3
   385
                    break;
lubomir@281
   386
                case opc_iload: {
lubomir@281
   387
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   388
                    emit(out, "@1 = @2;", smapper.pushI(), lmapper.getI(indx));
lubomir@281
   389
                    break;
lubomir@281
   390
                }
lubomir@281
   391
                case opc_lload: {
lubomir@281
   392
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   393
                    emit(out, "@1 = @2;", smapper.pushL(), lmapper.getL(indx));
lubomir@281
   394
                    break;
lubomir@281
   395
                }
lubomir@281
   396
                case opc_fload: {
lubomir@281
   397
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   398
                    emit(out, "@1 = @2;", smapper.pushF(), lmapper.getF(indx));
lubomir@281
   399
                    break;
lubomir@281
   400
                }
lubomir@281
   401
                case opc_dload: {
lubomir@281
   402
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   403
                    emit(out, "@1 = @2;", smapper.pushD(), lmapper.getD(indx));
lubomir@281
   404
                    break;
lubomir@281
   405
                }
jaroslav@151
   406
                case opc_aload: {
jtulach@128
   407
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   408
                    emit(out, "@1 = @2;", smapper.pushA(), lmapper.getA(indx));
jaroslav@3
   409
                    break;
jaroslav@3
   410
                }
lubomir@281
   411
                case opc_istore: {
lubomir@281
   412
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   413
                    emit(out, "@1 = @2;", lmapper.setI(indx), smapper.popI());
lubomir@281
   414
                    break;
lubomir@281
   415
                }
lubomir@281
   416
                case opc_lstore: {
lubomir@281
   417
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   418
                    emit(out, "@1 = @2;", lmapper.setL(indx), smapper.popL());
lubomir@281
   419
                    break;
lubomir@281
   420
                }
lubomir@281
   421
                case opc_fstore: {
lubomir@281
   422
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   423
                    emit(out, "@1 = @2;", lmapper.setF(indx), smapper.popF());
lubomir@281
   424
                    break;
lubomir@281
   425
                }
lubomir@281
   426
                case opc_dstore: {
lubomir@281
   427
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   428
                    emit(out, "@1 = @2;", lmapper.setD(indx), smapper.popD());
lubomir@281
   429
                    break;
lubomir@281
   430
                }
jaroslav@151
   431
                case opc_astore: {
jtulach@128
   432
                    final int indx = readByte(byteCodes, ++i);
lubomir@307
   433
                    emit(out, "@1 = @2;", lmapper.setA(indx), smapper.popA());
jaroslav@31
   434
                    break;
jaroslav@31
   435
                }
jaroslav@151
   436
                case opc_astore_0:
lubomir@307
   437
                    emit(out, "@1 = @2;", lmapper.setA(0), smapper.popA());
lubomir@281
   438
                    break;
jaroslav@151
   439
                case opc_istore_0:
lubomir@307
   440
                    emit(out, "@1 = @2;", lmapper.setI(0), smapper.popI());
lubomir@281
   441
                    break;
jaroslav@151
   442
                case opc_lstore_0:
lubomir@307
   443
                    emit(out, "@1 = @2;", lmapper.setL(0), smapper.popL());
lubomir@281
   444
                    break;
jaroslav@151
   445
                case opc_fstore_0:
lubomir@307
   446
                    emit(out, "@1 = @2;", lmapper.setF(0), smapper.popF());
lubomir@281
   447
                    break;
jaroslav@151
   448
                case opc_dstore_0:
lubomir@307
   449
                    emit(out, "@1 = @2;", lmapper.setD(0), smapper.popD());
jaroslav@5
   450
                    break;
jaroslav@151
   451
                case opc_astore_1:
lubomir@307
   452
                    emit(out, "@1 = @2;", lmapper.setA(1), smapper.popA());
lubomir@281
   453
                    break;
jaroslav@151
   454
                case opc_istore_1:
lubomir@307
   455
                    emit(out, "@1 = @2;", lmapper.setI(1), smapper.popI());
lubomir@281
   456
                    break;
jaroslav@151
   457
                case opc_lstore_1:
lubomir@307
   458
                    emit(out, "@1 = @2;", lmapper.setL(1), smapper.popL());
lubomir@281
   459
                    break;
jaroslav@151
   460
                case opc_fstore_1:
lubomir@307
   461
                    emit(out, "@1 = @2;", lmapper.setF(1), smapper.popF());
lubomir@281
   462
                    break;
jaroslav@151
   463
                case opc_dstore_1:
lubomir@307
   464
                    emit(out, "@1 = @2;", lmapper.setD(1), smapper.popD());
jaroslav@5
   465
                    break;
jaroslav@151
   466
                case opc_astore_2:
lubomir@307
   467
                    emit(out, "@1 = @2;", lmapper.setA(2), smapper.popA());
lubomir@281
   468
                    break;
jaroslav@151
   469
                case opc_istore_2:
lubomir@307
   470
                    emit(out, "@1 = @2;", lmapper.setI(2), smapper.popI());
lubomir@281
   471
                    break;
jaroslav@151
   472
                case opc_lstore_2:
lubomir@307
   473
                    emit(out, "@1 = @2;", lmapper.setL(2), smapper.popL());
lubomir@281
   474
                    break;
jaroslav@151
   475
                case opc_fstore_2:
lubomir@307
   476
                    emit(out, "@1 = @2;", lmapper.setF(2), smapper.popF());
lubomir@281
   477
                    break;
jaroslav@151
   478
                case opc_dstore_2:
lubomir@307
   479
                    emit(out, "@1 = @2;", lmapper.setD(2), smapper.popD());
jaroslav@5
   480
                    break;
jaroslav@151
   481
                case opc_astore_3:
lubomir@307
   482
                    emit(out, "@1 = @2;", lmapper.setA(3), smapper.popA());
lubomir@281
   483
                    break;
jaroslav@151
   484
                case opc_istore_3:
lubomir@307
   485
                    emit(out, "@1 = @2;", lmapper.setI(3), smapper.popI());
lubomir@281
   486
                    break;
jaroslav@151
   487
                case opc_lstore_3:
lubomir@307
   488
                    emit(out, "@1 = @2;", lmapper.setL(3), smapper.popL());
lubomir@281
   489
                    break;
jaroslav@151
   490
                case opc_fstore_3:
lubomir@307
   491
                    emit(out, "@1 = @2;", lmapper.setF(3), smapper.popF());
lubomir@281
   492
                    break;
jaroslav@151
   493
                case opc_dstore_3:
lubomir@307
   494
                    emit(out, "@1 = @2;", lmapper.setD(3), smapper.popD());
jaroslav@5
   495
                    break;
jaroslav@151
   496
                case opc_iadd:
Martin@351
   497
                    emit(out, "@1 = (@1 + @2) | 0;", smapper.getI(1), smapper.popI());
lubomir@281
   498
                    break;
jaroslav@151
   499
                case opc_ladd:
lubomir@307
   500
                    emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
lubomir@281
   501
                    break;
jaroslav@151
   502
                case opc_fadd:
lubomir@307
   503
                    emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
lubomir@281
   504
                    break;
jaroslav@151
   505
                case opc_dadd:
lubomir@307
   506
                    emit(out, "@1 += @2;", smapper.getD(1), smapper.popD());
jaroslav@0
   507
                    break;
jaroslav@151
   508
                case opc_isub:
Martin@351
   509
                    emit(out, "@1 = (@1 - @2) | 0;", smapper.getI(1), smapper.popI());
lubomir@281
   510
                    break;
jaroslav@151
   511
                case opc_lsub:
lubomir@307
   512
                    emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
lubomir@281
   513
                    break;
jaroslav@151
   514
                case opc_fsub:
lubomir@307
   515
                    emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
lubomir@281
   516
                    break;
jaroslav@151
   517
                case opc_dsub:
lubomir@307
   518
                    emit(out, "@1 -= @2;", smapper.getD(1), smapper.popD());
jaroslav@2
   519
                    break;
jaroslav@151
   520
                case opc_imul:
Martin@351
   521
                    emit(out, "@1 = (((@1 * (@2 >> 16)) << 16) + @1 * (@2 & 0xFFFF)) | 0;", smapper.getI(1), smapper.popI());
lubomir@281
   522
                    break;
jaroslav@151
   523
                case opc_lmul:
lubomir@307
   524
                    emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
lubomir@281
   525
                    break;
jaroslav@151
   526
                case opc_fmul:
lubomir@307
   527
                    emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
lubomir@281
   528
                    break;
jaroslav@151
   529
                case opc_dmul:
lubomir@307
   530
                    emit(out, "@1 *= @2;", smapper.getD(1), smapper.popD());
jaroslav@1
   531
                    break;
jaroslav@151
   532
                case opc_idiv:
lubomir@283
   533
                    emit(out, "@1 = Math.floor(@1 / @2);",
lubomir@307
   534
                         smapper.getI(1), smapper.popI());
lubomir@281
   535
                    break;
jaroslav@151
   536
                case opc_ldiv:
lubomir@283
   537
                    emit(out, "@1 = Math.floor(@1 / @2);",
lubomir@307
   538
                         smapper.getL(1), smapper.popL());
jaroslav@3
   539
                    break;
jaroslav@151
   540
                case opc_fdiv:
lubomir@307
   541
                    emit(out, "@1 /= @2;", smapper.getF(1), smapper.popF());
lubomir@281
   542
                    break;
jaroslav@151
   543
                case opc_ddiv:
lubomir@307
   544
                    emit(out, "@1 /= @2;", smapper.getD(1), smapper.popD());
jaroslav@3
   545
                    break;
jaroslav@178
   546
                case opc_irem:
lubomir@307
   547
                    emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   548
                    break;
jaroslav@178
   549
                case opc_lrem:
lubomir@307
   550
                    emit(out, "@1 %= @2;", smapper.getL(1), smapper.popL());
lubomir@281
   551
                    break;
jaroslav@178
   552
                case opc_frem:
lubomir@307
   553
                    emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
lubomir@281
   554
                    break;
jaroslav@178
   555
                case opc_drem:
lubomir@307
   556
                    emit(out, "@1 %= @2;", smapper.getD(1), smapper.popD());
jaroslav@178
   557
                    break;
jaroslav@151
   558
                case opc_iand:
lubomir@307
   559
                    emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   560
                    break;
jaroslav@151
   561
                case opc_land:
lubomir@307
   562
                    emit(out, "@1 &= @2;", smapper.getL(1), smapper.popL());
jaroslav@7
   563
                    break;
jaroslav@151
   564
                case opc_ior:
lubomir@307
   565
                    emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   566
                    break;
jaroslav@151
   567
                case opc_lor:
lubomir@307
   568
                    emit(out, "@1 |= @2;", smapper.getL(1), smapper.popL());
jaroslav@7
   569
                    break;
jaroslav@151
   570
                case opc_ixor:
lubomir@307
   571
                    emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   572
                    break;
jaroslav@151
   573
                case opc_lxor:
lubomir@307
   574
                    emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
jaroslav@6
   575
                    break;
jaroslav@151
   576
                case opc_ineg:
lubomir@307
   577
                    emit(out, "@1 = -@1;", smapper.getI(0));
lubomir@281
   578
                    break;
jaroslav@151
   579
                case opc_lneg:
lubomir@307
   580
                    emit(out, "@1 = -@1;", smapper.getL(0));
lubomir@281
   581
                    break;
jaroslav@151
   582
                case opc_fneg:
lubomir@307
   583
                    emit(out, "@1 = -@1;", smapper.getF(0));
lubomir@281
   584
                    break;
jaroslav@151
   585
                case opc_dneg:
lubomir@307
   586
                    emit(out, "@1 = -@1;", smapper.getD(0));
jaroslav@93
   587
                    break;
jaroslav@151
   588
                case opc_ishl:
lubomir@307
   589
                    emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   590
                    break;
jaroslav@151
   591
                case opc_lshl:
lubomir@307
   592
                    emit(out, "@1 <<= @2;", smapper.getL(1), smapper.popI());
jaroslav@93
   593
                    break;
jaroslav@151
   594
                case opc_ishr:
lubomir@307
   595
                    emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   596
                    break;
jaroslav@151
   597
                case opc_lshr:
lubomir@307
   598
                    emit(out, "@1 >>= @2;", smapper.getL(1), smapper.popI());
jaroslav@93
   599
                    break;
jaroslav@151
   600
                case opc_iushr:
lubomir@307
   601
                    emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
lubomir@281
   602
                    break;
jaroslav@151
   603
                case opc_lushr:
lubomir@307
   604
                    emit(out, "@1 >>>= @2;", smapper.getL(1), smapper.popI());
jaroslav@93
   605
                    break;
jaroslav@151
   606
                case opc_iinc: {
jtulach@128
   607
                    final int varIndx = readByte(byteCodes, ++i);
jaroslav@104
   608
                    final int incrBy = byteCodes[++i];
jaroslav@5
   609
                    if (incrBy == 1) {
lubomir@307
   610
                        emit(out, "@1++;", lmapper.getI(varIndx));
jaroslav@5
   611
                    } else {
lubomir@307
   612
                        emit(out, "@1 += @2;",
lubomir@307
   613
                             lmapper.getI(varIndx),
lubomir@283
   614
                             Integer.toString(incrBy));
jaroslav@5
   615
                    }
jaroslav@5
   616
                    break;
jaroslav@5
   617
                }
jaroslav@151
   618
                case opc_return:
lubomir@283
   619
                    emit(out, "return;");
jaroslav@10
   620
                    break;
jaroslav@151
   621
                case opc_ireturn:
lubomir@307
   622
                    emit(out, "return @1;", smapper.popI());
lubomir@281
   623
                    break;
jaroslav@151
   624
                case opc_lreturn:
lubomir@307
   625
                    emit(out, "return @1;", smapper.popL());
lubomir@281
   626
                    break;
jaroslav@151
   627
                case opc_freturn:
lubomir@307
   628
                    emit(out, "return @1;", smapper.popF());
lubomir@281
   629
                    break;
jaroslav@151
   630
                case opc_dreturn:
lubomir@307
   631
                    emit(out, "return @1;", smapper.popD());
lubomir@281
   632
                    break;
jaroslav@151
   633
                case opc_areturn:
lubomir@307
   634
                    emit(out, "return @1;", smapper.popA());
jaroslav@1
   635
                    break;
jaroslav@151
   636
                case opc_i2l:
lubomir@307
   637
                    emit(out, "@2 = @1;", smapper.popI(), smapper.pushL());
lubomir@281
   638
                    break;
jaroslav@151
   639
                case opc_i2f:
lubomir@307
   640
                    emit(out, "@2 = @1;", smapper.popI(), smapper.pushF());
lubomir@281
   641
                    break;
jaroslav@151
   642
                case opc_i2d:
lubomir@307
   643
                    emit(out, "@2 = @1;", smapper.popI(), smapper.pushD());
lubomir@281
   644
                    break;
jaroslav@151
   645
                case opc_l2i:
lubomir@307
   646
                    emit(out, "@2 = @1;", smapper.popL(), smapper.pushI());
lubomir@281
   647
                    break;
jaroslav@3
   648
                    // max int check?
jaroslav@151
   649
                case opc_l2f:
lubomir@307
   650
                    emit(out, "@2 = @1;", smapper.popL(), smapper.pushF());
jaroslav@272
   651
                    break;
jaroslav@151
   652
                case opc_l2d:
lubomir@307
   653
                    emit(out, "@2 = @1;", smapper.popL(), smapper.pushD());
jaroslav@272
   654
                    break;
jaroslav@151
   655
                case opc_f2d:
lubomir@307
   656
                    emit(out, "@2 = @1;", smapper.popF(), smapper.pushD());
lubomir@281
   657
                    break;
jaroslav@151
   658
                case opc_d2f:
lubomir@307
   659
                    emit(out, "@2 = @1;", smapper.popD(), smapper.pushF());
jaroslav@3
   660
                    break;
jaroslav@151
   661
                case opc_f2i:
lubomir@283
   662
                    emit(out, "@2 = Math.floor(@1);",
lubomir@307
   663
                         smapper.popF(), smapper.pushI());
lubomir@281
   664
                    break;
jaroslav@151
   665
                case opc_f2l:
lubomir@283
   666
                    emit(out, "@2 = Math.floor(@1);",
lubomir@307
   667
                         smapper.popF(), smapper.pushL());
lubomir@281
   668
                    break;
jaroslav@151
   669
                case opc_d2i:
lubomir@283
   670
                    emit(out, "@2 = Math.floor(@1);",
lubomir@307
   671
                         smapper.popD(), smapper.pushI());
lubomir@281
   672
                    break;
jaroslav@151
   673
                case opc_d2l:
lubomir@283
   674
                    emit(out, "@2 = Math.floor(@1);",
lubomir@307
   675
                         smapper.popD(), smapper.pushL());
jaroslav@3
   676
                    break;
jaroslav@151
   677
                case opc_i2b:
jaroslav@151
   678
                case opc_i2c:
jaroslav@151
   679
                case opc_i2s:
jaroslav@337
   680
                    out.append("{ /* number conversion */ }");
jaroslav@2
   681
                    break;
jaroslav@151
   682
                case opc_aconst_null:
lubomir@307
   683
                    emit(out, "@1 = null;", smapper.pushA());
jaroslav@46
   684
                    break;
jaroslav@151
   685
                case opc_iconst_m1:
lubomir@307
   686
                    emit(out, "@1 = -1;", smapper.pushI());
jaroslav@48
   687
                    break;
jaroslav@151
   688
                case opc_iconst_0:
lubomir@307
   689
                    emit(out, "@1 = 0;", smapper.pushI());
lubomir@281
   690
                    break;
jaroslav@151
   691
                case opc_dconst_0:
lubomir@307
   692
                    emit(out, "@1 = 0;", smapper.pushD());
lubomir@281
   693
                    break;
jaroslav@151
   694
                case opc_lconst_0:
lubomir@307
   695
                    emit(out, "@1 = 0;", smapper.pushL());
lubomir@281
   696
                    break;
jaroslav@151
   697
                case opc_fconst_0:
lubomir@307
   698
                    emit(out, "@1 = 0;", smapper.pushF());
jaroslav@4
   699
                    break;
jaroslav@151
   700
                case opc_iconst_1:
lubomir@307
   701
                    emit(out, "@1 = 1;", smapper.pushI());
lubomir@281
   702
                    break;
jaroslav@151
   703
                case opc_lconst_1:
lubomir@307
   704
                    emit(out, "@1 = 1;", smapper.pushL());
lubomir@281
   705
                    break;
jaroslav@151
   706
                case opc_fconst_1:
lubomir@307
   707
                    emit(out, "@1 = 1;", smapper.pushF());
lubomir@281
   708
                    break;
jaroslav@151
   709
                case opc_dconst_1:
lubomir@307
   710
                    emit(out, "@1 = 1;", smapper.pushD());
jaroslav@4
   711
                    break;
jaroslav@151
   712
                case opc_iconst_2:
lubomir@307
   713
                    emit(out, "@1 = 2;", smapper.pushI());
lubomir@281
   714
                    break;
jaroslav@151
   715
                case opc_fconst_2:
lubomir@307
   716
                    emit(out, "@1 = 2;", smapper.pushF());
jaroslav@4
   717
                    break;
jaroslav@151
   718
                case opc_iconst_3:
lubomir@307
   719
                    emit(out, "@1 = 3;", smapper.pushI());
jaroslav@4
   720
                    break;
jaroslav@151
   721
                case opc_iconst_4:
lubomir@307
   722
                    emit(out, "@1 = 4;", smapper.pushI());
jaroslav@4
   723
                    break;
jaroslav@151
   724
                case opc_iconst_5:
lubomir@307
   725
                    emit(out, "@1 = 5;", smapper.pushI());
jaroslav@4
   726
                    break;
jaroslav@151
   727
                case opc_ldc: {
jtulach@128
   728
                    int indx = readByte(byteCodes, ++i);
jaroslav@151
   729
                    String v = encodeConstant(indx);
lubomir@307
   730
                    int type = VarType.fromConstantType(jc.getTag(indx));
lubomir@307
   731
                    emit(out, "@1 = @2;", smapper.pushT(type), v);
jaroslav@20
   732
                    break;
jaroslav@20
   733
                }
jaroslav@151
   734
                case opc_ldc_w:
jaroslav@151
   735
                case opc_ldc2_w: {
jaroslav@8
   736
                    int indx = readIntArg(byteCodes, i);
jaroslav@8
   737
                    i += 2;
jaroslav@151
   738
                    String v = encodeConstant(indx);
lubomir@307
   739
                    int type = VarType.fromConstantType(jc.getTag(indx));
lubomir@307
   740
                    emit(out, "@1 = @2;", smapper.pushT(type), v);
jaroslav@8
   741
                    break;
jaroslav@8
   742
                }
jaroslav@151
   743
                case opc_lcmp:
lubomir@283
   744
                    emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
lubomir@307
   745
                         smapper.popL(), smapper.popL(), smapper.pushI());
lubomir@281
   746
                    break;
jaroslav@151
   747
                case opc_fcmpl:
jaroslav@151
   748
                case opc_fcmpg:
lubomir@283
   749
                    emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
lubomir@307
   750
                         smapper.popF(), smapper.popF(), smapper.pushI());
lubomir@281
   751
                    break;
jaroslav@151
   752
                case opc_dcmpl:
lubomir@281
   753
                case opc_dcmpg:
lubomir@283
   754
                    emit(out, "@3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
lubomir@307
   755
                         smapper.popD(), smapper.popD(), smapper.pushI());
jaroslav@20
   756
                    break;
jaroslav@151
   757
                case opc_if_acmpeq:
lubomir@307
   758
                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
lubomir@281
   759
                                   "===");
jaroslav@104
   760
                    break;
jaroslav@151
   761
                case opc_if_acmpne:
lubomir@307
   762
                    i = generateIf(byteCodes, i, smapper.popA(), smapper.popA(),
lubomir@281
   763
                                   "!=");
jaroslav@104
   764
                    break;
lubomir@283
   765
                case opc_if_icmpeq:
lubomir@307
   766
                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
lubomir@281
   767
                                   "==");
jaroslav@4
   768
                    break;
jaroslav@151
   769
                case opc_ifeq: {
jaroslav@7
   770
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   771
                    emit(out, "if (@1 == 0) { gt = @2; continue; }",
lubomir@307
   772
                         smapper.popI(), Integer.toString(indx));
jaroslav@7
   773
                    i += 2;
jaroslav@7
   774
                    break;
jaroslav@7
   775
                }
jaroslav@151
   776
                case opc_ifne: {
jaroslav@20
   777
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   778
                    emit(out, "if (@1 != 0) { gt = @2; continue; }",
lubomir@307
   779
                         smapper.popI(), Integer.toString(indx));
jaroslav@20
   780
                    i += 2;
jaroslav@20
   781
                    break;
jaroslav@20
   782
                }
jaroslav@151
   783
                case opc_iflt: {
jaroslav@20
   784
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   785
                    emit(out, "if (@1 < 0) { gt = @2; continue; }",
lubomir@307
   786
                         smapper.popI(), Integer.toString(indx));
jaroslav@20
   787
                    i += 2;
jaroslav@20
   788
                    break;
jaroslav@20
   789
                }
jaroslav@151
   790
                case opc_ifle: {
jaroslav@20
   791
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   792
                    emit(out, "if (@1 <= 0) { gt = @2; continue; }",
lubomir@307
   793
                         smapper.popI(), Integer.toString(indx));
jaroslav@20
   794
                    i += 2;
jaroslav@20
   795
                    break;
jaroslav@20
   796
                }
jaroslav@151
   797
                case opc_ifgt: {
jaroslav@20
   798
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   799
                    emit(out, "if (@1 > 0) { gt = @2; continue; }",
lubomir@307
   800
                         smapper.popI(), Integer.toString(indx));
jaroslav@20
   801
                    i += 2;
jaroslav@20
   802
                    break;
jaroslav@20
   803
                }
jaroslav@151
   804
                case opc_ifge: {
jaroslav@20
   805
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   806
                    emit(out, "if (@1 >= 0) { gt = @2; continue; }",
lubomir@307
   807
                         smapper.popI(), Integer.toString(indx));
jaroslav@20
   808
                    i += 2;
jaroslav@20
   809
                    break;
jaroslav@20
   810
                }
jaroslav@151
   811
                case opc_ifnonnull: {
jaroslav@16
   812
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   813
                    emit(out, "if (@1 !== null) { gt = @2; continue; }",
lubomir@307
   814
                         smapper.popA(), Integer.toString(indx));
jaroslav@16
   815
                    i += 2;
jaroslav@16
   816
                    break;
jaroslav@16
   817
                }
jaroslav@151
   818
                case opc_ifnull: {
jaroslav@16
   819
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   820
                    emit(out, "if (@1 === null) { gt = @2; continue; }",
lubomir@307
   821
                         smapper.popA(), Integer.toString(indx));
jaroslav@16
   822
                    i += 2;
jaroslav@16
   823
                    break;
jaroslav@16
   824
                }
jaroslav@151
   825
                case opc_if_icmpne:
lubomir@307
   826
                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
lubomir@281
   827
                                   "!=");
jaroslav@4
   828
                    break;
jaroslav@151
   829
                case opc_if_icmplt:
lubomir@307
   830
                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
lubomir@281
   831
                                   "<");
jaroslav@4
   832
                    break;
jaroslav@151
   833
                case opc_if_icmple:
lubomir@307
   834
                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
lubomir@281
   835
                                   "<=");
jaroslav@4
   836
                    break;
jaroslav@151
   837
                case opc_if_icmpgt:
lubomir@307
   838
                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
lubomir@281
   839
                                   ">");
jaroslav@4
   840
                    break;
jaroslav@151
   841
                case opc_if_icmpge:
lubomir@307
   842
                    i = generateIf(byteCodes, i, smapper.popI(), smapper.popI(),
lubomir@281
   843
                                   ">=");
jaroslav@4
   844
                    break;
jaroslav@151
   845
                case opc_goto: {
jaroslav@5
   846
                    int indx = i + readIntArg(byteCodes, i);
lubomir@283
   847
                    emit(out, "gt = @1; continue;", Integer.toString(indx));
jaroslav@5
   848
                    i += 2;
jaroslav@5
   849
                    break;
jaroslav@5
   850
                }
jaroslav@151
   851
                case opc_lookupswitch: {
jtulach@128
   852
                    int table = i / 4 * 4 + 4;
jaroslav@115
   853
                    int dflt = i + readInt4(byteCodes, table);
jaroslav@115
   854
                    table += 4;
jaroslav@115
   855
                    int n = readInt4(byteCodes, table);
jaroslav@115
   856
                    table += 4;
lubomir@307
   857
                    out.append("switch (").append(smapper.popI()).append(") {\n");
jaroslav@115
   858
                    while (n-- > 0) {
jaroslav@115
   859
                        int cnstnt = readInt4(byteCodes, table);
jaroslav@115
   860
                        table += 4;
jaroslav@115
   861
                        int offset = i + readInt4(byteCodes, table);
jaroslav@115
   862
                        table += 4;
jaroslav@115
   863
                        out.append("  case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
jaroslav@115
   864
                    }
jaroslav@115
   865
                    out.append("  default: gt = " + dflt).append("; continue;\n}");
jaroslav@115
   866
                    i = table - 1;
jaroslav@115
   867
                    break;
jaroslav@115
   868
                }
jaroslav@151
   869
                case opc_tableswitch: {
jtulach@128
   870
                    int table = i / 4 * 4 + 4;
jaroslav@115
   871
                    int dflt = i + readInt4(byteCodes, table);
jaroslav@115
   872
                    table += 4;
jaroslav@115
   873
                    int low = readInt4(byteCodes, table);
jaroslav@115
   874
                    table += 4;
jaroslav@115
   875
                    int high = readInt4(byteCodes, table);
jaroslav@115
   876
                    table += 4;
lubomir@307
   877
                    out.append("switch (").append(smapper.popI()).append(") {\n");
jaroslav@115
   878
                    while (low <= high) {
jaroslav@115
   879
                        int offset = i + readInt4(byteCodes, table);
jaroslav@115
   880
                        table += 4;
jaroslav@115
   881
                        out.append("  case " + low).append(": gt = " + offset).append("; continue;\n");
jaroslav@115
   882
                        low++;
jaroslav@115
   883
                    }
jaroslav@115
   884
                    out.append("  default: gt = " + dflt).append("; continue;\n}");
jaroslav@115
   885
                    i = table - 1;
jaroslav@115
   886
                    break;
jaroslav@115
   887
                }
jaroslav@151
   888
                case opc_invokeinterface: {
lubomir@307
   889
                    i = invokeVirtualMethod(byteCodes, i, smapper) + 2;
jaroslav@46
   890
                    break;
jaroslav@46
   891
                }
jaroslav@151
   892
                case opc_invokevirtual:
lubomir@307
   893
                    i = invokeVirtualMethod(byteCodes, i, smapper);
jaroslav@12
   894
                    break;
jaroslav@151
   895
                case opc_invokespecial:
lubomir@307
   896
                    i = invokeStaticMethod(byteCodes, i, smapper, false);
jaroslav@4
   897
                    break;
jaroslav@151
   898
                case opc_invokestatic:
lubomir@307
   899
                    i = invokeStaticMethod(byteCodes, i, smapper, true);
jaroslav@10
   900
                    break;
jaroslav@151
   901
                case opc_new: {
jaroslav@8
   902
                    int indx = readIntArg(byteCodes, i);
jaroslav@151
   903
                    String ci = jc.getClassName(indx);
lubomir@283
   904
                    emit(out, "@1 = new @2;",
lubomir@317
   905
                         smapper.pushA(), accessClass(ci.replace('/', '_')));
jaroslav@151
   906
                    addReference(ci);
jaroslav@8
   907
                    i += 2;
jaroslav@8
   908
                    break;
jaroslav@8
   909
                }
lubomir@283
   910
                case opc_newarray:
lubomir@221
   911
                    ++i; // skip type of array
lubomir@283
   912
                    emit(out, "@2 = new Array(@1).fillNulls();",
lubomir@307
   913
                         smapper.popI(), smapper.pushA());
jaroslav@21
   914
                    break;
lubomir@283
   915
                case opc_anewarray:
jaroslav@21
   916
                    i += 2; // skip type of array
lubomir@283
   917
                    emit(out, "@2 = new Array(@1).fillNulls();",
lubomir@307
   918
                         smapper.popI(), smapper.pushA());
jaroslav@21
   919
                    break;
jaroslav@151
   920
                case opc_multianewarray: {
jtulach@128
   921
                    i += 2;
jtulach@128
   922
                    int dim = readByte(byteCodes, ++i);
lubomir@307
   923
                    out.append("{ var a0 = new Array(").append(smapper.popI())
lubomir@221
   924
                       .append(").fillNulls();");
jtulach@128
   925
                    for (int d = 1; d < dim; d++) {
lubomir@221
   926
                        out.append("\n  var l" + d).append(" = ")
lubomir@307
   927
                           .append(smapper.popI()).append(';');
jtulach@128
   928
                        out.append("\n  for (var i" + d).append (" = 0; i" + d).
jtulach@128
   929
                            append(" < a" + (d - 1)).
jtulach@128
   930
                            append(".length; i" + d).append("++) {");
jtulach@128
   931
                        out.append("\n    var a" + d).
jaroslav@172
   932
                            append (" = new Array(l" + d).append(").fillNulls();");
jtulach@128
   933
                        out.append("\n    a" + (d - 1)).append("[i" + d).append("] = a" + d).
jtulach@128
   934
                            append(";");
jtulach@128
   935
                    }
jtulach@128
   936
                    for (int d = 1; d < dim; d++) {
jtulach@128
   937
                        out.append("\n  }");
jtulach@128
   938
                    }
lubomir@307
   939
                    out.append("\n").append(smapper.pushA()).append(" = a0; }");
jtulach@128
   940
                    break;
jtulach@128
   941
                }
jaroslav@151
   942
                case opc_arraylength:
lubomir@307
   943
                    emit(out, "@2 = @1.length;", smapper.popA(), smapper.pushI());
jaroslav@272
   944
                    break;
lubomir@283
   945
                case opc_lastore:
lubomir@283
   946
                    emit(out, "@3[@2] = @1;",
lubomir@307
   947
                         smapper.popL(), smapper.popI(), smapper.popA());
lubomir@281
   948
                    break;
lubomir@283
   949
                case opc_fastore:
lubomir@283
   950
                    emit(out, "@3[@2] = @1;",
lubomir@307
   951
                         smapper.popF(), smapper.popI(), smapper.popA());
lubomir@281
   952
                    break;
lubomir@283
   953
                case opc_dastore:
lubomir@283
   954
                    emit(out, "@3[@2] = @1;",
lubomir@307
   955
                         smapper.popD(), smapper.popI(), smapper.popA());
lubomir@281
   956
                    break;
lubomir@283
   957
                case opc_aastore:
lubomir@283
   958
                    emit(out, "@3[@2] = @1;",
lubomir@307
   959
                         smapper.popA(), smapper.popI(), smapper.popA());
jaroslav@21
   960
                    break;
jaroslav@151
   961
                case opc_iastore:
jaroslav@151
   962
                case opc_bastore:
jaroslav@151
   963
                case opc_castore:
lubomir@283
   964
                case opc_sastore:
lubomir@283
   965
                    emit(out, "@3[@2] = @1;",
lubomir@307
   966
                         smapper.popI(), smapper.popI(), smapper.popA());
jaroslav@240
   967
                    break;
lubomir@283
   968
                case opc_laload:
lubomir@283
   969
                    emit(out, "@3 = @2[@1];",
lubomir@307
   970
                         smapper.popI(), smapper.popA(), smapper.pushL());
lubomir@281
   971
                    break;
lubomir@283
   972
                case opc_faload:
lubomir@283
   973
                    emit(out, "@3 = @2[@1];",
lubomir@307
   974
                         smapper.popI(), smapper.popA(), smapper.pushF());
lubomir@281
   975
                    break;
lubomir@283
   976
                case opc_daload:
lubomir@283
   977
                    emit(out, "@3 = @2[@1];",
lubomir@307
   978
                         smapper.popI(), smapper.popA(), smapper.pushD());
lubomir@281
   979
                    break;
lubomir@283
   980
                case opc_aaload:
lubomir@283
   981
                    emit(out, "@3 = @2[@1];",
lubomir@307
   982
                         smapper.popI(), smapper.popA(), smapper.pushA());
jaroslav@272
   983
                    break;
jaroslav@272
   984
                case opc_iaload:
jaroslav@272
   985
                case opc_baload:
jaroslav@272
   986
                case opc_caload:
lubomir@283
   987
                case opc_saload:
lubomir@283
   988
                    emit(out, "@3 = @2[@1];",
lubomir@307
   989
                         smapper.popI(), smapper.popA(), smapper.pushI());
jaroslav@272
   990
                    break;
lubomir@221
   991
                case opc_pop:
jaroslav@272
   992
                case opc_pop2:
lubomir@307
   993
                    smapper.pop(1);
jaroslav@399
   994
                    debug("/* pop */");
jaroslav@272
   995
                    break;
lubomir@281
   996
                case opc_dup: {
lubomir@307
   997
                    final Variable v = smapper.get(0);
lubomir@307
   998
                    emit(out, "@1 = @2;", smapper.pushT(v.getType()), v);
jaroslav@21
   999
                    break;
jaroslav@21
  1000
                }
lubomir@281
  1001
                case opc_dup2: {
lubomir@307
  1002
                    if (smapper.get(0).isCategory2()) {
lubomir@307
  1003
                        final Variable v = smapper.get(0);
lubomir@307
  1004
                        emit(out, "@1 = @2;", smapper.pushT(v.getType()), v);
lubomir@281
  1005
                    } else {
lubomir@307
  1006
                        final Variable v1 = smapper.get(0);
lubomir@307
  1007
                        final Variable v2 = smapper.get(1);
lubomir@283
  1008
                        emit(out, "{ @1 = @2; @3 = @4; }",
lubomir@307
  1009
                             smapper.pushT(v2.getType()), v2,
lubomir@307
  1010
                             smapper.pushT(v1.getType()), v1);
lubomir@281
  1011
                    }
jaroslav@21
  1012
                    break;
jaroslav@21
  1013
                }
lubomir@281
  1014
                case opc_dup_x1: {
lubomir@307
  1015
                    final Variable vi1 = smapper.pop();
lubomir@307
  1016
                    final Variable vi2 = smapper.pop();
lubomir@307
  1017
                    final Variable vo3 = smapper.pushT(vi1.getType());
lubomir@307
  1018
                    final Variable vo2 = smapper.pushT(vi2.getType());
lubomir@307
  1019
                    final Variable vo1 = smapper.pushT(vi1.getType());
lubomir@281
  1020
lubomir@283
  1021
                    emit(out, "{ @1 = @2; @3 = @4; @5 = @6; }",
lubomir@283
  1022
                         vo1, vi1, vo2, vi2, vo3, vo1);
jaroslav@93
  1023
                    break;
lubomir@281
  1024
                }
lubomir@281
  1025
                case opc_dup_x2: {
lubomir@307
  1026
                    if (smapper.get(1).isCategory2()) {
lubomir@307
  1027
                        final Variable vi1 = smapper.pop();
lubomir@307
  1028
                        final Variable vi2 = smapper.pop();
lubomir@307
  1029
                        final Variable vo3 = smapper.pushT(vi1.getType());
lubomir@307
  1030
                        final Variable vo2 = smapper.pushT(vi2.getType());
lubomir@307
  1031
                        final Variable vo1 = smapper.pushT(vi1.getType());
lubomir@281
  1032
lubomir@283
  1033
                        emit(out, "{ @1 = @2; @3 = @4; @5 = @6; }",
lubomir@283
  1034
                             vo1, vi1, vo2, vi2, vo3, vo1);
lubomir@281
  1035
                    } else {
lubomir@307
  1036
                        final Variable vi1 = smapper.pop();
lubomir@307
  1037
                        final Variable vi2 = smapper.pop();
lubomir@307
  1038
                        final Variable vi3 = smapper.pop();
lubomir@307
  1039
                        final Variable vo4 = smapper.pushT(vi1.getType());
lubomir@307
  1040
                        final Variable vo3 = smapper.pushT(vi3.getType());
lubomir@307
  1041
                        final Variable vo2 = smapper.pushT(vi2.getType());
lubomir@307
  1042
                        final Variable vo1 = smapper.pushT(vi1.getType());
lubomir@281
  1043
lubomir@283
  1044
                        emit(out, "{ @1 = @2; @3 = @4; @5 = @6; @7 = @8; }",
lubomir@283
  1045
                             vo1, vi1, vo2, vi2, vo3, vi3, vo4, vo1);
lubomir@281
  1046
                    }
jaroslav@8
  1047
                    break;
lubomir@281
  1048
                }
jaroslav@151
  1049
                case opc_bipush:
lubomir@283
  1050
                    emit(out, "@1 = @2;",
lubomir@307
  1051
                         smapper.pushI(), Integer.toString(byteCodes[++i]));
jaroslav@8
  1052
                    break;
jaroslav@151
  1053
                case opc_sipush:
lubomir@283
  1054
                    emit(out, "@1 = @2;",
lubomir@307
  1055
                         smapper.pushI(),
lubomir@283
  1056
                         Integer.toString(readIntArg(byteCodes, i)));
jaroslav@31
  1057
                    i += 2;
jaroslav@31
  1058
                    break;
jaroslav@151
  1059
                case opc_getfield: {
jaroslav@8
  1060
                    int indx = readIntArg(byteCodes, i);
jaroslav@151
  1061
                    String[] fi = jc.getFieldInfoName(indx);
lubomir@307
  1062
                    final int type = VarType.fromFieldType(fi[2].charAt(0));
lubomir@283
  1063
                    emit(out, "@2 = @1.fld_@3;",
lubomir@307
  1064
                         smapper.popA(), smapper.pushT(type), fi[1]);
jaroslav@8
  1065
                    i += 2;
jaroslav@8
  1066
                    break;
jaroslav@8
  1067
                }
jaroslav@151
  1068
                case opc_getstatic: {
jaroslav@9
  1069
                    int indx = readIntArg(byteCodes, i);
jaroslav@151
  1070
                    String[] fi = jc.getFieldInfoName(indx);
lubomir@307
  1071
                    final int type = VarType.fromFieldType(fi[2].charAt(0));
jaroslav@358
  1072
                    emit(out, "@1 = @2(false).constructor.@3;",
lubomir@317
  1073
                         smapper.pushT(type),
lubomir@317
  1074
                         accessClass(fi[0].replace('/', '_')), fi[1]);
jaroslav@9
  1075
                    i += 2;
jaroslav@151
  1076
                    addReference(fi[0]);
jaroslav@9
  1077
                    break;
jaroslav@9
  1078
                }
jaroslav@151
  1079
                case opc_putfield: {
jaroslav@10
  1080
                    int indx = readIntArg(byteCodes, i);
jaroslav@151
  1081
                    String[] fi = jc.getFieldInfoName(indx);
lubomir@307
  1082
                    final int type = VarType.fromFieldType(fi[2].charAt(0));
lubomir@283
  1083
                    emit(out, "@2.fld_@3 = @1;",
lubomir@307
  1084
                         smapper.popT(type), smapper.popA(), fi[1]);
jaroslav@10
  1085
                    i += 2;
jaroslav@10
  1086
                    break;
jaroslav@10
  1087
                }
lubomir@281
  1088
                case opc_putstatic: {
lubomir@281
  1089
                    int indx = readIntArg(byteCodes, i);
lubomir@281
  1090
                    String[] fi = jc.getFieldInfoName(indx);
lubomir@307
  1091
                    final int type = VarType.fromFieldType(fi[2].charAt(0));
jaroslav@358
  1092
                    emit(out, "@1(false).constructor.@2 = @3;",
lubomir@317
  1093
                         accessClass(fi[0].replace('/', '_')), fi[1],
lubomir@317
  1094
                         smapper.popT(type));
lubomir@281
  1095
                    i += 2;
lubomir@281
  1096
                    addReference(fi[0]);
lubomir@281
  1097
                    break;
lubomir@281
  1098
                }
jaroslav@151
  1099
                case opc_checkcast: {
jaroslav@30
  1100
                    int indx = readIntArg(byteCodes, i);
jaroslav@151
  1101
                    final String type = jc.getClassName(indx);
jaroslav@42
  1102
                    if (!type.startsWith("[")) {
jaroslav@42
  1103
                        // no way to check arrays right now
lubomir@283
  1104
                        // XXX proper exception
lubomir@317
  1105
                        emit(out,
lubomir@317
  1106
                             "if (@1 !== null && !@1.$instOf_@2) throw {};",
lubomir@307
  1107
                             smapper.getA(0), type.replace('/', '_'));
jaroslav@42
  1108
                    }
jaroslav@30
  1109
                    i += 2;
jaroslav@30
  1110
                    break;
jaroslav@30
  1111
                }
jaroslav@151
  1112
                case opc_instanceof: {
jaroslav@17
  1113
                    int indx = readIntArg(byteCodes, i);
jaroslav@151
  1114
                    final String type = jc.getClassName(indx);
lubomir@283
  1115
                    emit(out, "@2 = @1.$instOf_@3 ? 1 : 0;",
lubomir@317
  1116
                         smapper.popA(), smapper.pushI(),
lubomir@317
  1117
                         type.replace('/', '_'));
jaroslav@17
  1118
                    i += 2;
jaroslav@30
  1119
                    break;
jaroslav@17
  1120
                }
jaroslav@151
  1121
                case opc_athrow: {
lubomir@307
  1122
                    final Variable v = smapper.popA();
lubomir@307
  1123
                    smapper.clear();
lubomir@281
  1124
lubomir@283
  1125
                    emit(out, "{ @1 = @2; throw @2; }",
lubomir@307
  1126
                         smapper.pushA(), v);
jaroslav@104
  1127
                    break;
jaroslav@104
  1128
                }
lubomir@221
  1129
lubomir@221
  1130
                case opc_monitorenter: {
lubomir@221
  1131
                    out.append("/* monitor enter */");
lubomir@307
  1132
                    smapper.popA();
lubomir@221
  1133
                    break;
lubomir@221
  1134
                }
lubomir@221
  1135
lubomir@221
  1136
                case opc_monitorexit: {
lubomir@221
  1137
                    out.append("/* monitor exit */");
lubomir@307
  1138
                    smapper.popA();
lubomir@221
  1139
                    break;
lubomir@221
  1140
                }
lubomir@221
  1141
jaroslav@104
  1142
                default: {
lubomir@283
  1143
                    emit(out, "throw 'unknown bytecode @1';",
lubomir@283
  1144
                         Integer.toString(c));
jaroslav@104
  1145
                }
jaroslav@0
  1146
            }
jaroslav@399
  1147
            if (debug(" //")) {
jaroslav@399
  1148
                for (int j = prev; j <= i; j++) {
jaroslav@399
  1149
                    out.append(" ");
jaroslav@399
  1150
                    final int cc = readByte(byteCodes, j);
jaroslav@399
  1151
                    out.append(Integer.toString(cc));
tzezula@285
  1152
                }
jaroslav@0
  1153
            }
tzezula@285
  1154
            out.append("\n");            
jaroslav@0
  1155
        }
jaroslav@398
  1156
        if (previousTrap != null) {
jaroslav@398
  1157
            generateCatch(previousTrap);
jaroslav@398
  1158
        }
jaroslav@10
  1159
        out.append("  }\n");
lubomir@307
  1160
        out.append("};");
jaroslav@4
  1161
    }
jaroslav@4
  1162
lubomir@281
  1163
    private int generateIf(byte[] byteCodes, int i,
lubomir@281
  1164
                           final Variable v2, final Variable v1,
lubomir@281
  1165
                           final String test) throws IOException {
jaroslav@4
  1166
        int indx = i + readIntArg(byteCodes, i);
lubomir@281
  1167
        out.append("if (").append(v1)
lubomir@221
  1168
           .append(' ').append(test).append(' ')
lubomir@281
  1169
           .append(v2).append(") { gt = " + indx)
lubomir@221
  1170
           .append("; continue; }");
jaroslav@4
  1171
        return i + 2;
jaroslav@4
  1172
    }
jaroslav@4
  1173
jaroslav@4
  1174
    private int readIntArg(byte[] byteCodes, int offsetInstruction) {
jaroslav@5
  1175
        final int indxHi = byteCodes[offsetInstruction + 1] << 8;
jaroslav@5
  1176
        final int indxLo = byteCodes[offsetInstruction + 2];
jaroslav@5
  1177
        return (indxHi & 0xffffff00) | (indxLo & 0xff);
jaroslav@4
  1178
    }
jaroslav@115
  1179
    private int readInt4(byte[] byteCodes, int offsetInstruction) {
jaroslav@115
  1180
        final int d = byteCodes[offsetInstruction + 0] << 24;
jaroslav@115
  1181
        final int c = byteCodes[offsetInstruction + 1] << 16;
jaroslav@115
  1182
        final int b = byteCodes[offsetInstruction + 2] << 8;
jaroslav@115
  1183
        final int a = byteCodes[offsetInstruction + 3];
jaroslav@115
  1184
        return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
jaroslav@115
  1185
    }
jtulach@128
  1186
    private int readByte(byte[] byteCodes, int offsetInstruction) {
lubomir@221
  1187
        return byteCodes[offsetInstruction] & 0xff;
jtulach@128
  1188
    }
jaroslav@4
  1189
    
lubomir@281
  1190
    private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
jaroslav@4
  1191
        int i = 0;
jaroslav@4
  1192
        Boolean count = null;
jaroslav@32
  1193
        boolean array = false;
jaroslav@248
  1194
        sig.append("__");
jaroslav@10
  1195
        int firstPos = sig.length();
jaroslav@4
  1196
        while (i < descriptor.length()) {
jaroslav@4
  1197
            char ch = descriptor.charAt(i++);
jaroslav@4
  1198
            switch (ch) {
jaroslav@4
  1199
                case '(':
jaroslav@4
  1200
                    count = true;
jaroslav@4
  1201
                    continue;
jaroslav@4
  1202
                case ')':
jaroslav@4
  1203
                    count = false;
jaroslav@4
  1204
                    continue;
jaroslav@4
  1205
                case 'B': 
jaroslav@4
  1206
                case 'C': 
jaroslav@4
  1207
                case 'D': 
jaroslav@4
  1208
                case 'F': 
jaroslav@4
  1209
                case 'I': 
jaroslav@4
  1210
                case 'J': 
jaroslav@4
  1211
                case 'S': 
jaroslav@4
  1212
                case 'Z': 
jaroslav@4
  1213
                    if (count) {
jaroslav@32
  1214
                        if (array) {
jaroslav@248
  1215
                            sig.append("_3");
jaroslav@32
  1216
                        }
jaroslav@4
  1217
                        sig.append(ch);
jtulach@156
  1218
                        if (ch == 'J' || ch == 'D') {
jtulach@156
  1219
                            cnt.append('1');
jtulach@156
  1220
                        } else {
jtulach@156
  1221
                            cnt.append('0');
jtulach@156
  1222
                        }
jaroslav@4
  1223
                    } else {
jaroslav@10
  1224
                        sig.insert(firstPos, ch);
jaroslav@32
  1225
                        if (array) {
lubomir@281
  1226
                            returnType[0] = '[';
jaroslav@248
  1227
                            sig.insert(firstPos, "_3");
lubomir@281
  1228
                        } else {
lubomir@281
  1229
                            returnType[0] = ch;
jaroslav@32
  1230
                        }
jaroslav@4
  1231
                    }
jaroslav@93
  1232
                    array = false;
jaroslav@4
  1233
                    continue;
jaroslav@4
  1234
                case 'V': 
jaroslav@4
  1235
                    assert !count;
lubomir@281
  1236
                    returnType[0] = 'V';
jaroslav@10
  1237
                    sig.insert(firstPos, 'V');
jaroslav@4
  1238
                    continue;
jaroslav@4
  1239
                case 'L':
jaroslav@16
  1240
                    int next = descriptor.indexOf(';', i);
jaroslav@248
  1241
                    String realSig = mangleSig(descriptor, i - 1, next + 1);
jaroslav@4
  1242
                    if (count) {
jaroslav@32
  1243
                        if (array) {
jaroslav@248
  1244
                            sig.append("_3");
jaroslav@32
  1245
                        }
jaroslav@248
  1246
                        sig.append(realSig);
jtulach@156
  1247
                        cnt.append('0');
jaroslav@4
  1248
                    } else {
jaroslav@248
  1249
                        sig.insert(firstPos, realSig);
jaroslav@32
  1250
                        if (array) {
jaroslav@248
  1251
                            sig.insert(firstPos, "_3");
jaroslav@32
  1252
                        }
lubomir@281
  1253
                        returnType[0] = 'L';
jaroslav@4
  1254
                    }
jaroslav@16
  1255
                    i = next + 1;
lubomir@407
  1256
                    array = false;
jaroslav@4
  1257
                    continue;
jaroslav@4
  1258
                case '[':
jaroslav@248
  1259
                    array = true;
jaroslav@4
  1260
                    continue;
jaroslav@4
  1261
                default:
jaroslav@248
  1262
                    throw new IllegalStateException("Invalid char: " + ch);
jaroslav@4
  1263
            }
jaroslav@4
  1264
        }
jaroslav@0
  1265
    }
jaroslav@248
  1266
    
jaroslav@248
  1267
    private static String mangleSig(String txt, int first, int last) {
jaroslav@248
  1268
        StringBuilder sb = new StringBuilder();
jaroslav@248
  1269
        for (int i = first; i < last; i++) {
jaroslav@248
  1270
            final char ch = txt.charAt(i);
jaroslav@248
  1271
            switch (ch) {
jaroslav@248
  1272
                case '/': sb.append('_'); break;
jaroslav@248
  1273
                case '_': sb.append("_1"); break;
jaroslav@248
  1274
                case ';': sb.append("_2"); break;
jaroslav@248
  1275
                case '[': sb.append("_3"); break;
jaroslav@248
  1276
                default: sb.append(ch); break;
jaroslav@248
  1277
            }
jaroslav@248
  1278
        }
jaroslav@248
  1279
        return sb.toString();
jaroslav@248
  1280
    }
jaroslav@9
  1281
jaroslav@248
  1282
    private static String findMethodName(MethodData m, StringBuilder cnt) {
jaroslav@42
  1283
        StringBuilder name = new StringBuilder();
jaroslav@10
  1284
        if ("<init>".equals(m.getName())) { // NOI18N
jaroslav@42
  1285
            name.append("cons"); // NOI18N
jaroslav@19
  1286
        } else if ("<clinit>".equals(m.getName())) { // NOI18N
jaroslav@42
  1287
            name.append("class"); // NOI18N
jaroslav@10
  1288
        } else {
jaroslav@42
  1289
            name.append(m.getName());
jaroslav@10
  1290
        } 
jaroslav@42
  1291
        
lubomir@282
  1292
        countArgs(m.getInternalSig(), new char[1], name, cnt);
jaroslav@42
  1293
        return name.toString();
jaroslav@10
  1294
    }
jaroslav@10
  1295
lubomir@282
  1296
    static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
jaroslav@10
  1297
        StringBuilder name = new StringBuilder();
jaroslav@151
  1298
        String descr = mi[2];//mi.getDescriptor();
jaroslav@151
  1299
        String nm= mi[1];
jaroslav@151
  1300
        if ("<init>".equals(nm)) { // NOI18N
jaroslav@10
  1301
            name.append("cons"); // NOI18N
jaroslav@10
  1302
        } else {
jaroslav@151
  1303
            name.append(nm);
jaroslav@10
  1304
        }
lubomir@282
  1305
        countArgs(descr, returnType, name, cnt);
jaroslav@10
  1306
        return name.toString();
jaroslav@10
  1307
    }
jaroslav@10
  1308
lubomir@307
  1309
    private int invokeStaticMethod(byte[] byteCodes, int i, final StackMapper mapper, boolean isStatic)
jaroslav@10
  1310
    throws IOException {
jaroslav@10
  1311
        int methodIndex = readIntArg(byteCodes, i);
jaroslav@151
  1312
        String[] mi = jc.getFieldInfoName(methodIndex);
lubomir@281
  1313
        char[] returnType = { 'V' };
jtulach@156
  1314
        StringBuilder cnt = new StringBuilder();
lubomir@281
  1315
        String mn = findMethodName(mi, cnt, returnType);
lubomir@221
  1316
lubomir@221
  1317
        final int numArguments = isStatic ? cnt.length() : cnt.length() + 1;
lubomir@281
  1318
        final Variable[] vars = new Variable[numArguments];
lubomir@221
  1319
lubomir@281
  1320
        for (int j = numArguments - 1; j >= 0; --j) {
lubomir@281
  1321
            vars[j] = mapper.pop();
jaroslav@11
  1322
        }
lubomir@281
  1323
lubomir@281
  1324
        if (returnType[0] != 'V') {
lubomir@307
  1325
            out.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
lubomir@281
  1326
               .append(" = ");
jaroslav@10
  1327
        }
lubomir@221
  1328
jaroslav@151
  1329
        final String in = mi[0];
jaroslav@274
  1330
        out.append(accessClass(in.replace('/', '_')));
jaroslav@224
  1331
        out.append("(false).");
jaroslav@397
  1332
        if (mn.startsWith("cons_")) {
jaroslav@397
  1333
            out.append("constructor.");
jaroslav@397
  1334
        }
jaroslav@10
  1335
        out.append(mn);
jaroslav@442
  1336
        if (isStatic) {
jaroslav@442
  1337
            out.append('(');
jaroslav@442
  1338
        } else {
jaroslav@442
  1339
            out.append(".call(");
jaroslav@442
  1340
        }
lubomir@221
  1341
        if (numArguments > 0) {
lubomir@281
  1342
            out.append(vars[0]);
lubomir@281
  1343
            for (int j = 1; j < numArguments; ++j) {
lubomir@221
  1344
                out.append(", ");
lubomir@281
  1345
                out.append(vars[j]);
lubomir@221
  1346
            }
jaroslav@10
  1347
        }
lubomir@221
  1348
        out.append(");");
jaroslav@10
  1349
        i += 2;
jaroslav@18
  1350
        addReference(in);
jaroslav@10
  1351
        return i;
jaroslav@10
  1352
    }
lubomir@307
  1353
    private int invokeVirtualMethod(byte[] byteCodes, int i, final StackMapper mapper)
jaroslav@12
  1354
    throws IOException {
jaroslav@12
  1355
        int methodIndex = readIntArg(byteCodes, i);
jaroslav@151
  1356
        String[] mi = jc.getFieldInfoName(methodIndex);
lubomir@281
  1357
        char[] returnType = { 'V' };
jtulach@156
  1358
        StringBuilder cnt = new StringBuilder();
lubomir@281
  1359
        String mn = findMethodName(mi, cnt, returnType);
lubomir@221
  1360
lubomir@281
  1361
        final int numArguments = cnt.length() + 1;
lubomir@281
  1362
        final Variable[] vars = new Variable[numArguments];
lubomir@221
  1363
lubomir@281
  1364
        for (int j = numArguments - 1; j >= 0; --j) {
lubomir@281
  1365
            vars[j] = mapper.pop();
jaroslav@12
  1366
        }
lubomir@221
  1367
lubomir@281
  1368
        if (returnType[0] != 'V') {
lubomir@307
  1369
            out.append(mapper.pushT(VarType.fromFieldType(returnType[0])))
lubomir@281
  1370
               .append(" = ");
jaroslav@12
  1371
        }
lubomir@281
  1372
lubomir@281
  1373
        out.append(vars[0]).append('.');
jaroslav@12
  1374
        out.append(mn);
jaroslav@12
  1375
        out.append('(');
jaroslav@442
  1376
        String sep = "";
lubomir@281
  1377
        for (int j = 1; j < numArguments; ++j) {
jaroslav@442
  1378
            out.append(sep);
lubomir@281
  1379
            out.append(vars[j]);
jaroslav@442
  1380
            sep = ", ";
jaroslav@12
  1381
        }
lubomir@221
  1382
        out.append(");");
jaroslav@12
  1383
        i += 2;
jaroslav@12
  1384
        return i;
jaroslav@12
  1385
    }
lubomir@221
  1386
jaroslav@103
  1387
    private void addReference(String cn) throws IOException {
jtulach@162
  1388
        if (requireReference(cn)) {
jaroslav@399
  1389
            debug(" /* needs " + cn + " */");
jaroslav@18
  1390
        }
jaroslav@18
  1391
    }
jaroslav@16
  1392
jaroslav@33
  1393
    private void outType(String d, StringBuilder out) {
jaroslav@33
  1394
        int arr = 0;
jaroslav@33
  1395
        while (d.charAt(0) == '[') {
jaroslav@33
  1396
            out.append('A');
jaroslav@33
  1397
            d = d.substring(1);
jaroslav@33
  1398
        }
jaroslav@16
  1399
        if (d.charAt(0) == 'L') {
jaroslav@16
  1400
            assert d.charAt(d.length() - 1) == ';';
jaroslav@16
  1401
            out.append(d.replace('/', '_').substring(0, d.length() - 1));
jaroslav@16
  1402
        } else {
jaroslav@16
  1403
            out.append(d);
jaroslav@16
  1404
        }
jaroslav@16
  1405
    }
jaroslav@21
  1406
jaroslav@230
  1407
    private String encodeConstant(int entryIndex) throws IOException {
jaroslav@230
  1408
        String[] classRef = { null };
jaroslav@230
  1409
        String s = jc.stringValue(entryIndex, classRef);
jaroslav@230
  1410
        if (classRef[0] != null) {
jaroslav@230
  1411
            addReference(classRef[0]);
jaroslav@274
  1412
            s = accessClass(s.replace('/', '_')) + "(false).constructor.$class";
jaroslav@230
  1413
        }
jaroslav@151
  1414
        return s;
jaroslav@21
  1415
    }
jaroslav@32
  1416
jaroslav@266
  1417
    private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
jaroslav@152
  1418
        byte[] arr = m.findAnnotationData(true);
jaroslav@152
  1419
        if (arr == null) {
jaroslav@266
  1420
            return null;
jaroslav@152
  1421
        }
jaroslav@200
  1422
        final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
jaroslav@152
  1423
        class P extends AnnotationParser {
jaroslav@237
  1424
            public P() {
jaroslav@237
  1425
                super(false);
jaroslav@237
  1426
            }
jaroslav@237
  1427
            
jaroslav@152
  1428
            int cnt;
jaroslav@152
  1429
            String[] args = new String[30];
jaroslav@152
  1430
            String body;
jaroslav@94
  1431
            
jaroslav@152
  1432
            @Override
jaroslav@236
  1433
            protected void visitAttr(String type, String attr, String at, String value) {
jaroslav@152
  1434
                if (type.equals(jvmType)) {
jaroslav@152
  1435
                    if ("body".equals(attr)) {
jaroslav@152
  1436
                        body = value;
jaroslav@152
  1437
                    } else if ("args".equals(attr)) {
jaroslav@152
  1438
                        args[cnt++] = value;
jaroslav@152
  1439
                    } else {
jaroslav@152
  1440
                        throw new IllegalArgumentException(attr);
jaroslav@152
  1441
                    }
jaroslav@152
  1442
                }
jaroslav@94
  1443
            }
jaroslav@94
  1444
        }
jaroslav@152
  1445
        P p = new P();
jaroslav@152
  1446
        p.parse(arr, jc);
jaroslav@152
  1447
        if (p.body == null) {
jaroslav@266
  1448
            return null;
jaroslav@152
  1449
        }
jtulach@156
  1450
        StringBuilder cnt = new StringBuilder();
jaroslav@266
  1451
        final String mn = findMethodName(m, cnt);
jaroslav@266
  1452
        out.append(prefix).append(mn);
jaroslav@203
  1453
        out.append(" = function(");
jaroslav@442
  1454
        String space = "";
jaroslav@443
  1455
        int index = 0;
jtulach@156
  1456
        for (int i = 0; i < cnt.length(); i++) {
jaroslav@152
  1457
            out.append(space);
jaroslav@316
  1458
            space = outputArg(out, p.args, index);
jaroslav@152
  1459
            index++;
jaroslav@152
  1460
        }
jaroslav@152
  1461
        out.append(") {").append("\n");
jaroslav@152
  1462
        out.append(p.body);
jaroslav@152
  1463
        out.append("\n}\n");
jaroslav@266
  1464
        return mn;
jaroslav@151
  1465
    }
jaroslav@151
  1466
    private static String className(ClassData jc) {
jaroslav@151
  1467
        //return jc.getName().getInternalName().replace('/', '_');
jaroslav@151
  1468
        return jc.getClassName().replace('/', '_');
jaroslav@94
  1469
    }
jaroslav@152
  1470
    
jaroslav@152
  1471
    private static String[] findAnnotation(
jaroslav@152
  1472
        byte[] arr, ClassData cd, final String className, 
jaroslav@152
  1473
        final String... attrNames
jaroslav@152
  1474
    ) throws IOException {
jaroslav@152
  1475
        if (arr == null) {
jaroslav@152
  1476
            return null;
jaroslav@152
  1477
        }
jaroslav@152
  1478
        final String[] values = new String[attrNames.length];
jaroslav@152
  1479
        final boolean[] found = { false };
jaroslav@152
  1480
        final String jvmType = "L" + className.replace('.', '/') + ";";
jaroslav@237
  1481
        AnnotationParser ap = new AnnotationParser(false) {
jaroslav@152
  1482
            @Override
jaroslav@236
  1483
            protected void visitAttr(String type, String attr, String at, String value) {
jaroslav@152
  1484
                if (type.equals(jvmType)) {
jaroslav@152
  1485
                    found[0] = true;
jaroslav@152
  1486
                    for (int i = 0; i < attrNames.length; i++) {
jaroslav@152
  1487
                        if (attrNames[i].equals(attr)) {
jaroslav@152
  1488
                            values[i] = value;
jaroslav@152
  1489
                        }
jaroslav@152
  1490
                    }
jaroslav@152
  1491
                }
jaroslav@152
  1492
            }
jaroslav@152
  1493
            
jaroslav@152
  1494
        };
jaroslav@152
  1495
        ap.parse(arr, cd);
jaroslav@152
  1496
        return found[0] ? values : null;
jaroslav@152
  1497
    }
jaroslav@173
  1498
jaroslav@173
  1499
    private CharSequence initField(FieldData v) {
jaroslav@173
  1500
        final String is = v.getInternalSig();
jaroslav@173
  1501
        if (is.length() == 1) {
jaroslav@173
  1502
            switch (is.charAt(0)) {
jaroslav@173
  1503
                case 'S':
jaroslav@173
  1504
                case 'J':
jaroslav@173
  1505
                case 'B':
jaroslav@173
  1506
                case 'Z':
jaroslav@173
  1507
                case 'C':
jaroslav@173
  1508
                case 'I': return " = 0;";
jaroslav@173
  1509
                case 'F': 
jaroslav@180
  1510
                case 'D': return " = 0.0;";
jaroslav@173
  1511
                default:
jaroslav@173
  1512
                    throw new IllegalStateException(is);
jaroslav@173
  1513
            }
jaroslav@173
  1514
        }
jaroslav@173
  1515
        return " = null;";
jaroslav@173
  1516
    }
jaroslav@235
  1517
jaroslav@235
  1518
    private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
jaroslav@237
  1519
        AnnotationParser ap = new AnnotationParser(true) {
jaroslav@237
  1520
            int anno;
jaroslav@235
  1521
            int cnt;
jaroslav@235
  1522
            
jaroslav@235
  1523
            @Override
jaroslav@235
  1524
            protected void visitAnnotationStart(String type) throws IOException {
jaroslav@237
  1525
                if (anno++ > 0) {
jaroslav@237
  1526
                    out.append(",");
jaroslav@237
  1527
                }
jaroslav@235
  1528
                out.append('"').append(type).append("\" : {\n");
jaroslav@235
  1529
                cnt = 0;
jaroslav@235
  1530
            }
jaroslav@235
  1531
jaroslav@235
  1532
            @Override
jaroslav@235
  1533
            protected void visitAnnotationEnd(String type) throws IOException {
jaroslav@235
  1534
                out.append("\n}\n");
jaroslav@235
  1535
            }
jaroslav@235
  1536
            
jaroslav@235
  1537
            @Override
jaroslav@236
  1538
            protected void visitAttr(String type, String attr, String attrType, String value) 
jaroslav@235
  1539
            throws IOException {
jaroslav@266
  1540
                if (attr == null) {
jaroslav@266
  1541
                    return;
jaroslav@266
  1542
                }
jaroslav@235
  1543
                if (cnt++ > 0) {
jaroslav@235
  1544
                    out.append(",\n");
jaroslav@235
  1545
                }
jaroslav@250
  1546
                out.append(attr).append("__").append(attrType).append(" : ").append(value);
jaroslav@235
  1547
            }
jaroslav@235
  1548
        };
jaroslav@235
  1549
        ap.parse(data, cd);
jaroslav@235
  1550
    }
jaroslav@316
  1551
jaroslav@316
  1552
    private static String outputArg(Appendable out, String[] args, int indx) throws IOException {
jaroslav@316
  1553
        final String name = args[indx];
jaroslav@316
  1554
        if (name == null) {
jaroslav@316
  1555
            return "";
jaroslav@316
  1556
        }
jaroslav@316
  1557
        if (name.contains(",")) {
jaroslav@316
  1558
            throw new IOException("Wrong parameter with ',': " + name);
jaroslav@316
  1559
        }
jaroslav@316
  1560
        out.append(name);
jaroslav@316
  1561
        return ",";
jaroslav@316
  1562
    }
lubomir@317
  1563
lubomir@283
  1564
    private static void emit(final Appendable out,
lubomir@283
  1565
                             final String format,
lubomir@283
  1566
                             final CharSequence... params) throws IOException {
lubomir@283
  1567
        final int length = format.length();
lubomir@283
  1568
lubomir@283
  1569
        int processed = 0;
lubomir@283
  1570
        int paramOffset = format.indexOf('@');
lubomir@283
  1571
        while ((paramOffset != -1) && (paramOffset < (length - 1))) {
lubomir@283
  1572
            final char paramChar = format.charAt(paramOffset + 1);
lubomir@283
  1573
            if ((paramChar >= '1') && (paramChar <= '9')) {
lubomir@283
  1574
                final int paramIndex = paramChar - '0' - 1;
lubomir@283
  1575
lubomir@283
  1576
                out.append(format, processed, paramOffset);
lubomir@283
  1577
                out.append(params[paramIndex]);
lubomir@283
  1578
lubomir@283
  1579
                ++paramOffset;
lubomir@283
  1580
                processed = paramOffset + 1;
lubomir@283
  1581
            }
lubomir@283
  1582
lubomir@283
  1583
            paramOffset = format.indexOf('@', paramOffset + 1);
lubomir@283
  1584
        }
lubomir@283
  1585
lubomir@283
  1586
        out.append(format, processed, length);
lubomir@283
  1587
    }
jaroslav@398
  1588
jaroslav@398
  1589
    private void generateCatch(TrapData[] traps) throws IOException {
jaroslav@400
  1590
        out.append("} catch (e) {\n");
jaroslav@401
  1591
        int finallyPC = -1;
jaroslav@398
  1592
        for (TrapData e : traps) {
jaroslav@398
  1593
            if (e == null) {
jaroslav@398
  1594
                break;
jaroslav@398
  1595
            }
jaroslav@398
  1596
            if (e.catch_cpx != 0) { //not finally
jaroslav@398
  1597
                final String classInternalName = jc.getClassName(e.catch_cpx);
jaroslav@398
  1598
                addReference(classInternalName);
jaroslav@423
  1599
                if ("java/lang/Throwable".equals(classInternalName)) {
jaroslav@423
  1600
                    out.append("if (e.$instOf_java_lang_Throwable) {");
jaroslav@423
  1601
                    out.append("  stA0 = e;");
jaroslav@423
  1602
                    out.append("} else {");
jaroslav@423
  1603
                    out.append("  stA0 = vm.java_lang_Throwable(true);");
jaroslav@442
  1604
                    out.append("  vm.java_lang_Throwable.cons__VLjava_lang_String_2.call(stA0, e.toString());");
jaroslav@423
  1605
                    out.append("}");
jaroslav@423
  1606
                    out.append("gt=" + e.handler_pc + "; continue;");
jaroslav@423
  1607
                } else {
jaroslav@423
  1608
                    out.append("if (e.$instOf_" + classInternalName.replace('/', '_') + ") {");
jaroslav@423
  1609
                    out.append("gt=" + e.handler_pc + "; stA0 = e; continue;");
jaroslav@423
  1610
                    out.append("}\n");
jaroslav@423
  1611
                }
jaroslav@398
  1612
            } else {
jaroslav@401
  1613
                finallyPC = e.handler_pc;
jaroslav@398
  1614
            }
jaroslav@398
  1615
        }
jaroslav@401
  1616
        if (finallyPC == -1) {
jaroslav@401
  1617
            out.append("throw e;");
jaroslav@401
  1618
        } else {
jaroslav@401
  1619
            out.append("gt=" + finallyPC + "; stA0 = e; continue;");
jaroslav@401
  1620
        }
jaroslav@400
  1621
        out.append("\n}");
jaroslav@398
  1622
    }
jaroslav@0
  1623
}