TruffleSOM: A Smalltalk implemented with Truffle

Stefan Marr java at
Fri Jun 28 06:23:31 PDT 2013


In order to get to know the Truffle framework better, I ported SOM, a little
Smalltalk bytecode interpreter written in Java, to Truffle.

The result is a first basic version that does not yet use any of the advanced
features of Truffle, but is fully functional and executes tests and benchmarks:

When I was implementing it, I was wondering whether you might be interested in
TruffleSOM as a show case for how to use Truffle. Digging through the
implementation of SimpleLanguage and the test cases did give me only minimal
guidance. The set of language features covered is just too minimal. Relevant
features such as calling methods, proper calling conventions, supporting
lexical scopes, proper usage of control-flow exceptions and so on are either
not covered or only in the simplest variation. So, to get a better idea of how
to use Truffle, I actually looked at FastR, but I had the feeling that using
Truffle was only an afterthought and thus, I am not sure whether it is used
'idiomatically'. Furthermore, the R semantics make it rather hard to see the
key elements.

However, if that would be interesting, I could use some feedback on the way
Truffle is used. One example that should probably be changed is the way I
implement lexical scopes for variable access and non-local returns. I suppose I
should use materialized frames for that because a block/closure is holding on
to its frame. And there are other things that could be done better, for
instance, I am not yet supporting blocks/closures escaping from their
activation scope, i.e., blocks that get returned as values from the method
where they are defined.

I would also like to use the chance to report a little problem, I had with the
way the type system works. I haven't really used it yet, but I had trouble with
the som.vmobjects.Object class clashing with java.lang.Object. That lead me to
add a hack to the codegen to use fully qualified names for all classes with the
simple name Object. I am sure there are more general solutions to the problem,
but I wanted to avoid having to rename the Object class. The current patch I
use is available here:

Another little nit is this patch:

I messed up the mx/env file when getting started, and found the resulting
Python stack trace rather unpleasant.

However, while I encountered a few stumbling blocks being not familiar with
Truffle, overall I had the feeling that it is rather pleasant to use. For
specific questions, the javadocs and test cases typically already provide hints
how to solve problems or how to use the API correctly. So, thanks for the nice
framework :)

Best regards

Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
Phone: +32 2 629 2974
Fax:   +32 2 629 3525

More information about the graal-dev mailing list