Today I got a hello world program to run:
Oh yeah.[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!");
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 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.
1 comment:
Post a Comment