Our great sponsors
-
compiler
an incomplete toy barebones compiler backend for amd64 x86_64 in Python and an incomplete JIT compiler written in C (by samsquire)
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
This is so awesome.
My dream is to understand JIT compiler tech. Does anybody have any resources?
I've read the documentation of Pypy but I don't understand everything. And I've looked at dynasm for luajit.
I also read about Ruby's YJIT.
Do JIT compilers create machine code templates of bytecode instructions and then emit that? Or do they create basic blocks and then emit that as machine code?
My amd64 compiler is toy barebones that can evaluate ADD and MUL expressions https://github.com/samsquire/compiler I would love for it to become a JIT compiler!
I'm no expert, but you might be interested in: https://llvm.org/docs/tutorial/
There's also a Haskell version if you'd prefer: https://www.stephendiehl.com/llvm/
Idk how to do this in python as I'm not really good with it, but in C, to make your compiler a JIT, you would `mmap` a region as writeable, write the machine code to it that you already know how to generate, `mprotect` it as PROT_EXEC instead of PROC_WRITE, cast the pointer to the region to a function pointer, and then call it. These functions may be available in the python sys package but I don't really know.
I've implemented a "JIT" that takes machine code as hex and does this. Warning: it's complete garbage with no error checking but is a good proof of concept. https://gist.github.com/martinjacobd/3ee56f3c7b7ce621034ec3e...