Squeak Plugin For DoubleArray

This page is created as a guide on how to create a plugin in Squeak that is based on a DoubleArray Class. Creating a plugin is by no means a trivial task as it requires knowledge on both Squeak programming and some basic C knowledge. It is hereby assumed that the user or programmer has some fundamental knowledge about Squeak programming. If a user is new to Squeak, it is recommended to take a brief glance on the book, Squeak By Example, which introduces the fundamentals of Squeak.
Introduction
The Squeak environment offers a chance for any user to customize or to extend the Squeak Virtual Machine according to their needs. This can be achieved by writing plugin(s) as a method of extending Squeak. In Squeak, plugin is defined as a collection of primitives. The built-in nature of primitive allows Squeak to call it directly instead of having to rely on message sends, which avoids the message send overhead.
The new Squeak Virtual Machine and plugin is rebuilt by writing the equivalent .C files and is compiled along with the source file of Squeak and then, with the help of the VMMaker package, the codes written in Squeak/ Slang language can be easily translated into its C equivalent.
There are two types of plugins in Squeak, which is internal plugin(.lib) and external plugin(.dll). An internal plugin is a plugin that is embedded within the Squeak VM; whereas external plugin is quite literally isolated from the VM creation and appears as separate .dll files.
Internal plugin is favoured if the plugin size is substantially large; Whilst external plugin is preferred when there are still a lot of development work of testing and debugging yet to be done, hence requiring the plugin to be regenerated frequently.
Squeak VM Setup
There are a few tools that needs to be downloaded before we can proceed to create our own plugins.
*The Squeak Source Release File
*The Compiling Tools
*A Fresh Squeak Image and Squeak Virtual Machine
All the files downloaded are then extracted, preferably into C:\ for the ease of explanation. Successfully download and extraction of the files will create the following few folders:
<code>
C:\SqueakVM-Win32-3.10.7\platforms\win32\build - From here on known as the build directory
C:\gnutools
C:\dx7sdk
C:\Squeak3.10.2-7179
</code>
Environment Setup
In order to get the compiling tools running, environment variables have to be set. This can be done by going to the properties of My Computer>Properties>Advanced Tab. The path under system variables is edited by adding C:\GNUTools\bin with semicolon(;) as the separator.


Install VMMaker Package
From the Squeak image, the package loader is pulled out from the tool tab. A search for the VMMaker package is carried out, and then installed into the Squeak Virtual Machine.


If there is any prompt or warning pop-ups, Just click on 'Yes' to proceed.
Replace Win32VMMaker Class
The Win32VMMaker Class in from the package that has just been downloaded is outdated. Failing to replace this will cause a complication in setting the path for generating the C files into the build directory. Hence, there is a need to remove the Win32VMMaker Class, under the 'VMMaker-Building' package. The updated Win32VMMaker Class is available in the build directory and it can be file-in to the image by using the file list tool. After that, perform a quick check on the updated Win32VMMaker Class definition to ensure that it is subclassed under VMMaker instead of VMMakerWithFileCopying.
Creating A Plugin
When writing a plugin, we have two things to consider. The first being the codes to interface the plugin within Squeak, the other being the actual plugin itself along with its collection of primitives. A plugin is normally developed in the interface before proceeding to the underlying primitives that will be called by Squeak.
Plugin Interface
The interface is the surface where Classes in Squeak runs through various message sends that needs to call the primitive to do the computation on behalf of the Class itself. The most important part in the plugin interface is that the programmer has to ensure that the necessary arguments are placed onto the stack. This is generally done by a method that will take the relevant number of arguments along with the receiver which can be then operated by the primitive.
Besides ensuring the arguments are in place in the stack, the development of backup codes are strongly encourage so that in case the plugin fails for some reason, there is the backup codes to pick up the pieces and perform the necessary computation. Another of writing backup codes for the interface first is that the logic of program can be tested and optimized. This makes use of the superior debugger of Squeak and reduces the time needed to troubleshoot and debug the program significantly. Testing the logic of the program in the interface also avoids the need to constantly regenerating the plugin after each and every minor amendment.
Plugin Primitives
There are two things two worry in this section, one being the handling of the stack, the other being the computational part of the primitive. The stack has to be accessed properly and tests has to be conducted to ensure that the object in the stack is having the correct data type or the number of elements (if the object happens to be an array) are having the correct size. The top of the stack are designated with the index 0, and the first, second objects after the top of the stack are having the index of 1, 2 respectively and this stack mapping extends according to the index.
In developing the computational part of the primitive, it is noted that a reference on the program logic is already developed in the interface backup code, hence the logic of the codes are transferred into this part and only minor amendments are needed, for example, the array indices are reduced by one for all array accesses since array starts at 0 in C, and 1 in Squeak.
Plugin Generation and Compilation
The VMMaker GUI is invoked by do-ing the following in workspace.
<code>VMMakerTool openInWorld</code>


The fields are filled with the following:
<code>
Interpreter class name: Interpreter
Path to platform code: C:\SqueakVM-Win32-3.10.7\platforms
Platform name: Win32
Path to generate sources: C:\SqueakVM-Win32-3.10.7\platforms\win32\build\src
</code>
Next, right click in the Plugins Not Built pane and select make all internal. Then, click on Entire to genarate source code for compilation. For customized plugins, it will appear in the Plugins Not Built pane and it can be draged to the internal plugin or external plugin pane on the programmer's discretion. Instead of clicking on generating entire, generating internal or external should suffice.
In order to compile the New VM and plugins, the command prompt is executed and the directory is changed to the build directory, C:\SqueakVM-Win32-3.10.7\platforms\win32\build. Then make is invoked. If there is any error, then click on Entire again in the VMMaker GUI, follow by reinvoke make in the command prompt.
The translated .C files are stored in C:\SqueakVM-Win32-3.10.7\platforms\win32\build\src whilst the new VM and plugin is stored in C:\SqueakVM-Win32-3.10.7\platforms\win32\build\obj\vm.
DoubleArray Class
DoubleArray is created to manipulate 64-bit double precision floating point data type. This gives a better precision in computation as compared to 32-bit single precision floating point data type.
DoubleArray Class Interface
DoubleArray Plugin
 
< Prev   Next >