Presenting AjSoda

A year ago, I wrote a post, in Spanish, commenting Ian Piumarta work:

Self-sustaining sysmtes, Cola, Pepsi y Mate

I proposed that an implementation of Ian Piumarta ideas, in .NET or Java, could be possible. Instead of using C as underlying language, it could be reimplemented over a virtual machine language, with a rich class framework, and an automatic garbage colector. For me, it looks as an interesting idea, that deserves some attention.

To understand Piumarta and Warth ideas, they described a minimal implementation at:

You’ll find minimal object implementation, in those papers. A diagram:

(taken from

Open Extensible Dynamic Programming Systems Dls


This past week, I was working on an implementation in C# of such ideas. I commited my work in my AjCodeKatas Google Code project, at:

The solution has four projects (two library classes, and the respective test suites). The main project is AjSoda:


An introductory diagram:

IObject is the interface I wrote to represent a generic object. It has a payload, an array of references to arbitrary .NET objects:

One alternative I considered, was to point only to IObject. But I want to have the feature of access directly to native .NET objects (or Java ones, if I change the implementation language).

The more important method in IObject is Send. Using this method, you can send a message (selector plus arguments) to any IObject instance.

IBehavior is my implementation of what Piumarta/Warth named a vtable. It is the object that containts the list of method that can attend the messages sent to an IObject.

Each IObject has a Behavior property that points to an IObject. I could had choose to point to an IBehavior, but in this way, the Behavior of an object can be replaced by any object that understand a #lookup: message selector.

I don’t need to implement the closure concept, as described in Piumarta/Warth papers. Using closures, they implemented slots a la Javascript or Selft. But I have no need to take that approach in my experiments, yet.

The main implementation classes are:

Each BaseObject implements IObject, having an internal array of objects:

public class BaseObject : IObject { private object[] values; public BaseObject() { } public BaseObject(int size) { this.values = new object[size]; } public int Size { get { if (this.values == null) { return 0; } return this.values.Length; } } public IObject Behavior { get; set; }

(Note that Behavior property is an IObject, as I explained above).

The more interesting method is Send:


public virtual object Send(string selector, params object[] arguments) { if (selector == null) { throw new ArgumentNullException("selector"); } if (this.Behavior == null) { throw new InvalidOperationException("No behavior in object"); } IMethod method = (IMethod) this.Behavior.Send("lookup:", selector); if (method == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown message '{0}'", selector)); } return method.Execute(this, arguments); }

I don’t use this.Behavior.Lookup to get the method associated with message selector. Instead, I’m using directly the Send method, so obj.Behavior can be mapped to any IObject that knows how to implement a method lookup. This feature has a performance impact, but it ables to implements new ways of dispatching a message. You can find in the cited papers, multiple inheritance and traits implemented using this extensibility.


In the code, you’ll see an additional project, called AjPepsi, where I’m implementing a parser and a byte code interpreter, of the language Piumarta/Warth used as a proof of concept in their papers. It accepts code like:

Object new [^self class basicNew initialize] Object initialize [] List : Object(head tail) List head [^head] List tail [^tail] List head: newHead [head := newHead] List tail: newTail [tail := newTail] list1 := [^List new] list2 := [^List new] [list1 head: 'Hello'] [list2 head: 'World'] [list1 tail: list2]

Object and List are prototypes, but I should pospone any detailed discussion to a future post. AjPepsi is still under development; probably, I’ll make major refactoring and implementation in the next week. I took AjTalk code as a base, but I don’t sure it was a clever decision: AjPepsi is strong prototype oriented, so I spent ten hours refactoring AjTalk to fit AjSoda ideas.

One big next feature: as in the current implementation of Pepsi/Id/Cola, I’m thinking in automatic generation of underlying language code (in this case, C# code), representing the state of a machine (classes, methods, instances).

Test are green:

Code coverage is fair:

There are some smell code to refactoring, yet. Classical example: a big switch with lot of code in byte code interpreter. But the majority of such smell is inside AjPepsi code. AjSoda is taking form, going to an stable version. It took only 4 hours of my time to write AjSoda current code, but I’m spending a lot of time writing a complete AjPepsi interpreter/parser/machine (10 hours until today).

As usual, I had a lot of fun writing all this code!

More links about Piumarta/Warth ideas:

Comments, suggestions, welcome.

Angel “Java” Lopez

4 thoughts on “Presenting AjSoda

  1. Pingback: Smalltalks 2011 - Tu conferencia sobre desarrollo de software - Angel "Java" Lopez

  2. Pingback: GrammGen en C# (1) Primeros Conceptos - Angel "Java" Lopez

  3. Pingback: GrammGen en C# (1) Primeros Conceptos | MVPs de LATAM

  4. Pingback: GrammGen in C# (1) First Concepts | Angel "Java" Lopez on Blog

Leave a Reply

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

You are commenting using your 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