Transpiling Slang Methods to C Functions: An Example of Static Polymorphism for Smalltalk VM Objects (Video, VMIL 2023)
Tom Braun, Marcel Taeumel, Eliot Miranda, and Robert Hirschfeld
(Hasso Plattner Institute, Germany / University of Potsdam, Germany; Hasso Plattner Institute, Germany / University of Potsdam, Germany; Hasso Plattner Institute, Germany / University of Potsdam, Germany; Hasso Plattner Institute, Germany / University of Potsdam, Germany)

Abstract: The OpenSmalltalk-VM is written in a subset of Smalltalk
which gets transpiled to C. Developing the VM in Smalltalk
allows to use the Smalltalk developer tooling and brings
a fast feedback cycle. However, transpiling to C requires
mapping Smalltalk constructs, i.e., object-oriented concepts,
to C, which sometimes requires developers to use a different
design than they would use when developing purely in
Smalltalk.
We describe a pragmatic extension for static polymorphism
in Slang, our experience using it as well as the shortcomings
of the new approach. While our solution extends the
concepts developers can express in Slang, which reduces the
burden of finding alternatives to well-known design patterns
and by enabling the use of such patterns the modularity, it
further complicates a fragile, already complicated system.
While our extension solves the task it was designed for, it
needs further enhancements, as does Slang itself in terms
of understandability in the field.

Article: https://doi.org/10.1145/3623507.3623548

ORCID: https://orcid.org/0009-0000-3853-4882, https://orcid.org/0000-0002-7559-6035, https://orcid.org/0009-0004-5604-1116, https://orcid.org/0000-0002-4249-6003

Video Tags: object-orientation, modularity, polymorphism, virtual-machine development, tooling, Smalltalk, code generation, splashws23vmilmain-p11-p, doi:10.1145/3623507.3623548, orcid:0009-0000-3853-4882, orcid:0000-0002-7559-6035, orcid:0009-0004-5604-1116, orcid:0000-0002-4249-6003

Presentation at the VMIL 2023 conference, October 23, 2023, https://2023.splashcon.org/home/vmil-2023
Sponsored by ACM SIGPLAN, ACM SIGAda,

Presentation transpiring slang methods to C functions um let’s start with the challenge uh the challenge was mapping a source language in our case slang which is a subset of small talk to another language with different language capabilities which uh C in our case and the Big Challenge is that SL supports

Polymorphism and C does not and our goals were extending the use of polymorphism to static polymorphism so a polymorphism that is determined at compile time no Dynamic dispatching at one time and we didn’t want to do a big re of translation tool because this is just a subpart of implementing a new

Garbage collector so it wasn’t the main challenge um and oh yes uh what what is our context our context is here open smm uh which is a VM for SM slen and uh now the room is uh unmuted I can hear you um and advantage of of uh writing

The and slang sub of smart talk is you can execute the smallart talk so you can use the powerful SM ping the debugging the uh type feedback loop that’s really nice and so the workflow is developing Z as long as possible in small talk until it’s to slow sorry can you hear us

Yes I can he sorry oh finally so we had some technical problem in the room so what happened is that you were not hear us and at the beginning when you were presenting the audience could not see your slides so I’m so sorry about that

Um do you mind if we start over because this time everybody can see your slides and so we can and also I can properly introduce you I’m sorry about that oh okay um uh well do it and say when I should start so so um yeah so I’m so

Sorry for the technical issues so we are now it’s now time for the final Talk of the session talk will be given by Tom Brown um and the talk is is titled transpiling slang methods to C functions an example of static polymorphism for small talk VM objects this is also um a

Work in progress paper so Tom when you like please go ahead okay again welcome to my talk um as I said the challenge is mapping a subset of small talk slang to C and we want um to have some uh reduced set of polymorphism static polymorphism which

Is polymorphism you um have at compile time no Dynamic dispatches and we don’t want a big reite of the translation tool and uh the whole thing is done in Open Water frame which is uh implemented in slang so you can execute it you can debug it in small talk which is quite

Nice and so you want to stay as long as possible there and afterwards you compile it um here’s an example of a slang function uh it’s it’s just an example so don’t let’s be here too long you have Pras that are method annotations where you say something like the C return type

Should be that and that you could say please in line the function for me and such stuff and there are you write normal SM code sometimes you have uh such things uh you want to say I don’t want to do anything and see or I just

Want to do something and see and small talk don’t do it so we have uh capabilities for that too and um what I did in the past was writing a second garbage collector and uh I did this in the simulator as I said it’s quite nice to work there and as

State there I’m more of a high level programmer um more a small programmer so I use the strategy pattern and that’s quite nice if you just work in the garbage collector uh just work in the simulator um but in the end I needed both both garbage collectors in the Wim

And that’s uh nothing that’s supported by um that’s interesting uh uh by by slang until then so we needed uh some extension of the sling translation oh it’s quite interesting at the moment um okay so the first why was a direct static polymorphism that’s just um prefixing the methods so we have the

