usethesource / flybytes

Flybytes is an intermediate language between JVM bytecode and software languages (DSLs, PLs), for compilation and decompilation.
BSD 2-Clause "Simplified" License
16 stars 6 forks source link

decompiling lambdas fails due to missing local variable declarations #10

Open jurgenvinju opened 4 years ago

jurgenvinju commented 4 years ago

This is a disassembled lambda where you can see that there are no LOCALVARIABLE instructions for stack location 0 and 1. This stops their LOAD instructions from being decompiled and that blocks further decompilation steps downstream.

My guess is that the creating scope is captured by the 0 and 1 stack locations in lambda's, and so we need to add rules for recovering expressions for these LOADs somehow.

methodDesc(
      void(),
      "lambda$11",
      [
        object("java.lang.Object"),
        object("java.lang.Object"),
        object("io.usethesource.vallang.IConstructor"),
        object("java.lang.Integer")
      ]),
    [
      var(
        object("java.lang.Object"),
        "arg_0"),
      var(
        object("java.lang.Object"),
        "arg_0"),
      var(
        object("io.usethesource.vallang.IConstructor"),
        "arg_0"),
      var(
        object("java.lang.Integer"),
        "arg_0")
    ],
    [asm([
          LABEL("L20804602"),
          LINENUMBER(589,"L20804602"),
          ALOAD(0),
          ALOAD(3),
          INVOKEVIRTUAL(
            object("java.lang.Integer"),
            methodDesc(
              integer(),
              "intValue",
              []),
            false),
          ALOAD(1),
          INVOKESTATIC(
            object("java.lang.reflect.Array"),
            methodDesc(
              void(),
              "set",
              [
                object("java.lang.Object"),
                integer(),
                object("java.lang.Object")
              ]),
            false),
          RETURN(),
          LABEL("L1344519051"),
          LOCALVARIABLE(
            "S",
            object("io.usethesource.vallang.IConstructor"),
            "L20804602",
            "L1344519051",
            2),
          LOCALVARIABLE(
            "ind",
            object("java.lang.Integer"),
            "L20804602",
            "L1344519051",
            3)
        ])])