r/ProgrammingLanguages • u/Relevant_South_1842 • Mar 26 '26
Discussion MIR intermediate compiler
https://github.com/vnmakarov/mir
i have been looking at MIR as a JIT backend for a language I’m building. Tiny, fast startup, not LLVM. Looks almost too good. Has anyone here built something on top of it?
For my language. I am thinking of having two modes, compiled and dynamic (neither of which I want to touch). Luajit for the default/dynamic and compiled functions if typed. I was going to just (try to) do (subset of)c transpilation with tinyC but then found something smaller, and faster and maybe easier to use?
25
Upvotes
8
u/suhcoR Mar 26 '26
I tried to re-target its C compiler and also the backend and found the code to be full of magic numbers (i.e. the fact that it's designed for 64 bit systems is widely spread around the architecture). Did you have a look at SLJIT? It's likely closer to what you want and more time-proven. If you also need a powerful debugger and a robust implementation, then ECMA-335 CIL with Mono is a very good target (see in use here: https://github.com/rochus-keller/oberon/). You can also use LuaJIT as the backend instead (see in use e.g. here: https://github.com/rochus-keller/luon/). I found Mono to be about twice as fast as LuaJIT and more robust, but if your language is single-threaded without complex FFI, LuaJIT is nice. See also https://github.com/rochus-keller/ljtools/ and https://github.com/rochus-keller/monotools.
1
u/Germisstuck CrabStar Mar 27 '26
Maybe try making a copy and patch jit? My compiler is copy and patch (granted it writes to an object file), and it is quite small (for arithmetic and if-else branding)
6
u/Pretty_Jellyfish4921 Mar 26 '26
I never heard of this repo, but there's another "popular" compiler backend called QBE and looks pretty straightforward, another option that IMHO feels that has a lot more potential is Cranelift (written in Rust) that is used by Wasmtime and experimentally by Rust for debug builds. Note that Cranelift supports AOT and JIT.
4
u/ravilang Mar 26 '26
Yes - see https://github.com/dibyendumajumdar/ravi
MIR JIT is excellent but has no support for debugging JITed code.
I am looking forward to https://github.com/dstogov/ir as an alternative.
1
u/Dapper_Compote_8628 Mar 26 '26
This does indeed look so, so cool. I bookmarked (and starred) it.
1
u/[deleted] Mar 26 '26
[removed] — view removed comment
4
u/[deleted] Mar 26 '26
[removed] — view removed comment