Complete marker the incremental marker and say okay we prefix um these methods and in the source code you have a configuration so you say uh all codes to the receiver marker should be um resolved to the incremental marker and uh the internals will um that’s quite annoying uh we’ll

Resolve this to to the corresponding function but uh this approach isn’t enough uh if you have an configuration with the default marker to increment a marker set as an example on the comp marker for complete marker and to call it so you will um cause a CM Mark and if CM Mark

Um my display doesn’t refresh at this moment it’s interesting I don’t know if you can see it or what you can see can you see us no uh you have some memory manager in this so we we can see the slides and to us they are advancing without any

Problem Oh for me is I sometimes freeze don’t Advance that’s a bit annoying um if we have a complete marker and we call something else that isn’t touched by the polymorphism um it will when it will solve the next operation on the marker will get just the marker call because

It’s the Comm marker is just an exception we we want normally the marker and we will call incremental marker operation which is um mostly in not um compatible with the um other logic so that’s problem so we need another approach and that’s the um spreading approach um and in this approach we have

A configuration again for the marker as an increment marker to complete marker we say these are the possibilities and what is the default incremental marker and logically what will happen is we get three versions we get a store version uh that’s the default so incremental marker and the prefixed versions all calls um

Going out of them are resolved to complete marker or incremental marker um in this cases so um this is something we apply to um existing code base so we want to do it easily um so we did some works on economics um and calls from polymorphic classes like a complete marker uh um

Generally um resolve to um calls resolved for this class so complete marker will call functions and they will resolve to the complete marker version um we can associate classes uh with polymorphic classes some classes are written on mind with only working with the com complete all the incremental logic so we can associate

Them and then there’s some fine fine grain control we can do on um method receiver base on uh the whole function um again it’s not Refreshing yeah no um okay we take the example from earlier again now M with the spreading polymorphism logic and again a Comm marker for complete marker we call the Comm marker with Mark it will um it it will again call an operation on the memory manager and because we are in

The complete marker it will resolve through the CM version of the call and now because everything here is resolved for the complete marker we get the CM Mark operation just what we want so solve uh um no a short experience report uh it work quite nice in the end but uh

At at starting time all slang is a bit funcky to work with sometimes it just doesn’t translate or um you have problems like it doesn’t generate all methods you need to see so it’s then that’s debugging it it’s quite annoying um what my tooling introduced is that

You get prefixes for the C functions which can be a bit annoying if you’re on CD debugger and you assume there’s a function that’s called without the prefix um that’s a minor inconvenience what’s bit more difficult and that’s more of an implementation thing is um the information how to resolve a method is

Spread from method to Method so if you go to a method that isn’t influenced by polymorphism and you call something that’s influenced by polymorphism you go back to the default case so that will breach the um the information spreading so you can get invalid State again like for the direct

Um uh for the first case for the direct approach and then you have to go in and find it and annotate some methods uh as you need it um one thing I did what was a bit uh helpful was was um exporting and cor graph of uh of the VM

Which is possible because he uh doesn’t have uh is you can uh see it and see what what method is called and it’s uh unique um and I annotated it with metal information so we can ask it something like show me uh where we resolved something for the incremental garbage

Collector and where goes through a call chain and how we come to the world uh to the stop the world garbage collector um logic and then we can uh validate is it okay is it not and possibly annotate some methods future work is generally a more sling improvements but expendability as

I said it’s something quite difficult to uh reason about then um detect if all necessary necessary functions got generated and um it’s a first class support for static polymer fism um not just as hacking around and uh using the static analysis but having it uh natively working so as a conclusion

Um our problem was just mapping from slang to small talk and we needed a limited amount of polymorphism we extended the code generator with Butch’s uh mental model with between slang and see a bit more because you can now WR your code a bit more small talky and

Errors can be difficult to trace even more now and finally to say slangers in general is a bit brittle but it works as a working tool thank you do you have questions thank [Applause] you so so any question I hope you can hear so uh when you were talking about

The the putting the prefixes on methods that that just reminded me a lot of you know C++ name mangling for instance uh and so but but it looked like some of the some some of the uh calls you you didn’t actually put prefixes on so just

Can can you explain a bit bit more about what decides when you prefix uh or or not because yeah you’ve got uh one that’s just store on its own um in general you in the direct case so in the first case from earlier you always preix before because you have um

In both cases you have some method present like Mark so you have to preix it or you could say one one is more more General but they all preix them here it’s more um of a logical view of it um it’s uh in general the uh default uh will be

Generated and um then the other case will be two so I am still isn’t you won’t see it any other question I I’m wondering if there’s any uh big difference here between uh your kind of spreading polymorphism and uh really just a kind of aggressive function specialization is

Specializing functions to the types of their arguments uh I don’t really understand your question could you specify that yeah function specialization is a technique where uh by looking at the specific types of the arguments being passed you generate another version of the function that uh then assumes those

Types yes you you could say this that’s uh mostly done on the Met method base that you say assume all markers are complete markers now or whatever we resolve for in this cases you could think let’s write about it any other question then I think we can thank the

Speaker for his talk thank you

Share.
Leave A Reply