Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing a GNU Smalltalk project into Pharo?

I have about 1800 lines of GNU Smalltalk code I'd like to pull into Pharo. I've started doing it class by class, selector by selector, but it is very time consuming and tedious.

Is there a way to bulk import a project? I could easily adjust the format of the GST source files with vi to be more Pharo-like beforehand.

Another thing I've considered is copying a "starter" .mcz file, getting a feel for the format of the source.st file, then creating a new source.st with file cats and vi. But then there's the snapshot.bin file which seems also to have the source in it, making that a difficult path. It seems there should be an easier way. I've Google'd for it with different phrases but haven't hit anything.

like image 448
lurker Avatar asked Jun 07 '16 23:06

lurker


2 Answers

Putting it in Monticello (.mcz) format is overkill for migrating. Just get it into fileout format (http://wiki.squeak.org/squeak/1105) and once you've loaded it into Pharo via filein, then you can create a Monticello package using the GUI if you want.

An quick way to see what fileout format involves (mainly just putting '!' in the right places):

  1. Load up Pharo
  2. Open a Browser
  3. Right click on a class and select 'File Out' from the menu
  4. You should see a file called [Classname].st in the directory you launched Pharo from
like image 60
blihp Avatar answered Nov 03 '22 19:11

blihp


Say you have two classes, LuckyClass1 a subclass of Object and LuckyClass2 subclass of LuckyClass1. And let's say your name is LuckyName. And let's say you want to put your code into the package Lucky-Package1.

Object subclass: #LuckyClass1
LuckyClass1 subclass: #LuckyClass2

Class LuckyClass1 with an instance side method luckyInstanceSideMethod1, a class side method luckyClassSideMethod1 and instance side variable luckyInstanceSideVariable1 and class side variable LuckyClassSideVariable1.

Similarly class LuckyClass2 with an instance side method luckyInstanceSideMethod1, a class side method luckyClassSideMethod1 and an additional instance side variable luckyInstanceSideVariable2 and class side variable LuckyClassSideVariable2.

Method references would look like this

LuckyClass1>>#luckyInstanceSideMethod1
LuckyClass1 class>>#luckyClassSideMethod1
LuckyClass2>>#luckyInstanceSideMethod1
LuckyClass2 class>>#luckyClassSideMethod1

On Linux/Mac OS X, do

vi Lucky-Package1-unix.st

to put in a file named Lucky-Package1-unix.st something like

Object subclass: #LuckyClass1
    instanceVariableNames: 'luckyInstanceSideVariable1'
    classVariableNames: 'LuckyClassSideVariable1'
    poolDictionaries: ''
    category: 'Lucky-Package1'!

!LuckyClass1 methodsFor: 'lucky instance side protocol 1' stamp: 'LuckyName 6/8/2016 17:05'!
luckyInstanceSideMethod1
    ^ luckyInstanceSideVariable1 := 'lucky instance side'
! !

!LuckyClass1 class methodsFor: 'lucky class side protocol 1' stamp: 'LuckyName 6/8/2016 17:06'!
luckyClassSideMethod1
    ^ LuckyClassSideVariable1 := 'lucky class side'
! !

LuckyClass1 subclass: #LuckyClass2
    instanceVariableNames: 'luckyInstanceSideVariable2'
    classVariableNames: 'LuckyClassSideVariable2'
    poolDictionaries: ''
    category: 'Lucky-Package1'!

!LuckyClass2 methodsFor: 'lucky instance side protocol 1' stamp: 'LuckyName 6/8/2016 17:15'!
luckyInstanceSideMethod1
    ^ super luckyInstanceSideMethod1, ' subclass'
! !

!LuckyClass2 class methodsFor: 'lucky class side protocol 1' stamp: 'LuckyName 6/8/2016 17:17'!
luckyClassSideMethod1
    ^ super luckyClassSideMethod1, ' subclass'
! !

In fact, you can cut & paste the preceding block.

Then convert linefeeds to carriage returns or else Pharo will complain. This is important. If you are on Linux/Mac OS X you can use the following

cat Lucky-Package1-unix.st | tr \\n \\r > Lucky-Package1-pharo.st

On Windows I would still use bash, vi, cat, tr from git-scm https://git-scm.com/download/win

Then file in Lucky-Package1-pharo.st. It should appear in the Lucky-Package1 package in System Browser.

like image 44
Milan Vavra Avatar answered Nov 03 '22 19:11

Milan Vavra