Angel \”Java\” Lopez on Blog

May 12, 2010

Objects in AjIo (Part 1)

Filed under: .NET, AjIo, C Sharp, Open Source Projects, Programming Languages — ajlopez @ 1:50 pm

I was writing an Io-like interpreter, in C#. It’s named AjIo (what else?). I wrote about it in my previous post:

Working in AjIo: Io-like interpreter in C#

Now, I want to discuss the object design I adopted in this project. AjIo is not a true, full reimplementation of Io programming language. It’s my toy project. I want to rewrite Io (partially) so I can use .NET class library and native objects. I’m a fan of using existing VMs and class library (.NET, Java) to reimplement dynamic, functional and other kind of languages.

IObject interface is the mother of all objects in AjIo:

More detail in direct code:

namespace AjIo.Language
{
    public interface IObject
    {
        string TypeName { get; }
        IObject Self { get; }
        IObject Parent { get; }
        object Evaluate(object expression);
        void SetSlot(string name, object value);
        object GetSlot(string name);
        void UpdateSlot(string name, object value);
    }
}

The slot methods are used to implement dynamic properties in AjIo objects. UpdateSlot needs that the slot was previously defined, with a SetSlot. As I choose to support native objects, the value parameter is a .NET object.

TypeName property is used to print object. That is, evaluating:

Object clone

prints as

Object_14fd2b5

The “Object” prefix is the type name of the new object. Note that Object is an object in AjIo, not a class name. And it’s the top object in the parent hierarchy.

Self property points to the current object. It could not be the current .NET object pointed by this C# keyword. It will be discussed in an upcoming post about local objects.

Original Io is a prototype based language. Each Io object has a Protos slot, a list of prototypes to which it belongs. Using YAGNI, I didn’t need a list of prototypes, yet. Only one in pointed by Parent property. There is a top object without parent, and is the prototype of all other AjIo objects.

Evaluate usually receives a message (message name plus arguments), but, again, native object processing implies that I use an object as expression parameter.

As this project is work in progress, the above interface is not carved in stone, and it could suffer changes in the near future. I’m using TDD: if in a case I need something more in this interface, I will add to it. But I guess it’s taking form. Only a major refactoring could affect it. The current source code is at:

http://code.google.com/p/ajcodekatas/

under the AjIo folder.

Next posts to write: description of the base class implementations of this interface.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: