new jitescript release is out!

Finally, after more than 6 months, jitescript gets a shiny new release!

jitescript?

Jitescript is an API for generating java bytecode. Yeah, the output is scary at best. Bytes, 0xCAFEBABE, you know, weird stuff.

My main motivation to write it came when I discovered @headiusbitescript.

main do
  ldc "Hello, world!"
  aprintln
  returnvoid
end

Whoa, even if it’s bytecode, its very readable to me! And Immediately I remembered ASM, the swiss knife of bytecode generation on the JVM. ASM is very useful (and tons of projects use it), but its API is really hard to grok.

With great power comes great responsibility!

I was working on dynjs already and thought: “why can’t I have something cool like bitescript for my bytecode generation stuff?”

We know that the java language is verbose, but we can try harder to keep code small and concise. So I built jitescript, mostly as a nice DSL around ASM

JiteClass jiteClass = new JiteClass(className) { {
    defineMethod("main", ACC_PUBLIC | ACC_STATIC, sig(void.class, String[].class),
        newCodeBlock()
            .ldc("helloWorld")
            .aprintln()
            .voidreturn();
    );
} };

It was used even for a wicked s-exp compiler!.

Things evolved a lot since jitescript‘s first release, and here are some highlights:

  • configurable superclass for the generated class
  • configurable interfaces to be implemented
  • handy helpers to generate things like default constructors, etc
  • we now include ASM4.0, shadowed under a internal package (this might change on the next release, stay tuned)
  • codeblocks are aware of return calls

why should I care?

Jitescript is what allows dynjs to have a more readable compiler:

Let’s use 2 > 3 JavaScript code as an example:

This is the equivalent code on dynjs

newCodeBlock()
    .append(l.getCodeBlock()) // the literal '2'
    .append(r.getCodeBlock()) // the literal '3'
    .invokedynamic(operator, // the '>' operator
                   sig(Boolean.class, Object.class, Object.class),
                   RT.BOOTSTRAP, RT.BOOTSTRAP_ARGS);

How cool is that?

jitescript‘s future

On the project’s roadmap we have some cool tasks:

  • currently we use ASM‘s tree API, and would be nice to split bytecode emitting on two modes: tree and visitor.
  • improve JavaDocs
  • re-evaluate the need to keep ASM vendored.

Thoughts?