Daily Archives: April 30, 2010

Working in AjIo: Io-Like interpreter in C#

Last year, I discovered Io programming language:



Io is a prototype-based programming language inspired by Smalltalk (all values are objects, all messages are dynamic), Self (prototype-based), NewtonScript (differential inheritance), Act1 (actors and futures for concurrency), LISP (code is a runtime inspectable/modifiable tree) and Lua (small, embeddable).

It has a simple syntax, and its features are based in functional languages, Smalltalk, Self and others. As usual, I want to write my own version, with a twist: support for native objects. That is, to implement an interpreter over a virtual machine plus class libraries. The current choices are Java or .Net.

Two weeks ago, @MartinSalias pointed me to Io, again. Then, past weekend, I started my own implementation, based only in the written specification. It will be not exactly the same language, and it is still work in progress.

The code is in my Google project AjCodeKata:


in the trunk, under AjIo folder. There is a .NET solution, with three projects:

The class library is the core, the console program can be used to interact with the interpreter, and the test project has the test I wrote during the design/coding process.

Actually, I have written the lexer, the parser, and the main languages objects, using TDD approach, as usual. You can write:

Some days ago, I implemented the assignment operators (syntax suger over setSlot, newSlot, updateSlot):

but, now, you have native .NET object support:

Next steps:

– Write more comparison operators (I only write ==)
– Native numbers (now, only ints are parsed, but other can be managed, try 1 / 6, it returns a real)
– Precedence in arithmetic operators (now 2 + 2 * 3 returns 12, instead 8)
– for, foreach, range, and more (I only write if())
– block() (I have method())
– include()
– Begin to write some Io library objects

About last point: I should decide how to implements things like:

List clone

Possible approaches:

– List as a derived object (Object clone) with its own slots, wrapping a native list
– List clone returning native ArrayList, then ArrayList type has associated “slots”
– No List, and use directly the native objects

As in AjSharp, original Io has agents and coroutines. I want to add AjSharp features (agents, goroutines, channels, queue channels, futures) to AjIo. Original Io implements agents with virtual machine “threads”: that is, it’s not using operating system threads, the virtual machine executes the many agents code, switching from one code to another during running (I guess, I don’t see the implementation code in Io). I won’t take that approach, in my first attempts.

As usual, I had fun written this stuff!

Keep tuned!

Angel “Java” Lopez