Simn / genjvm

13 stars 1 forks source link

Bytecode-level tests #15

Closed Simn closed 5 years ago

Simn commented 5 years ago

So the reason I worked on format.jvm.Reader was because I wanted to add support for bytecode-level tests in order to catch regressions there. The basic idea is to get the jvm-tests to read their own .jar file and then compare it to some specific input.

This requires writing a printer for https://github.com/Simn/format/blob/jvm/format/jvm/Data.hx#L47 which fetches items from the constant pool. Once we have that, we can come up with some nice way to define the expected bytecode in-line. I imagine a macro like this would work nicely:

        bytecodeEquals(<>
            iconst_0
            istore_1
            iinc 1, 1
        </>, {
            var i = 0;
            i++;
        });
nadako commented 5 years ago

Wow that's actually a pretty cool usage for inline XMLs :)

For my AS3 compiler, I wrote a macro that generates printer for all the syntax tree structures, because I was super-lazy to write them myself. I imagine something like this can be done here too?

Simn commented 5 years ago

At bytecode-level we should probably output whatever javap outputs.

nadako commented 5 years ago

I'm wondering if we should even somehow expose this to the users at some point. Because untyped __java__/@:functionCode is not applicable to the bytecode target, but maybe there are still some cases where one'd want to construct custom code?

Simn commented 5 years ago

Maybe yeah. That requires a parser in OCaml, but the instruction format isn't exactly complicated.

nadako commented 5 years ago

maybe we could get away with normal haxe syntax tho:

haxe.Jvm.code({
    Iconst_0;
    Istore_1;
    Iinc(1, 1);
});
Simn commented 5 years ago

That could be made to work. But is that really more fun than writing the code as string? Not sure...

Simn commented 5 years ago

Meh, at this point I don't really need these kinds of tests anymore. It would be nice to have, but I can't really be arsed to spend time on it.