Angel “Java” Lopez on Blog

September 23, 2009

Exploring objects

Filed under: Programming Languages, Smalltalk — ajlopez @ 9:38 am

I’m following @jarober (James A. Robertson) in Twitter, Cincom Smalltalk Product Evangelist. He post links about news and resources about Smalltalk, and Cincom Smalltalk in particular. He writes a blog:

http://www.cincomsmalltalk.com/blog/View.ssp

powered by Smalltalk. If you visit his blog, there are many entries about Smalltalk. Recently, Robertson posted:

Smalltalk Daily: Exploring Objects

There is the video:

Robertson wrote:

Many times, you want to do something, know that it can be done – but just aren’t sure how to construct the code to do it. If you have an object, you can usually solve that problem by drilling into it with the inspector and looking at it. Today we learn how to programmatically change workspace page text by drilling into a workspace.

It’s refreshing to see such interaction with objects, so “Smalltalk-way” of interaction.

I should work on my Smalltalk VM (interpreter) AjTalk, to have support of visual interaction. My idea is to wire the current VM with .NET framework, WinForms. In this way, I could leverage the built-in GUI support in the framework. In these day, every language should take advantage of a class framework: .NET and Java are the obvious choice (see Clojure as a “modern” example of this strategy)

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

January 25, 2009

Presenting AjSoda

Filed under: Smalltalk, Software Development — ajlopez @ 6:38 pm

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:

http://piumarta.com/pepsi/objmodel2.pdf
http://piumarta.com/pepsi/objmodel.pdf

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:

http://code.google.com/p/ajcodekatas/source/browse#svn/trunk/AjSoda

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.

AjPepsi

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:

http://lambda-the-ultimate.org/node/2483
http://piumarta.com/
http://piumarta.com/pepsi/pepsi.html
http://piumarta.com/software/cola/

Comments, suggestions, welcome.

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez

December 22, 2008

AjTalk: my Smalltalk-like interpreter project updated

Filed under: .NET, AjTalk, C Sharp, Smalltalk — ajlopez @ 7:30 am

I committed new code to my Google code project AjTalk:

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

The previous version was described in my post

AjTalk- a Smalltalk-like interpreter

It’s an interpreter written using C#. This post describes the work in progress in this solution:

There are interfaces and base classes to support objects and classes:

Every method is compiled to bytecodes. Block and Method are the classes that contains bytecodes programs:

Blocks are anonymous code block. A Method has name and belongs to a class.

The bytecodes are described in an enumeration:

using System; namespace AjTalk { public enum ByteCode : byte { Nop = 0, GetVariable = 1, SetVariable = 2, GetArgument = 3, SetArgument = 4, GetConstant = 5, GetLocal = 6, SetLocal = 7, GetClassVariable = 8, SetClassVariable = 9, GetGlobalVariable = 10, SetGlobalVariable = 11, GetBlock = 12, GetSelf = 20, GetClass = 21, GetSuperClass = 22, NewObject = 23, Pop = 24, ReturnSub = 25, ReturnPop = 26, Add = 40, Substract = 41, Multiply = 42, Divide = 43, Send = 50 } }

In this committed version, there is support to create and access .NET objects. You can write

@System.IO.FileInfo new: ‘aFile.txt’

to create a new .NET object (@ is used to mark a name with special chars like ‘.’).

In this version, I added support to load .st files. It’s not an standard .st file: I will use this files to define the initial class library. Now, there are used only in tests. An example:

nil subclass: #Figure instanceVariables: 'x y' !Figure methods! x ^x ! y ^y ! x: newX x := newX ! y: newY y := newY ! ! Figure subclass: #Rectangle instanceVariables: 'width height' !Rectangle methods! width ^width ! height ^height !

 I bootstrapped the system with a global nil variable. In the loader tests, the nil variable is bound to understand messages like subclass: and ifFalse:.

I changed the unit test to use VS test support. All in green:

The code coverage is good, 84.29%:

I added support to blocks in method, but there is no parameter support, yet:

nil ifFalse: [GlobalName := 'foo']

Next steps

The proposed roadmap is:

- Add more .NET object support

- Write the initial class in base library

