[Vm-dev] Is B2DPlugin C code only?

David T. Lewis lewis at mail.msen.com
Sun May 18 02:23:11 UTC 2014


On Sat, May 17, 2014 at 11:44:40AM -0700, gettimothy wrote:
>  
> Hi All,
> 
> 
> I have checked high and low and cannot find B2DPlugin in Smalltalk, but it is in a lot of repositories. Is there such a thing as plugins without an internal smalltalk class?
> 

This one is a bit tricky. You are looking at B2DPlugin.c, which is the
translated C code for one of the plugins that is written in Smalltalk.
As you have noticed, it is not entirely obvious how this came to be, but
if you look in the comment at the top fo the B2DPlugin.c file, you will
see that it was automatically generated from class BalloonEnginePlugin.

The tricky bit is that the name of the C source module is controlled by
the #moduleName method in the Smalltalk class being generated. By default,
the C module name is just the name of the class being translated. But if
a class method #moduleName is provided, then this will specify the name of
the generated C code.

If you look at BalloonEnginePlugin, which is the class that is translated
into B2DPlugin.c in C, you will see that it has a superclass BalloonEngineBase,
and that the superclass does this:

  BalloonEngineBase class>>moduleName 
     ^'B2DPlugin'

So this is the method that causes the generated C file to be called B2DPlugin.c.

The Smalltalk class comments give an indication of why B2DPlugin is organized
in this manner. After reading the comments, you can see how the methods
#shouldBeTranslated and #moduleName are implemented in BalloonEngineBase
to control the code generation to C.

You will notice also that there is a class BalloonEngineSimulation that is
subclassed from BalloonEngineSimulation. This subclass is not translated to
C, but instead provides support for running B2DPlugin directly in Smalltalk.

This particular plugin is interesting because it represents a substantial
amount of low level graphics code written directly in Smalltalk, not in C.
The author was able to write in Smalltalk for clarity and ease of debugging,
with no sacrifice of performance once the code was translated to compiled C.

Dave



More information about the Vm-dev mailing list