Friday, June 24, 2016

Functional callbacks on all Cog platforms

Pharo as well as Squeak are based on a common virtual machine implementation (Squeak VM, later Cog). This virtual machine source code recently was moved over to GitHub as OpenSmalltalk VM to better maintain the (small but existing) differences in the virtual machines for Squeak, Pharo, Newspeak and Cuis Smalltalk.

Within all open source Smalltalks derived from Squeak (Squeak, Pharo, Newspeak) historically and initially there was a mechanisms to call external code outside the Smalltalk environment. This mechanism was called FFI - which is the abbreviation for foreign function interface. So you could call external libraries to perform an action.

Later there was another mechanism called Alien FFI that also allowed to pass a callback function to the ouside world. Alien was provided in 2007 by Eliot Miranda and old docu could be found here and here.

In Pharo later there was another mechanism called "NativeBoost" (provided by Igor Stasenko) to call external functions. NB allowed to be using native code directly and really fast as the native code was attached to a compiled method and lived within the image. Relying on assembler (provided by a package called ASMJit) the NativeBoost solution is very fast - but also hard to maintain because NB was not as portable as the initial FFI solutions.

Later Pharo decided to resynch all these efforts into what is now known as UFFI (Unified Foreign Function Interface) provided by Esteban Lorenzano. UFFI unifies and also borrows from FFI, Alien and even NativeBoost.

Also with the more aligned OpenSmalltalk VM the different open source Smalltalks come closer together. Current work in progress on the virtual machine side is to allow for 64 bit Smalltalk systems and to better support ARM architecture beside x86 one.

Eliot now announced that Alien now has functional callbacks on all x86 platforms, ARM32 platforms and x86_64 platforms. This is another major step in having a portable interface to the outside world as we can use callbacks on all these platforms. Great stuff!!!


No comments: