What code generation tools are recommended?

I’m looking to generate classes once and immediately use them many times for executing custom scripts. These are the options that I found:

Does anyone have any feedback on these options or any other options that I’m not aware of? I would appreciate any suggestions regarding an ideal approach.

Use-Case:
I’m creating a Kotlin back-end application which allows the user to type custom scripts for automation and custom computation. I defined my own beginner-friendly scripting language which also exposes an API for interacting with the application.

My parser creates an object representation of a script and then calls an execute method to run it. I’m running into performance issues with these scripts as they’re run millions of times.

1 Like

asm and ByteBuddy (which is built on top of asm) generate classes during run time. JavaPoet as well as KotlinPoet on the other hand generate classes during compile time.

This means that using Poet’s you must know exactly what you want to generate before running your program. Though using asm and ByteBuddy you generate stuff during run time, which means you can pass some data, such as user input during class generation. This gives you more flexibility but requires some resources during your program runtime. Also, ByteBuddy is a higher-level API than asm.

Regarding your use case, as far as I understand it you’ve basically created an interpreter for your scripting language. Given that, you’ll probably want to use asm or ByteBuddy to compile those scripts to Java bytecode.

1 Like

@mibac138 Thanks for helping narrow it down. I’ll start researching asm & bytebuddy. Perhaps I’ll get lucky and find a nice Kotlin DSL for these.