AjTalk in C# (1): A minimal Hello, World image

Next Post

If you read this blog (and have the patience to follow me at Twitter ;-), you already know I was busy working on my AjTalk Smalltalk-like VM written in C#:

https://github.com/ajlopez/AjTalk

There is a small Hello, World:

nil subclass:#Object
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Objects'
!

Object subclass:#Program
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Objects'
!

!Program class methods!

main @System.Console writeLine: 'Hello, world'! !

At repo:

https://github.com/ajlopez/AjTalk/blob/master/Src/AjTalk.Console/Programs/HelloWorld.st

It coud be smaller, but the Program main is the entry point of a saved image. The console program can generate an image using

ajtalk Programas/HelloWorld.st –s hello.im

and then, launch the image with

ajtalk hello.im

In this case, AjTalk looks for a global Program with a method main, and if it exists, it will be invoked.

The @ notation for @System.Console is the way to refer to a native .NET type.

Note that I don’t load all the class library, only the classes that I need for run the image. AjTalk can manage many Smalltalk machines in memory, each one with its own classes and methods. I have implemented a way of manipulating one machine from another, so you don’t need, in principle, to have a complete environment in machine A. So, I can produce minimal image, if I remove the classes and methods I don’t use. Instead of having a big image in memory, and cut the fat, my running machines born light by design. This is an example of “thinking out of the box”: for decades, Smalltalk developers thought on having only one image, and were struggling on how to make it an smaller one. My approach is totally different: make the VM so it can manage many machine/images in memory, so one can be manipulated from another one.

I should write more about the current implementation and features (and issues to solve), like: remote objects, object methods, processes, semaphores, multithreading, native access, save/load images, internal AST, visitors, code generation for JavaScript, bytecodes in compiled blocks, modules (loosly inspired in Python import,  and Node.js require), environments (to avoid class name collision), and more.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez