Cliff Hacks Things.

Sunday, October 22, 2006

propasm, the Propeller Assembler

I've released propasm, my assembler for the Parallax Propeller eight-core microcontroller. Unlike the Parallax-provided assembler, it:

  • Runs on practically anything;

  • Can be automated from scripts or Makefiles;

  • Provides really good feedback;

  • Supports characters outside of US English;

  • Is written in Java;

  • Will be open-sourced shortly.



This was an interesting project for me, because it involved a number of separate areas of my brain. This was my first hand-written traditional parser; I've written plenty of parsers before, but this one is broken into a traditional scanner/lexer and recursive-descent parser. Since I was writing the parser by hand, I was able to make the error messages clear and specific — something generated parsers often lack.

I also had to reverse-engineer the binary format and parts of the instruction set, as Parallax's documentation on both is spotty.

Since it's in Java, rather than x86 assembler (like Parallax's), it's somewhat slower. It takes all of 10ms to load, parse, wire, and write out a decent-sized program.

...of course, to use Parallax's, I have to boot Windows, start an IDE, open my text file, and click four times in a menu. I think propasm wins overall. :-)

Update: I'm already on my first point release; I'd made an error on the I/O code that caused UTF-8 to be mangled on some platforms. Fortunately, my test case using ウーロン茶 as a variable name failed. If only I'd had the tests written when I released... :-)

Thursday, October 12, 2006

Mongoose Reborn

In any other context, this would probably be a bad thing:

Mnemosyne:~/Projects/m3/vm cbiffle$ ./vmtest test.mgm
HEAP: 0x2800400 - 0x2801400
HALT


But in this case, coming to a screeching halt is exactly what I wanted.

M3VM, the third virtual machine for Mongoose, has officially booted some code (even if that code was a single halt-catch-fire instruction). This is the third time in two years that I've rewritten the VM from scratch, proving hands-down that I have very weird hobbies.

This time, it's in C++, which has been trippy. I haven't written any large C++ apps in three years, and I really dislike the language — but it happens to be ideal for this, so I'm ignoring the nasty bits and making do. M2VM was written in GNU C, and M3VM isn't much different — but I can bundle my functions into classes now. For an object-head like me, that's a big plus.

Working with a higher level of abstractions has also let me focus less on the details, and more on the goal. I've built the object model the way I wanted it, and I'm working on the neat Self-like optimizations I've had planned.

To get to the triumphant HALT, the machine had to

  • Load the base module, in the new Mongoose Module format;

  • Wire all the objects together, including the ones that have to exist in phantom form (like Object, Class, and Array) before they are loaded;

  • Start the interpreter, written in Mongoose and translated by Ruby to C++;

  • Resolve the entry-point method by name;

  • Fall over screaming.



The rewrites are quicker each time. Not only is the line count of M3VM significantly lower than M2VM, it took less than a week (part-time) to write. It's also considerably smarter — the garbage collector, my fourth, has learned a lot of neat tricks, and runs in milliseconds even for fragmented 64MB heaps.

Soon, I'll have the compiler working, so I can quit writing code in a hex editor. :-)

(P.S. If you, too, are authoring files in a hex editor, you need to go download Hex Fiend. Seriously. It is, hands down, the best hex editor I've ever used — including the ones I've written.)