[Cuis-dev] transpiring Smalltalk to another programming language

Javier Pimás elpochodelagente at gmail.com
Wed Sep 11 21:08:58 PDT 2024


Hi folks, I needed some time to reply to this one. My 2 cents here:

There are quite a few projects related to transpilation of Smalltalk to
other langs. The slang in the open-smalltalk VM is one of them (remember,
the VM is written in Smalltalk, then converted to C). There are a few
projects that convert st 2 js, which seems easier than to C: js is
dynamically typed, with no type annotations in code and a very similar
semantics for its classes and dispatch compared to st. It's also GC'd which
reduces conversion impedance too. Things not possible in js: looking at the
execution stack, dnus and exceptions, some of these can be emulated in
ugly/not-highly-efficient ways.

There a couple of sides in transpilation to take care of: your code can
possibly be transpiled in a straightforward way (i.e. each of your classes
and methods generate an equivalent in the target language), the question is
what to do with standard libraries.


Imagine your code does x := OrderedCollection new. x add: self. What should
be created for x in js? Usually you don't want to transpile
OrderedCollection. The most similar thing in js is Array but you cannot
send add to js arrays and expect same semantics as st OrderedCollection. If
your target was C++, maybe you want to transpile to std::vector, but of
what kind of elements?


So what is needed to transpile a code corpus is a framework that can "look"
at the source code and make some smart decisions, maybe by inferring types
first and then applying some manually written rules depending on those
types (i.e. to declare inst vars of sensible types in target lang, to
convert ordered collections to std::vector for c++, to change add: messages
for push_back, etc). The lack of GC in C++ makes it harder, there's a
language called crystal, very similar to ruby but much faster, around C,
which has GC and almost no type annotations, I wonder how much it would fly
transpiling to it.


So the process has its complexity. The starting point are the st classes
and methods, from which AST can certainly be obtained in cuis (not sure how
to do it though). The target lang will shape what you do after you have the
AST.


Best regards!

Pocho

El mar, 27 de ago de 2024, 19:34, Boris Shingarov via Cuis-dev <
cuis-dev at lists.cuis.st> escribió:

> The guy you want to talk to about transpiling Smalltalk is @pocho on the
> slack, he has done a bunch of peer-reviewed work on the subject.
> None of that is Cuis-specific, though.
>
> On Mon, Aug 26, 2024 at 04:51:29PM -0500, Mark Volkmann via Cuis-dev wrote:
> > Is anyone aware of efforts to write a Smalltalk program that runs in Cuis
> > and generates code in some other programming language from Smalltalk
> code?
> >
> > Is there an easy way in Cuis to access an AST generated from Smalltalk
> code?
> >
> > --
> > R. Mark Volkmann
> > Object Computing, Inc.
>
> > --
> > Cuis-dev mailing list
> > Cuis-dev at lists.cuis.st
> > https://lists.cuis.st/mailman/listinfo/cuis-dev
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240912/057a703b/attachment.htm>


More information about the Cuis-dev mailing list