Hacker News new | ask | show | jobs
by Arwill 391 days ago
You mean like #define + #ifdef?
1 comments

Very niche but: https://github.com/SpongePowered/Mixin

It's not really possible to implement in the same way for many other languages, but something like this but for source code transformations (rather than bytecode, or machine code for compiled languages) is probably the kind of thing they're thinking of.

Mixin allows you to insert code into methods, modify calls to functions, read/write to local variables, modify constants, and a lot more in that type of vein. It is the way mods are made in the Fabric mod loader for Minecraft. I believe Forge also reluctantly added support for Mixin back in 1.16 or so.

Back in the day I used AspectJ to do something like this. The interface was decently friendly and IMO decorator style patterns are going to be the most user friendly approach to something like this. You won’t ever find a universal solution to this though without doing transpilation to some common format that gets morphed (ASM in your example, but I could see also a theoretical world where WASM would offer this)