TruffleSOM - The Simple Object Machine Smalltalk implemented using Oracle's Truffle Framework
SOM is a minimal Smalltalk dialect used to teach VM construction at the Hasso Plattner Institute. It was originally built at the University of Århus (Denmark) where it was used for teaching and as the foundation for Resilient Smalltalk.
In addition to TruffleSOM, other implementations exist for Java (SOM), C (CSOM), C++ (SOM++), and Squeak/Pharo Smalltalk (AweSOM).
A simple Hello World looks like:
Hello = ( run = ( 'Hello World!' println. ) )
Obtaining and Running TruffleSOM
To checkout the code:
git clone https://github.com/SOM-st/TruffleSOM.git
Then, TruffleSOM can be build with Ant:
Afterwards, the tests can be executed with:
./som -cp Smalltalk TestSuite/TestHarness.som
A simple Hello World program is executed with:
./som -cp Smalltalk Examples/Hello.som
When working on TruffleSOM, for instance in Eclipse, it is helpful to download the source files for Truffle as well:
Information on previous authors are included in the AUTHORS file. This code is distributed under the MIT License. Please see the LICENSE file for details.
TruffleSOM implements a file-based Smalltalk with most of the language features common to other Smalltalks. This includes support for objects, classes, methods, closures/blocks/lambdas, non-local returns, and typical reflective operations, e.g., method invocation or object field access.
The implementation of TruffleSOM is about 3500 lines of code in size and is a concise but comprehensive example for how to use the Truffle framework to implement standard language features.
Its parser creates a custom AST that is geared towards representing the executable semantics. Thus, we did not include AST nodes that have structural purpose only. Instead, we concentrated on the AST nodes that are relevant to express Smalltalk language semantics.
Currently TruffleSOM demonstrates for instance:
- method invocation: som.interpreter.nodes.MessageSendNode
- usage of Truffle frames
- argument passing som.interpreter.nodes.ArgumentInitializationNode
- associating AST tree nodes with source code, e.g., som.compiler.Parser.unaryMessage(..)
- support for lexical scoping and access from nested blocks, cf. ContextualNode subclasses and som.interpreter.ContextualNode.determineContext(..)
- usage of control-flow exception for
- non-local returns, cf. som.interpreter.nodes.ReturnNonLocalNode.executeGeneric(..) as well as som.interpreter.nodes.ReturnNonLocalNode.CatchNonLocalReturnNode.executeGeneric(..)
- looping: som.interpreter.nodes.specialized.AbstractWhileNode as well as som.interpreter.nodes.specialized.IntToDoMessageNode