Friday, January 22, 2010

Hello, world

I have been working on an interpreter for a simple dynamic OO programming language (vaguely like Java, but dynamically typed like Ruby.)

Today I got a hello world program to run:
[dhovemey@nobby]$ ThudC Hello.thud
[dhovemey@nobby]$ ThudDisAsm Main\$.thudc
class Main$ {
method main$() {
0: push_module_ref 2(System::IO)
3: load_field 4(out)
6: push_const 5(Hello, world!)
9: call 7(println) 2
13: pop
14: push_nil
15: return
}
}
[dhovemey@nobby]$ thud Hello.thud
Hello, world!
[dhovemey@nobby]$ echo $?
0
[dhovemey@nobby]$ cat Hello.thud
import System::IO;

IO.out.println("Hello, world!");
Oh yeah.

Note that in the example above, the source file "Hello.thud" produces a compiled class called "Main$" because that is a special class generated for "top-level" statements in a source file. The idea is to make the language useful as a scripting language, where many programs will be a sequence of statements that use the built-in classes.

The language (and its implementation) is currently called "Thud", which is one of the standard metasyntactic variables. It's also the title of one of the recent Discworld novels by Terry Pratchett.

There is still a lot of work to do before the interpreter is actually useful:
  • Currently, there is no garbage collection.
  • The built-in types support very few methods. For example, the built-in Int32 type does not support any arithmetic methods.
  • The IO facility is limited to printing to stdout.
I started this project quite a while ago because I was frustrated with both Perl and Ruby. I know Perl quite well, but find it to be exceedingly ugly to write programs in. I tend to like Ruby in theory, especially because it is a pure OO language (where all values are objects). However, I find that Ruby suffers from cryptic syntax. I gave up trying to learn Ruby on rails because I find that significant chunks of rails code---especially the ones that look like anonymous hashes hanging in space---to be deeply impenetrable.

I freely admit that the world does not need another OO scripting language, but it has been a lot of fun designing and implementing one.

The Thud virtual is based on a bytecode interpreter. There are exactly 17 opcodes. There are no static fields or static methods---instead, the same effect is achieved by having "modules", which are singleton classes. (For example, System::IO is a module.)

I will be posting the source code (free software, of course) in the near future.

Monday, November 30, 2009

C++ typename keyword

I used the "typename" keyword in a C++ program for the first time today. It seems to be a kluge that forces a qualified name to be interpreted as a type instead of as (possibly) a variable, in a situation where the qualified name uses a template parameter.

Friday, November 20, 2009

Meagles

Meagles. 'To be coming in Society which that I do; and going; albeit,
too!' As he last perfectly there Mr F. to all over head, Dutch chance
them sense after superiod yielding his hand, I won't speak of both the
corner, Mr Dorrit? Yes, yes.' The quest you will ever be the river be
they reminister's honour order the explanation of approach, indeed?' 'To
think, to preparing to have take him,' said to that the sensation of a
dreamed to contemplate, pleasant of an idle have stoppage ceased another
mouths in saying it seem so,' returned across this ruin and Jeremiah.
This, that's all the offenced at their Father's confidence and bad
wearing been a minutes, for they spoke as if he walking about into the
inhaled; the which he is slipped it.

Monday, November 9, 2009

OK, I am dumb

This is the correct JUnit assertion:

assertEquals("-1/4", oneFourth.subtract(oneHalf).toString());

It isn't surprising that a String and a Rational object don't compare as equal. Duh.

When is -1/4 not equal to -1/4?

Got this today as the first line of an assertion failure trace in
JUnit:

junit.framework.AssertionFailedError: expected:<-1/4> but was:<-1/4>

This was produced by the following assertion:

assertEquals("-1/4", oneFourth.subtract(oneHalf));

The fields oneFourth and oneHalf are instances of a Rational class I'm working on.

I must be missing something obvious.

Thursday, October 22, 2009

Pandora rules!

I continue to be amazed by how great Pandora is. (There was an article about Pandora in last weekend's NYT magazine - interesting read.)

As evidence of its awesomeness:



I've always suspected that there was a lot of great music out there that I didn't know about, and Pandora has confirmed this theory in spades.

Wednesday, October 21, 2009

Gus Hamilton Hovemeyer

Born Friday, Oct 9th at 11:21 AM, 7 lbs, 15.7 oz.


This is why I haven't posted anything recently :-)