Re:How to write a simple JIT compiler
by eatonphil on Wednesday December 15, 2021 @10:30AM
(#29567235)
Eli Bendersky has another great, even simpler introduction (from 2013) to JIT compiling but with hardcoded instructions [0]. And a more recent post on JIT compiling Brainfuck [1].
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.
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 ufo on Wednesday December 15, 2021 @12:35PM
(#29569050)
To be a bit less pedantic, this is an area that is kind of ambiguous... From one point of view it's still fair to call this "just in time".
I wish there was terminology to differentiate between kind of "on demand AOT compilation" and jits that do jitty stuff that can't be done ahead of time.
Re:How to write a simple JIT compiler
by chrisseaton on Wednesday December 15, 2021 @01:38PM
(#29569920)
> I wish there was terminology to differentiate between kind of "on demand AOT compilation" and jits that do jitty stuff that can't be done ahead of time.
Some people differentiate between dynamic JIT compilation and static JIT compilation.
Re:How to write a simple JIT compiler
by ufo on Wednesday December 15, 2021 @01:11PM
(#29569514)
Arguably the term "ahead of time" also suffers from the same problem. Among compiler people, "ahead of time" vs "just in time" sometimes has to do with whether the compiler uses run-time information when compiling. But the names don't reflect that, they talk about when the compilation happens.
Re:How to write a simple JIT compiler
by JulianWasTaken on Wednesday December 15, 2021 @01:22PM
(#29569666)
More good JIT tutorials can also be found in the PyPy ecosystem, which provides tooling to add JITs to any interpreter for a language implementation written with its (R)Python toolchain.
Re:How to write a simple JIT compiler
by Rendello on Wednesday December 15, 2021 @01:45PM
(#29570020)
Terry Davis learned in university and on the job before the schizophrenia 'kicked in'. How he was able to focus enough to write so much solid code after the illness started, I'll never know.
Re:How to write a simple JIT compiler
by hutzlibu on Wednesday December 15, 2021 @04:16PM
(#29571738)
It is also possible, that the illness gave him the fanatism required to maintain the focus over the years, to come so far with TempleOS.
(That same fanatism and crazieness also prevented people from participating I guess.)
Re:How to write a simple JIT compiler
by Rendello on Wednesday December 15, 2021 @04:55PM
(#29572094)
I bet it was less about fanaticism and more about time. Previously, he had worked full time and made money. He wasn't able to work after the illness (I think I read somewhere that he was rehired by his old company, but only lasted a few weeks).
[0] https://eli.thegreenplace.net/2013/11/05/how-to-jit-an-intro...
[1] https://eli.thegreenplace.net/2017/adventures-in-jit-compila...
Mine uses the DynASM framework developed for LuaJIT, so that the assembly instructions can be written symbolically: https://luajit.org/dynasm.html
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
Not necessarily. You might want to JIT a domain-specific abstraction, like a regular expression engine.
https://en.wikipedia.org/wiki/Multi-stage_programming
The classic example is MetaOCaml:
https://en.wikipedia.org/wiki/OCaml#MetaOCaml
As an example, here's a JIT compiler I made for BrainFuck that defers the compilation of some loops: https://github.com/danthedaniel/BF-JIT/blob/master/src/runna...
I wish there was terminology to differentiate between kind of "on demand AOT compilation" and jits that do jitty stuff that can't be done ahead of time.
Some people differentiate between dynamic JIT compilation and static JIT compilation.
If the code isn't compiled until it's executed, "ahead of time" seems extremely confusing
I assume you mean something like Common Lisp does with COMPILE? (http://clhs.lisp.se/Body/f_cmp.htm) That's just called "compilation" in some circles.
A Basic Just-In-Time Compiler https://nullprogram.com/blog/2015/03/19/
A JIT Compiler Skirmish with SELinux https://nullprogram.com/blog/2018/11/15/
E.g. here's a recent video: https://www.youtube.com/watch?v=fZj3uljJl_k
Actually... http://www.softwarepreservation.org/projects/apl/Papers/DYNA...
TempleOS wasn't the first thing he worked on after becoming ill, he'd previously been working on a three-axis milling machine. https://en.wikipedia.org/wiki/Terry_A._Davis#Onset_of_illnes...