This Article IsCreated at 2023-11-26Last Modified at 2024-01-20Referenced as ia.www.b27

Thoughts on MIR and Codegen

MIR generates non-relocatable machine code from its own IR. It’s very fast, fast enough that you can cache the IR and generate machine code every time you run a program with MIR.

Initially I planned to wrote about MIR with a simple example. however, I ended up modifying MIR a bit, and did not find any new trick.

If you have prior understanding for assembly language, MIR’s documentation is pretty good! Make sure you read all the .md files in the repo though. Otherwise you may be just as confused as I was.

Is JIT needed at all?

JIT is not needed. interpreter is easier to write and safer.

a discussion with people in r/PL discord:

Janet Bytecode

Janet bytecode is probably better. in Janet, arrays and tables are first-class objects. if I ever have to make another language, using Janet bytecode as the codegen target is probably easier than using MIR as the codegen target.

References

MIR

branch predictor

meow5

arrayForth