r/ProgrammingLanguages • Nain. • 20d ago

Help transpilation - Bootstrap compiler

So, I am making a compiler for my language, Nain, in CHICKEN Scheme. Should I output QBE IR or code for C or another language? This is a bootstrap compiler, I will use it only to test new language features and to compile the self hosting compiler so yeah.

1 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/AustinVelonaut Admiran 20d ago

You use T diagrams to figure out the path from a bootstrap compiler to your final self-hosted compiler. This video describes the process well.

1

u/Key_River7180 Nain. 20d ago

well i didnt know about that

2

u/AustinVelonaut Admiran 20d ago

Most self-hosting compilers are "continuously bootstrapped", meaning you add new features / capabilities to the existing compiler sources, compile with the existing compiler, and get a new compiler that understands the new features/capabilities. So you don't have to do everything in one step from original bootstrap compiler to final self-hosted compiler -- you can do the process in stages.

So it doesn't matter what the original bootstrap Nain compiler (written in Scheme) generates, as long as you have a path from that to an executable binary. Then rewrite the compiler in Nain that produces LLVM, run that through your bootstrap compiler, and get the Nain->LLVM compiler. Or you can do an intermediate stage, where you write a Nain -> C compiler written in Nain, then change the backend out to LLVM, run that through, and get a Nain -> LLVM compiler.

1

u/[deleted] 20d ago

The intermediate stage sounds a much better idea. Then the first compiler written in Hain can be a simple port of the Scheme one that generates the same output.

Otherwise using a brand-new language to write a quite different compiler with a complex LLVM backend, sounds too ambitious to do in one go.

But also, if LLVM is on the cards anyway, why doesn't the scheme version generate that instead of C or QBE - what limitations does Scheme has that Nain will not have?

1

u/AustinVelonaut Admiran 20d ago

It depends on how LLVM is used. You can generate LLVM asm or LLVM bitcode as output, then run that separately through a standalone LLVM. Or you can directly use LLVM IR and link to an LLVM library. But the later requires that your host language have interop bindings with the LLVM library (C/C++ foreign-function interface). I don't know if Chicken scheme has that or not.

1

u/Key_River7180 Nain. 11d ago

QBE is easier