3 ms·
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 w
by eterps 5y ago
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 https://github.com/eterps/loader/blob/master/syscall.nim
- yholio 5y agoWonder 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.
- naasking 5y agoYes, these are called multistage languages: https://en.wikipedia.org/wiki/Multi-stage_programming https://en.wikipedia.org/wiki/Multi-stage_programming The classic example is MetaOCaml: https://en.wikipedia.org/wiki/OCaml#MetaOCaml https://en.wikipedia.org/wiki/OCaml#MetaOCaml
- naasking 5y ago> 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.