News for hackers. Stuff that matters.
Re:How to write a simple JIT compiler by eterps on Wednesday December 15, 2021 @10:54AM (#29567684)
Experiments like these are really fun to do in a small setting. In reality you would only get to this point after having built a complete programming language with all its parts. But in a situation like this you can start at the end, focus on generating the machine code, putting it in a memory buffer and instructing the CPU to start running it at that point. It can hardly be called a JIT compiler of course, but you definitely get an impression of its mechanics.

A couple of years ago I did the JIT 'kickstarting' machinery for fun in the Nim language: https://github.com/eterps/loader/blob/master/syscall.nim

Re:How to write a simple JIT compiler by naasking on Wednesday December 15, 2021 @08:59PM (#29573975)
> In reality you would only get to this point after having built a complete programming language with all its parts.

Not necessarily. You might want to JIT a domain-specific abstraction, like a regular expression engine.

Re:How to write a simple JIT compiler by yholio on Wednesday December 15, 2021 @07:03PM (#29573152)
Wonder if you could create a new language using this approach, designed for efficient JIT compilation: maximum programmer convenience that is still coherent with maximum runtime performance, whiteout any learning curve for the user other than the language itself.
Re:How to write a simple JIT compiler by naasking on Wednesday December 15, 2021 @09:01PM (#29573984)
Yes, these are called multistage languages:

https://en.wikipedia.org/wiki/Multi-stage_programming

The classic example is MetaOCaml:

https://en.wikipedia.org/wiki/OCaml#MetaOCaml