- Implements Class, Metaclass, Behaviour “a la” Smalltalk-80

- Load initial library in console application

- Invoke AjTalk from .NET application

- Implements indexed variables

- Extends the bytecode set

As usual, I had fun written this code!

Angel “Java” Lopez
http://www.ajlopez.com/
http://twitter.com/ajlopez

September 15, 2008

Smalltalking meeting, with Claus Gittinger and Smalltalk/X

Filed under: Smalltalk — ajlopez @ 12:06 pm

On September 13rd, saturday morning, I assisted to Smalltalking group meeting. This time, the meeting was in a coffee store, near the National Library buildign, here, in Buenos Aires, Argentina. The  group is small but enthusiast, and the talkings were interesting.

The first one to arrive was Leonardo de Marco, that is changing his job to dedicate full time to Smalltalk development. Alejandro Reimondo, the “chief” of the group, was present. Other members that assisted were Esteban Lorenzano, Diego Coronel, Matías Castilla and Juan (no lastname, it’s only Juan… :-) .

Alejandro is a reference in the field of Smalltalk development, around the world. He is a chemist, that is working with Smalltalk since the eighties. He is the founder of Smalltalking group, dedicated to the difussion and discussion of software development in an virtual object environment.

Esteban Lorenzano is teaching project architecture in information technology, in Universidad Tecnológica Nacional, Buenos Aires. The page of the cathedra is:

http://apit.wikidot.com/

He is one of the founder of Smallworks, a new firm dedicated to software development using Smalltalk.

