Lately I’ve been getting into certain project ideas (which I’ll specify later if they ever become anything) that would require a GUI of some kind. Although I’ve had some success learning SFML, I’m not too much a fan of C and C++. Not because they’re bad languages, but I feel I’m spending more time making sure I’ve specified types and type casts correctly and things like that instead of actually coding1.
Also, my last C++ program segfaults right at a for loop declaration, for no discernible reason.
So, I decided to take a look at Zavolaj, which allows you to use external libraries, such as GUI toolkits, in Perl 6. I’m feeling excited about using Zavolaj and Perl 6 instead of C++ now, there’s just one roadblock left for me.
Parrot. Rakudo on Parrot is slooow, so slow that the last version of Rakudo I successfully compiled locally is 2011.09-46-g1c2c2d4, the culprit being compiling CORE.setting. I’ve barely tried since that last time (only once or twice more), because I must not have the memory to compile it.
Now I could just continue using C++ and live with it, but that won’t be very enjoyable, at least for a while2. So I wish to finally begin porting NQP to LLVM, so that I can ultimately have Rakudo run natively.
How to Port NQP
I see two ways of going about this task. The first is rewriting NQP, that is starting from scratch, and replacing all the PIR generating parts of the current NQP with LLVMIR generating parts.
Rewriting would seem to me to be the first choice, because it avoids the potential complexity of modifying parts of the existing code (bear in mind I haven’t examined NQP’s code deeply enough to know if this is more complex than a rewrite). A rewrite would also allow the option of not writing any of NQP in NQP, as long as the self-compiling part of the original NQP isn’t essential to its operation3.
The one problem is that the features of the NQP language aren’t well-documented. Except for a very helpful wikibooks page, I haven’t found much in the way of such documentation. Which would mean inspecting the original code and asking many, many question on #perl6 to get all the information needed.
Option two is rewriting the PIR generating parts of NQP to generate LLVMIR instead. Hopefuly this code resides in the .nqp files of NQP . After that, we have two choices. The first is that we could compile this LLVMIR-generating NQP to Parrot and update the bootstrap so we get .ll and .bc files instead of .pir and .pbc files, respectively. The other choice is to manually rewrite the .pir and .pbc files and then have a completely LLVM based NQP compiler.
This option could be either as simple as “just modify the nqp files in this directory and you’ll be targeting a new backend!” or as complex as “every single file needs modification. Good luck!”.
I hope to get started on this soon, so that I can use Perl 6 all the time .
1. Of course, I haven’t been coding C++ for long, so this could be just me being a beginner.
2. My general view on C++ is that every time I use C++, I appreciate Perl 6 more.
3. Maybe it’s a bootstrapped compiler because PIR isn’t very enjoyable . I’ll likely find out the reason very soon.