💾 Archived View for tozip.chickenkiller.com › 2022-06-23-toy-lang.gmi captured on 2023-05-24 at 17:51:05. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-07-16)

-=-=-=-=-=-=-

A toy language using Raku and QBE

Created 2022-06-23

You probably already know that Raku is a language intended to replace Perl 5.

QBE is a compiler backend in the same vein as llvm, but much simpler.

The Hare programming language uses QBE as an IR (intermediate representation).

I decided to dust off my old implementations of a really basic Basic. A C++ version I had didn't compile. Sigh.

I took a look at a version I had for Raku, and found it reasonably well-featured, and in under 300 lines of code.

I found grammars to be difficult to get working, and it turned me off of Raku a little.

Looking back on the code, however, I found it simple and accessible.

It's got me reconsidering the merits of Raku.

My big peeve with Raku is that it is dog slow. I am using a version 6.d, from 2020.12. I have read claims that Raku has been sped up, but I will exercise some scepticism on that score.

My implementation uses a "virtual machine", if you can call it that. I also have a version that emits ARM assembly. I had the idea of using QBE as a back end so that I could have native compiled code. That sounded like a neat idea. Reading through the docs, it seems that QBE lacks computed gotos. Major bummer. It rules out certain idioms. For example, when I toy around with microcontrollers, I sometimes use functions as if they were miniature state machines for use in cooperative multitasking. The function saves the current state (actually a goto label) in a static variable. When you call the function again it jumps to the address stored in the variable, thereby resuming where it left off.

QBE also seems a diffibult fit for constructing a compiled Forth. Forth has its own return stack. QBE performs jumps in terms of labels, you can't just pass it a variable which in turn holds an address. So you cannot do computed gotos.

So it's a little bit of a shame.