Smalltalk Interchange File

06 Jan 2016

The ANSI Smalltalk standard defines SIF, Smalltalk Interchange File, which is a common format for Smalltalk dialects to exchange file-outs. Eric Arseneau implemented SIF for Squeak (some old version), Dolphin (v2!), VisualWorks (v3!) and VisualAge Smalltalk (v4!) back in 2000. The implementation is found here.

15+ years later, the implementation files in cleanly on Squeak v5, Pharo v4 and Dolphin v7. Let's see if I can use this to quicken the port of NBSQLite3 from Pharo to Dolphin. I'll test with moving a single class, NBSQLite3Backup.

First, file out from a Pharo workspace.

SmalltalkInterchangeFileManager newForFileOut
    fileName: 'NBSQLite3Backup.sif';
    addClass: NBSQLite3Backup;
    addPackageNamed: 'NBSQLite3';
    fileOut. 

Then, file in from a Dolphin workspace.

SmalltalkInterchangeFileManager newForFileIn
    fileName: 'NBSQLite3Backup.sif';
    fileIn.

Up pops the Dolphin debugger, with an error signaled by SmalltalkInterchangeDolphin3FileInManager>>fileInClassItem:. Turns out that the offending filed-out source is the following:

a SmalltalkInterchangeFileItem(
    type: #class
    firstToken: 'Class'
    name: 'NBSQLite3Backup'
    superclassName: 'Object'
    instVarType: #'#none'
                 ^^^^^^^^

In particular, the symbol made from the string '#none'. I'm guessing that Dolphin wants the symbol #none, not #'#none'. Looking around SIF's source, the fix is in SmalltalkInterchangeSqueakFileOutManager>>nextSymbolPutString: which looks like this:

nextSymbolPutString: string
    self nextPut: $#.
    ^super nextSymbolPutString: string

Remove the "self nextPut: $#" line, accept the change. File out from Pharo, and try to file into Dolphin again.

Up pops the debugger. But this time the Transcript has something to say:

Error: NBSQLite3Backup>>prepare at line 1: undeclared 'NBExternalResourceManager'

NBExternalResourceManager is a NativeBoost thing and does not exist in Dolphin. To fix, edit the SIF file and remove that line, preserving the chunking.

File in again. Debugger again. This time Dolphin complains that NBSQLite3DatabaseExternalObject is undeclared. In Dolphin all FFI handles are instances of ExternalAddress. Edit the SIF file to that effect.

File in again. Finally, success! This is predicated on my having written the appropriate apiXXX methods in NBSQLite3FFI. And I haven't written/imported enough of the rest of NBSQLite3 to test whether the filed-in code works, so success here only means success in filing code into Dolphin. :-)

NBSQLite3 is a C library wrapper with dialect-specific FFI calls. As such porting it is slightly more involved. I suspect that "pure" Smalltalk code written portably should be much easier to move between Pharo and Dolphin, or between any two modern dialects of Smalltalk.

Tags: Dolphin Smalltalk

NBSQLite3 on Dolphin Smalltalk 7

31 Dec 2015

Dolphin Smalltalk 7 has been released as open source. Many thanks to Object Arts.

I spent an afternoon updating the mostly unused Windows partition on my laptop, installing various development tools, and playing with Dolphin 7. As a proof of concept, NBSQLite3 now runs on Dolphin 7. :-)

NBSQLite3 for Dolphin

Happy new year!

Tags: Dolphin Smalltalk, SQLite