Many still consider JIT compilation a dark artform.
While writing a production JIT like numba[1] or V8[2] is a tall order,
the fundamental principles behind JIT are not.
To demonstrate, we'll use a toy JIT compiler for a turing complete language.
We'll go over a toy interpreter that uses op-code based dispatch to execute a program.
Then, we will learn the ins-and-outs of a dynamic code generator to emit x64 machine code.
Finally, we will benchmark both versions to see how they compare.
At the end, we'll look at "fancy" features like compile time translation of assembly to machine code instructions.
We'll be using Zig[3] – a systems programming language with drop-in C-interop
to write the compiler.
1: https://numba.pydata.org/
2: https://v8.dev/blog/maglev
3: https://ziglang.org