For some time now, I’ve been flirting with the idea of creating a programming language for my own selfish desires and needs. The fact of the matter is, though, that I have precious little time to do what have to do, let alone what I would like to do. The vacation I recently took to Ireland left me with substantial flight time with my laptop, and my trusty IDE, Eclipse. I’d like to introduce you to the result of two trans-Atlantic flights: Ariel.
Although I’d previously salivated over writing and using my very own language, it turns out I am largely more interested in virtual machines, i.e., a sandboxed software interpreter. Ariel is newest step in that learning process; it is a stack-based, bytecode interpreter coupled with a simple assembly-like language. Despite that simplicity, the assembly language is enough to compute any well-defined algorithm (barring any bugs), making it Turing-complete (insofar as machines can actually be). In concept, this makes Ariel as powerful as any other known computing device, which is pretty darn awesome. In practice, the VM is particularly limited by Java’s int size. I know, everyone just skipped a beat.
Ariel itself is written in Java. I hope everyone remembers to take a breath before moaning; as I’ve said, the primary purpose of this VM is education. My goal for these two flights was to implement a working system in a language and platform I’m comfortable with. Eventually, translating the source to another language (e.g., C++, D) will be trivial. Another potential issue is the fact that there are many other VMs which are much more successful, faster, and generally better thought-out. The existence of these commercial grade platforms is a non-issue for me, though.
The basic language I’ve cobbled up so far is a nasty mix of regular expressions and convoluted logic. And beside that, the language isn’t at all joyful to write in. And there’s still that nagging irritation that I’m interpreting bytecode in bytecode, which itself is usually intepreted and may occasionly be compiled to native machine code. The headaches explaining what this could cause, cause headaches. Regardless, I have a good idea of where I want to move next. I’m currently working on implementing constant folding for the bytecode, and by extension, a framework to add other optimization passes. There is an obvious need to write a better, higher level language; I’ll either be writing my own lexer and parser for this, or building from an existing framework. I’ve even got ideas of writing my own JIT compiler for Ariel, targeting JVM bytecode instead of the usual machine code. Outside these immediate goals, I’ll be moving toward the full-scale production of the language I’ve been calling Casper, whose design will be heavily impacted by what I have learned here.
This is what has been keeping me busy en route this past week. I’ve learned enough to be even more interested in the subject, and will surely continue. So to the naysayers and those interested alike, I offer a new adage. Reinventing the wheel is usually a waste of time, unless you happen to know how to make the wheel rounder or you intend on learning a whole lot more about wheels.