r/ProgrammingLanguages • u/Key_River7180 Nain. • 22d 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.
2
u/tiger-56 20d ago
Write a Nain interpreter in Scheme. Use the interpreter to write your compiler.
1
u/Key_River7180 Nain. 18d ago
Why an interpreter?
an interpreter would make my memory model extremely slow and expensive, it is based in graph stuff that can be mostly done statically, but an interpreter would make this both know a lot of weird shit and do weird shit at runtime
now users need two dependencies instead of one and it has to either have an ugly wrapper script or an ugly invocation
2
u/tiger-56 17d ago
An interpreter is the quickest and simplest way to implement the semantics of your language. It won't do weird shit if you implement your language spec correctly. The only purpose of the scheme implementation is to bootstrap and then be discarded. Why bring in complexities of a QBE or C backend only to throw them away. Writing an interpreter actuallly reduces your dependencies to Chicken and LLVM. Under your proposal, you're injecting QBE or C in the pipeline, another dependency! Regardless of your implementation, you will need some sort of build script anyway. Your arguments don't make sense.
1
u/gio_vs 18d ago
Eu escolheria C. Como você só vai usar esse compilador para testar recursos da linguagem e compilar o compilador definitivo, acho que não vale a pena complicar muito. Gerar C é mais simples, facilita a depuração e ainda tem como aproveitar a infraestrutura de compilação C que você provavelmente já tem, considerando o CHICKEN. Também é mais portátil que QBE.
1
u/Key_River7180 Nain. 18d ago
Well, C is definitely portable and ubiquitous and debuggable but I'd argue it's ever so slightly harder to output C than QBE IR. QBE IR is an extremely simple language too, but QBE IR is SSA so I must do some weird trickery to lower it too, it's a single pass, not-very-optimizing compiler too.
I'm leaning C here lol
(srry for not responding in Portuguese i can only read it not write it)
2
u/[deleted] 21d ago
This doesn't make much sense. If the bootstrap compiler generates QBE or C, wouldn't the self-hosting one do the same?
Switching implementation language from Scheme to your language wouldn't affect that part of it. It would be a separate development stage, unless you are planning to combine it so that the self-hosted version also generates its own native code or whatever.
If planning to have users, you might also consider whether they need to build your compiler from source code, in which case that will be harder when it is in your language. And also what dependencies they will need to process whatever output it produces.
As for the choice between QBE and C, use whichever works and is simplest, and again consider any users you might have.