Monday, February 22, 2010

More progress on OO language interpreter

Garbage collection is now (I think?) working in Thud, my object-oriented scripting language:
[dhovemey@nobby]$ cat LongLoop.thud
# With the heap set to 8192 objects,
# this program causes the garbage collector to run.

import System::IO;

var n = 0;
while (n < 9000) {
n = n + 1;

[dhovemey@nobby]$ thud LongLoop.thud
At this point, the compiler and bytecode interpreter are more or less working. What remains is to add all of the standard library classes needed to make it a useful language: I/O, containers, regular expressions, etc.

I began this project with the idea that implementing a language like Python or Ruby would be a fairly easy task. Well, it was harder than I thought it would be, but really not that hard overall. Right now, there are about 15,000 lines of source, including comments and whitespace. This is bloated somewhat by the 2,500 or so lines generated by bison for the parser, and also the fact that I essentially recreated the Java I/O classes (streams, readers/writers, etc.) rather than use iostreams.

[Aside: is it just me, or is iostreams ridiculously complicated?]

Eventually, I'm hoping to use Thud as my main day-to-day scripting language. In the longer term, it would be an interesting project to replace the bytecode-interpreter-based virtual machine with one based on LLVM.

Wednesday, February 3, 2010

Last one

I could post more of these, but I'll stop with this one.

More random art

This random art stuff is really just too cool for words:

Random Art

I'm implementing Christopher Stone's Random Art Nifty Assignment in preparation for assigning it in a data structures course I'm teaching. Since the assignment involves the creation of "random" functions of two variables, it's a good opportunity to discuss the idea of using trees to represent expressions.

Obligatory screenshot of first successful run of the program:

This is an extremely cool assignment.