Cliff Hacks Things.

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.)

1 Comments:

Post a Comment

<< Home