Diego Coronel has a company Informagine (I guess the URL is http://www.informagine.com ), that works with Smalltalk, here in Argentina, and actually, in México. He is living between the two countries.

Matías Castillas is a student. He cames from La Plata (70 km from Buenos Aires). We missed another member from La Plata, Elvio Fernandez, that this time could not assist to the meeting.

There were many discussions, about the sustainability of open source development, the situation of education of object and architecture concepts in Argentina, the scarcity of human resources, in Smalltalk and other technologies, the rotation of the developers in companies, and the high salaries of junior developers, since the global situation and exchange rate in Argentina.

Alejandro commented his travel to Postdam, where he assisted to

Workshop on Self-Sustaining Systems (S3) 2008

The Workshop on Self-sustaining Systems (S3) is a forum for discussion of topics relating to computer systems and languages that are able to bootstrap, implement, modify, and maintain themselves. One property of these systems is that their implementation is based on small but powerful abstractions; examples include (amongst others) Squeak/Smalltalk, COLA, Klein/Self, PyPy/Python, Rubinius/Ruby, and Lisp. Such systems are the engines of their own replacement, giving researchers and developers great power to experiment with, and explore future directions from within, their own small language kernels.

He was impressed by the work of Richard Gabriel, of IBM (personal web page of Gabriel here). You can see the work presented by Gabriel on Sustaining Self at:

http://www.tele-task.de/page50_lecture3625.html

But the star of the meeting, was Claus Gittinger, founder of Exept Software AG, and the creator of Smalltalk/X. If you read his LinkedIn full profile, you’ll find impressive works of Claus, since the eighties, in many companies in technologies. In 1995, he founded Exept Software, that:

provides solutions, advice and consulting services in the Telecom, Automation, Automobile and other technology oriented software areas.
Products include a state of the art OO-development framework and environment (www.smalltalk-x.de) and frameworks for Test- and Qualitymanagement (www.expecco.de)

Claus skills includes

Architecture, Project Management, Team Building and Leading, Coaching, Teaching, Testing, Test Management, Prototyping,
Programming Language Implementation, VM design & Implementation, Compiler Construction, IDE Design & Implementation, GUI Framework Design & Implementation, OS-Kernel, OO, Smalltalk, ESUG

He is visiting my country, accompained by Félix Madrid, an argentinian developer that works for Exept in Germany. It’s Claus’ first visit to Argentina, so I hope he enjoy the trip.

Smalltalk/X

Claus was a kindly man, that gaves us a complete demo of his product, Smalltalk/X:

Smalltalk/X, a product from eXept Software AG, is a complete implementation of the programming language, class library and development environment, providing:

  • An object-oriented programming language
  • Graphic development environment with editors, browsers, debuggers, GUI builders, etc.
  • Incremental compilation, byte code interpreter and dynamic (just in time) compiler
  • Static compilation and DLL generation, controlled by make-files
  • Comprehensive class library with ready-to-use modules for applications
  • Open Smalltalk source code

Implementation of the language and class library complies with the draft ANSI standard and the industry standard.

Claus showed us the compilation of .st files directly to C language, in many platforms (in Windows, you can compile the full system with Borland C or with Microsoft Visual C++). In this way, you can produce native executables from your Smalltalk project. The features from the documentation:

ST/X Smalltalk is a complete implementation of the Smalltalk language. Smalltalk/X is not based on the original ST-80 virtual machine implementation and has been written from scratch. However, the API, class libraries and language semantic is highly compatible to ST-80 based smalltalks, such as VisualWorks, Squeak and others.

Smalltalk/X consists of both an integrated environment for program development AND a standalone smalltalk compiler(1), which generates true machine code, shared code libraries and binary executables without a need for a so called “image”. However, traditional image-based development is also supported and typically used for program development.

The programming environment includes editors, browsers, compiler and debugger and a large library of ready to use building blocks for application writers.
The standalone compiler generates true machine code from smalltalk source files – and can be used in a batch environment for production/delivery.

Features

  • Language syntax and semantic compatible to the industry standard, including arbitrary precision arithmetic and automatic number conversion, exception handling, automatic memory management, threads, contexts, blocks (block closures), metaprogramming and much more.
  • Additional (mostly backward compatible) extensions to the smalltalk language include: private classes, multiple namespaces, method privacy and end of line comments.
  • A comprehensive threadsafe library of basic classes, including collection classes, numeric classes, streams, lightweight processes, exception handling and metaclass hierachy.
  • Many user interface widget classes usable as building blocks for graphical applications. These are fully (non-polling) event driven, multithreaded and support multiple displays, parametrized view styles, wide characters (unicode) and national languages.
  • Integrated programming environment including browsers with sophisticated refactoring and code generation support, GUI- and Menu builders, monitors and symbolic debugger for efficient program development.
  • The additional Scripting Engine allows for command-line execution of smalltalk scripts. These script files can be generated by any other editor, or alternatively by saving code from the IDE (file-out from the browser).
  • Debug once – run everywhere !
    complete Source- and Byte-Code compatibility between Unix and Windows versions. Write your application once, run it without change on Win-NT, Linux, Alpha-OSF, Sun-solaris, HPUX, AIX, Silicon-Graphics IRIX(4).
  • Many demo and ‘how-to’ example programs
  • Online HTML documentation and class documentation generator, visualized by the ST/X HTML document viewer.
    Well documented classes and methods.
  • Very liberal licensing conditions

Implementation hilights

  • Incremental compilation to internal bytecodes for short turn around cycles during development.
    Binary files containing bytecode are portable across different machine architectures.
  • Dynamic (just-in-time) compilation from internal bytecodes to machine code (2).
    Except for the faster execution, this is transparent to the program or user.
  • Batch compilation to real machine code for high performance production code, enabling the creation of binary object modules, class libraries or even shared class libraries.
    Since more optimizations and code analysis are performed by this (offline) compiler, the resulting code executes faster – even when compared to dynamic compiled machine code.

    Although static compiled machine code leads to bigger executables, the main advantage (beside faster execution) is the deterministic runtime behavior, which cannot always be guaranteed, if bytecodes are compiled dynamically at execution time.
    In addition, big applications benefit from static compilation by the sharability of this compiled code among multiple applications, if shared libraries and/or shared text segments are supported by the operating system.

    Applications can (and do) use a mix of precompiled machine code classes and interpreted bytecode classes – this is transparent to the program or programmer.

    If supported by the operating system (3), machine compiled modules can be dynamically added to and removed from the running system.

  • Easy creation of standalone executables and applications without graphical user interfaces. This includes self-extracting installation code for windows platforms (null-soft self installing executables).
  • Easy binding to C-language by allowing inline c code (even inline assembler by using asm statements) or via the ffi-callout mechanism to dynamically loaded shared libraries (dll’s).
  • Sophisticated window interface combining event and process driven techniques.
    ST/X supports multiple display devices – you can work with others in the same object environment, or write applications which serve multiple screens.
    Your application can even run on a display-less host, serving multiple xTerminals or client applications via TCP connections.
  • Additional protocol provided in the process, semaphore and processor classes, for better thread synchronization. ST/X’s process handling includes additional mechanisms for recovery (semaphore cleanup) in exceptional situations, which is required in technical applications. The ST/X’s process scheduler supports timeSlicing and dynamic thread priorities. This allows for better response behavior in multiwindow applications and allows progress of background processes even in case of busy foreground processing.
  • Modern generational garbage collector, with dynamic adjustable newSpace, adaptive tenuring, both incremental and non-incremental collectors for the oldSpace, both copying and non-copying compressors for the oldSpace.
  • Object finalization via the WeakArray mechanism; in addition, a number of other collection classes are available with weak references (WeakSet, WeakDictionary etc.)
  • Both ANSI compliant class based exceptions and (VW-) backward compatible Signal-based exceptions are supported.
    In addition, process specific and global default exception handlers are avaliable, to allow for non scoped, global exception handling.
  • The byteCode interpreter and just-in-time compilers support multiple bytecode sets, for total integration of different languages into a single unified system.
    In the current release, this feature is used to support execution of compiled Java code.

Claus showed the command line compilation of .st files to .c, and the on the fly compilation of byte codes in native code during development. His implementation has departures from the classic Smalltalk, the product is not a direct reimplementation of the classic VM in other Smalltalks. For example, the context calls are in the C stack, and if you add a new variable in a class, the previously created instances are not affected, and become instances of the old class definition. become: implementation is tricky. The VM does not uses an object table. The garbage collector is a mark-and-sweep variant.

You can download the binaries of the system, or you can access and check out the company CVS (be prepared to a big download: more than 20000 files, >180 megas).

We asked Claus many details about the VM implementation (I was the more curious in the group: I’m very interested in VM implementation, since my AjTalk work in progress). One interesting thing, is that in the .st files, we can include C language fragments. For example, in Object.st file the basicAt: implementation has C language code included:

basicAt:index "return the indexed instance variable with index, anInteger..." ... %{ /* NOCONTEXT */ REGISTER int nbytes, indx; OBJ myClass; REGISTER char *pFirst; REGISTER int n; ... if (__isSmallInteger(index)) { myClass = __qClass(self); indx = __intVal(index) - 1; n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); nbytes = __qSize(self) - n /* nInstBytes */; pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; ... }%

Claus showed the GUI environment, with workspaces, browsers, implemented directly in Smalltalk. You can design GUI forms. And the product includes an HTTP server, so you can create web pages with Smalltalk. This part of the demo would deserve more space in this post, but you can check the product page for more info.

If you are interested in Smalltalk, you must visit the links page and documentation (with free books on Smalltalk).

Thanks to Claus Gittinger, for sharing his time and knowledge, with our group. It was a very interesing meeting.

Angel “Java” Lopez
http://www.ajlopez.com/en

August 17, 2008

New Smalltalk Site: ClubSmalltalk.org

Filed under: Programming Languages, Smalltalk, Software Development — ajlopez @ 2:37 pm

These days, this new site dedicated to Smalltalk was launched:

http://www.clubsmalltalk.org/

According to the site:

ClubSmalltalk.org is a non-profit organization which congregates Smalltalk programmers and enthusiastics. In 2008, we are going a step forward with this new website.
The big idea behind this website is to provide a source of information about Smalltalk in general.
The Smalltalk community has not good sources of information, or they’re all over the net, and sometimes it’s difficult to find them.

If you want to contribute, you’re welcome!

It’s an spinoff of the activity of the Spanish mailing list:

http://groups.google.com/group/clubSmalltalk

Some of the most popular articles published:

Interview with Luca Bruno, the creator of Smalltalk YX

Argentinian Smalltalk Congress- Smalltalks 2008

Seaside and Ruby on rails

It has sections:

FAQs:

Smalltalk Frequently Asked Questions

GemStone Frequently Asked Questions

Environments:

Commercial Smalltalk Environments

Free Smalltalk Environments

Abbandon Smalltalk Environments

Frameworks, Platforms & Tools

and more: Tools, Resources, Community. It has links to Smalltalk Books, like:

Free Books 

Thanks to the work of Stéphane Ducasse, we have a huge collection of Free Smalltalk books online.
Download from http://www.iam.unibe.ch/~ducasse/FreeBooks.html

Creative Common Books

Our friend Diego Gomez Deck has written an excellent book in Spanish to start in Smalltalk. You can buy a hardcopy or you can download it under the creative common licence from http://smalltalk.consultar.com/.
If you like it, we recommend to buy it, we are proud of this kind of projects.

The site is in its infancy, but I hope that with the help of the Smalltalk community, it will grow and become a reference to anyone interested in ST.

It’s supported by PHP. In my opinion, it’s a good sign: for years, Smalltalk community was reluctant to integrate or use other tools or technologies. In these days, with the plethora of languages, frameworks and platforms, we must abandon such isolated trend, and be more integrated.

Angel “Java” Lopez
http://www.ajlopez.com/

August 14, 2008

Smalltalk 2008 in Argentina, Call for Papers

Filed under: Smalltalk, Software Development — ajlopez @ 9:39 am

Last year was the first installment of this argentinian Smalltalk conference. Now, a group is preparing the 2008 version. This is the site (Seaside based) and annoucement:

Smalltalks 2008 – 2nd Argentinian Smalltalk Conference

 

This year’s conference will take place on the 13th, 14th and 15th of November on the Universidad Abierta Interamericana, Av. Montes de Oca 745, Buenos Aires, Argentina. Like the 2007 conference, the registration will be free of charge.

This year we are willing to offer new activities. For this reason we open the calls for:

Talks
The conference will have two tracks, one on Scientific Research and other on Software Development for Industries.
Programming Contest
This year we will host a programming contest, encompassing all Smalltalks dialects.
Keynotes
Guest lectures by outstanding personalities.
Hands on
Tutorial sessions.

There is a call for papers (PDF version), about topics:

 

  • Aspects, Aspect Languages and Applications.
  • Ambient Intelligence, Ubiquitous / Pervasive Computing and Embedded Systems.
  • Compilation Technology, Optimization, Virtual Machines.
  • Educational Material.
  • Language Engineering, Extensions.
  • Model Driven Engineering / Development.
  • Meta-Modeling.
  • Programming in the Large, Design, Architectures and Components.
  • Programming Environments, Browsers, User Interfaces, UI Frameworks.
  • Reasoning About Code (Analyses, Refactoring, Type Inference, Metrics).
  • Reflection and Meta-programming.
  • Team management.
  • Testing, Extreme Programming / Practices.
  • Web Services, Internet Applications, Event-driven Programming.
  • Experience Reports.

Interesting, this year they are extending the scope of the research and educational track to include other dynamic languages, not only Smalltalk. They have an impressive Program Committee:

  • Federico Balaguer (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Tulio Ballari (UTN, Buenos Aires, Argentina)
  • Alexandre Bergel (INRIA, Lille, France)
  • Gilad Bracha (Cadence Design Systems, USA)
  • Johan Brichau (Université Catholique de Louvain, Belgium)
  • Cecilia Challiol (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Marcus Denker (SCG, University of Bern, Switzerland)
  • Fernando Dodino (UTN, Buenos Aires, Argentina)
  • Stéphane Ducasse (INRIA, Lille, France)
  • Alejandra Garrido (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Tudor Girba (SCG, University of Bern, Switzerland)
  • Orla Greevy (SCG, University of Bern, Switzerland)
  • Julián Grigera (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Andy Kellens (PROG, Vrije Universiteit Brussels, Belgium)
  • Kim Mens (Université Catholique de Louvain, Belgium)
  • Guillermo Adrián Molina (ESSI Projects, Spain)
  • Damien Pollet (INRIA, Lille, France)
  • David Röthlisberger (SCG, University of Bern, Switzerland)
  • Daniel Solmirano (UTN, Buenos Aires, Argentina)
  • Tom Van Cutsem (PROG, Vrije Universeit Brussels, Belgium)
  • Roel Wuyts (IMEC, Belgium)

Smalltalk is a technology that, in my opinion, failed to crossing the chasm. At late 80s, early 90s, the community was divided in many diverging dialects and commercial implementations. But it has impetus and loyalty members, as was proved last year, here, in Argentina, with the success of the last year conference. I hope Smalltalk could integrate with other technologies, like .NET and Java, in order to gain more momentum and acceptance. See, as an example, F# adoption in scientific community: the access to a popular class framework is a key feature in today mainstream. Insisting in one world, one language attitude is not an option, nowadays. I celebrate, then, the open of the above call for papers to other dynamic languages.

Angel “Java” Lopez
http://www.ajlopez.com/en

July 14, 2008

AjTalk: a Smalltalk-like interpreter

Filed under: .NET, AjTalk, C Sharp, Smalltalk, Software Development — ajlopez @ 8:52 am

Weeks ago, I was working on my open source project AjTalk, an Smalltalk-like interpreter, written in .NET (using C#), and now, I want to present the status of that work. For years, I was interested in Smalltalk development, altought only in my free time, never as a professional developer. It’s not the first time I wrote such kind of interpreter (my first one was written in the eighties, and it was very simple: no garbage collector, only text commands), but this time I feel it could become a very complete implementation.

Current version is minimal, but it is taken form. The idea is to have dynamic objects, like in Smalltalk, and, at some point, add prototypes a la Self. The objects and the interpreter would access full .NET framework and other libraries, as I did in my AjBasic interpreter (included as part of AjGenesis code generation project).

The very initial version is now published at Google Code:

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

The solution

I’m using Professional VS 2005. There are four projects in the solution.

AjTalk is the main project, a class library containing the core of the system.

AjTalk.Test01 and AjTalk.Test02 are console applications, only for manual tests.

AjTalk.Tests contains the unit tests, written using NUnit framework 2.2.8.

Most of the core system consists of interfaces, defining the base behaviors, and classes, implementing such interfaces.

The object

The base is to have an interface to represent any object:

using System; namespace AjTalk { public interface IObject { IClass Class { get; } object this[int n] { get; set;} object SendMessage(string msgname, object [] args); } }

I could make a message an object (of type Message), but for now, the message is only a name, and an array of arguments.

The index this[int n] access the intance variables. Each value in AjTalk can point to any .NET object, not only the ones that implements IObject. In this way, I can manage int, long, String, DataSet, from other IObject objects.

The class

I’m implementing a simple IClass interface, without distinguing between class, behaviours, and other classes, as in the classic Smalltalk. I’ll separate these classes in a future version. For now, I’m managing only a interface:

using System; using System.Collections; using System.Collections.Generic; namespace AjTalk { public interface IClass : IObject { IClass SuperClass { get; } string Name { get; } void DefineClassMethod(IMethod method); void DefineInstanceMethod(IMethod method); void DefineClassVariable(string varname); void DefineInstanceVariable(string varname); IObject NewObject(); IMethod GetClassMethod(string mthname); IMethod GetInstanceMethod(string mthname); int GetClassVariableOffset(string varname); int GetInstanceVariableOffset(string varname); } }

There is a dictionary of class and instance methods, and lists of class and instance variable names. It doesn’t have support for indexed variables, yet. IClass interface is now implemented in a BaseClass class.

The method

There is an interface implemented in Method class:

using System; namespace AjTalk { public interface IMethod { string Name { get; } IClass Class { get; } object Execute(IObject receiver, object [] args); } }

The concrete Method class, has an Execute method:

public object Execute(IObject receiver, object[] args) { return (new ExecutionBlock(receiver,receiver,this,args)).Execute(); }

Execution blocks have local variables and arguments. The Execute of an execution block takes the instructions (bytecodes) from “compiled” methods, and then it executes them. Here, I took a departure from Smalltalk ideas: the execution block is not an AjTalk object. In this way, I could run this interpreter without implementing a lot of base classes. I have to research the advantages and problems that this decision could have in the overall design and implementation.

The bytecodes

I must think about using a tree of objects (as in Interpreter pattern) instead of bytecodes. But in this version, bytecodes are used. These are the basic instruction that my “virtual machine” understands and executes step by step.

There is a bytecode list (an enumeration)

namespace AjTalk { public enum ByteCode : byte { Nop = 0, GetVariable = 1, SetVariable = 2, GetArgument = 3, SetArgument = 4, GetConstant = 5, GetLocal = 6, SetLocal = 7, GetClassVariable = 8, SetClassVariable = 9, GetSelf = 20, GetClass = 21, GetSuperClass = 22, NewObject = 23, Pop = 24, ReturnSub = 25, ReturnPop = 26, Add = 40, Substract = 41, Multiply = 42, Divide = 43, Send = 50 } }

The bytecodes contained in a method, are interpreted and executed by the execution block. An excerpt of that code:

while (ip < method.ByteCodes.Length) { ByteCode bc = (ByteCode) method.ByteCodes[ip]; Byte arg; switch (bc) { case ByteCode.ReturnSub: return null; case ByteCode.ReturnPop: return Top; case ByteCode.GetConstant: ip++; arg = method.ByteCodes[ip]; Push(method.GetConstant(arg)); break; case ByteCode.GetArgument: ip++; arg = method.ByteCodes[ip]; Push(arguments[arg]); break; ….

Test everywhere

The initial code was written in VB.NET. Last year I began to rewrote the original source code to C#. Then, this year I switched to “TDD mind”, so, late but sure, I added NUnit tests:

Bootstraping

I plan to use a text file, with an ad-hoc format, to inject the definitions of the initial classes and objects. Now, in the AjTest.Test02, there is an example of such format in Definitions.txt file:

class Point
variables x y

method
x ^x.

method
y ^y.

class Rectangle
variables point1 point2
class Square Rectangle

Next steps

There is a lot of work to do:

- Complete the hierarchy of base classes (Behaviour, Class, ….)

- More byte codes

- Support of local variables in methods

- Standard file text format

- Access to native .NET objects

- Use from .NET applications

- Define the classes and methods for a minimal implementation

- Serialization/deserialization of memory image

- Support for adding variables to a class with created instances (this is a tough problem)

- Support for become:

- And much more….

But I’m confident on the shape the project is taken. I’m applying “baby steps”, to improve the base code and functionality.

Angel “Java” Lopez
http://www.ajlopez.com/en

June 27, 2008

The early history of Smalltalk

Filed under: Programming Languages, Smalltalk, Software Development — ajlopez @ 5:42 pm

Today I wanted to comment a text, in my opinion, a “must be read” by all those of us dedicated to software development. It is a writing of Alan Kay, about the early history of Smalltalk:

Smallhistory.pdf

It is an excellent text to read, and that has influences simply beyond Smalltalk. It is a history of how some ideas were arising, within the American community of software development. How the programming with objects was arising, and how the form to interact with the present computers was taking form.

Read, for example, how Kay detects  some germinal ideas (data along with behaviour) in developments of the Air Force, that today we would see very remote of the OOP. Read on his contact with Lisp, and Seymour Papert. Read on the internal problems of Xerox, the competition with DEC, how some ideas were almost generated by chance. Read on Simula, Euler, IPL predecessor of Lisp. Read on the Sketchpad of Sutherland (who I found by first time in some historical revision of the Scientific American). It is a delicious and enlighten reading, at least for me.

Kay has been having an idea for years, that I share: the idea that the machine, and computing in general, must serve to us to expand our human capacities. Excellent idea. It is what of some form also today we are reaching using Internet. Today, branches of the knowledge and human actions, have been leveraged by software, the hardware and everything what it has happened in our profession in the last decades.

Years ago, people guessed that the space trips were going to revolutionize human history. That has still not happened. But of some form subproduct of the cold war and the space race, the development of the computing science (we remember its modern beginnings in the second war, and the appearance of the cybernetics impelled by military subjects) and of Internet, is what it has caused a change, that is reaching to great part of the humanity.

To read the history of Kay is indispensable to be understanding what it has happened. Somebody that has said ” the best form to dominate the future, is inventing it” (approximated phrase, reads the text, to see where it arose exactly).

Angel ” Java” Lopez
http://www.ajlopez.com/en

June 18, 2007

Installing Squeak

Filed under: Programming, Smalltalk — ajlopez @ 12:06 pm

In the last century, sometimes I was studying Squeak. Now, in these days I have returned to visit it, and wanted to write a simple, introductory article, on its easy installation.

Squeak is an open source implementation of Smalltalk, that has been developed for years. The internal implementation of its virtual machine is interesting, to a great extent written in Smalltalk, with tools to produce its own virtual machine.

Like in other implementations, one needs to install the virtual machine of the operating system that will use. In this article, we will install a version (the 3,9) for Windows. Also we will need an image, a file with the state of the active instances. Smalltalk has been characterized from always, by being able to write and to raise an image, a species of “snapshot” of the state of the system.

The page of Squeak is

http://www.squeak.org

For somebody not warned of the existence of virtual machines and images, it is a little confused explanation of its installation:

http://www.squeak.org/Download/

because there are several options. For example, to lower the versions from

http://ftp.squeak.org

But there is multitude of archives. The one that we are going to use is a file .zip that contains the virtual machine for Windows and image 3,9 (at the moment already there is a developing image 3,10), directly from:

http://ftp.squeak.org/3.9/win/Squeak3.9-win32.zip

This file contains:

We see a Squeak.exe, that it is the feasible virtual machine. The SqueakV39.sources file is of text, of more than 4 megas of size. It contains the source code of the classes that compose this version. The file Squeak3.9-end-7067.image is the image, “snapshot” that contains the instances of this system.

We can expand the content of this .zip in a directory, and make double click on the feasible one of the virtual machine Squeak.exe. Automatically it detects the image. Alternatively, we could drag from the Explorer de Windows the file image on the file .exe. It appears our first welcome to the Squeak world:

All within this window, is created by the own Squeak. Following the tradition of the original Smalltalk, the graphical aspect, the controls, windows, and others “widgets” are drawn by the own system. The appearance of this window and its contents, then, is independent of the operating system.

In the right lapel titled tools, we found a series of tools. Raising the classic one “to browser” of Smalltalk, we found:

The four superior lists, show, in sequence:

  • categories of classes
  • classes of the selected category
  • categories of methods (of instance or class)
  • methods
  • In the screen capture it appears the classic Object, of Kernel-Objects.

    If you have interest on the virtual machine, can visit

    http://www.squeakvm.org

    He is interesting to see the instructions to produce a virtual machine, in Win32:

    http://www.squeakvm.org/win32/compiling.html

    Well, for today, enough. I hope that it serves to you, as an start in the use of this implementation of Smalltalk.

    Angel “Java” Lopez
    http://www.ajlopez.com/en

    March 20, 2007

    Smalltalk Archeology

    Filed under: Programming Languages, Smalltalk, Software Development — ajlopez @ 9:24 am

    Aaron Reichow posted a message to Squeak development mailing list. He published a page with old versions of Smalltalk. You can download these oldies, too:

    http://bitquabit.com/rev/old/
    http://bitquabit.com/rev/old/download

     Look and feel of Digitalk Methods 1.1 (old good times… :-):

     

    I remember such windows, popularized via Borland products…. I want my Sidekick!!… :-)

    The original message:

    > Hey Squeakers!
    >
    > I and others have discussed old versions of Smalltalk a few times on  the
    > list in recent months.  Something I mentioned was putting up a  page with
    > screenshots of various old versions of Smalltalk.  I  recently got a few
    > of these old Smalltalks running and tonight I put  together a simple page
    > with a few screenshots and some basic info.
    >
    > Check it out at:
    > http://bitquabit.com/rev/old/
    >
    > Right now I’ve got some info and screenshots up for: Apple  Smalltalk-80
    > for Mac OS Classic, Digitalk Methods 1.1 (text-mode) for  DOS, and
    > Digitalk Smalltalk/V 286 R3 (graphical) for DOS.
    >
    > Thanks to all those who made this thing we love: Smalltalk! And  thanks to
    > those who have helped me out with this lil project.
    >
    > Regards,
    > Aaron
    >

    Blog at WordPress.com.