4 ms·
I'm no expert, but you might be interested in: https://llvm.org/docs/tutorial/ https://llvm.org/docs/tutorial/ There's also a Haskell version if you'd prefer:
by jacobmartin 4y ago
I'm no expert, but you might be interested in: https://llvm.org/docs/tutorial/ https://llvm.org/docs/tutorial/
There's also a Haskell version if you'd prefer: https://www.stephendiehl.com/llvm/ 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/3ee56f3c7b7ce621034ec3ecbc8e13f1 https://gist.github.com/martinjacobd/3ee56f3c7b7ce621034ec3e...