Earlier I wrote about Ariel, my new bytecode, stack-based interpreter. One of the biggest grievances I had with it was the fact that it was written in Java. Ordinarily I would never shy away from using Java, but the recursive nature of that proposition in this context is mind-numbingly stupid. Coming from a strict C-based shop my first instinct was to use C. Five hours of reinventing the “standard library” wheel, I realized I was just spinning my own wheels: I don’t know how to make that wheel rounder, and it wasn’t the time to learn more about it either. C is largely ill suited for the object oriented programming I am used to. A coworker suggested I try C++. After getting over my initial nausea, I sat down to write.
Work on porting Ariel to C++ is on its third day, and is more or less complete. The same sample factorial program takes less time to execute than the JVM needs to startup on my aging T43 when compiled using Cygwin’s GCC; using MSVC or ICC cuts that number roughly in half. On my MacBook Pro, though, that same program executes in less than hundredth of a second. This is not bad for a few days of work, if I do say so myself. The only part of the original implementation is the more robust syntax features (specifically block definition) that required some ugly regular expressions. I’ve decided to ignore these features for now and instead focus on bolting on a true grammar.
I’ll be using LEG (a slight variation of a PEG) and I’ll hopefully be inventing my own AST. peg/leg is a C project, but I did find a useful port to C++. I forked it to produce warning free compiles using GCC. All that remains after that is to figure out how to traverse that tree to produce usable bytecode. In my limited experience with C++, I’d always stuck with Qt. Ariel’s C++ implementation though uses only the STL, and that hasn’t been a bad experience at all. Sticking with member initialization on the stack greatly simplifies memory management and STL containers are provide everything I need. The only issue I’ve been having is ridiculous error messages from the compiler when using templates- gah! I dare say, though, I’m having fun! and may have to revoke my previous sentiments on the topic. I, for one, welcome our new C++ overlords.