Importing a GNU Smalltalk project into Pharo?
Asked Answered
C

2

7

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.

Chaos answered 7/6, 2016 at 23:21 Comment(1)
Very good question. I'm posting this on the list to give it more exposure.Chrissa
O
8

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
Ora answered 8/6, 2016 at 5:57 Comment(4)
This looks promising. I took one of my modules and quickly converted it to the filein format. I used the Pharo 5.0 Tools > File Browser to find the filein file and selected it. it showed up in the preview window. I clicked "Filein" and... nothing happened. I also tried right-clicking the file name, selecting "Filein entire file" or "Install into new change set" and nothing happened.Chaos
fileIn (or chunk) format is a bit tricky as for the ! mark signs. Sometimes you need two of them with a whitespace between in unsuspected places... You should check that.carefully And the final solution shoudl be debugging what happens when you do "File in", you will quickly find the wring assumption if you are patience enough to go Into, and Into.Anissa
@CarlosE.Ferro OK, good suggestion. I may have oversimplified my conversion process or missed some subtlety in it. I can check it.Chaos
I either neglected to refresh the system browser first time I did the import, or making sure I included the SystemOrganization line, but it works great now.Chaos
H
3

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.

Halfwit answered 8/6, 2016 at 16:3 Comment(4)
See my comment to the other answer. I created a filein formatted file, but Pharo quietly did nothing when I tried importing it.Chaos
Sorry. Can't help you if you are not willing to try out my solution. Good luck.Halfwit
No need to be snarky. I did not say I wasn't willing to try your suggestion at all, did I? I plan to examine what I did try first, and if that fails, try your simplified example as a baseline. I may reverse the order of those. Don't know yet.Chaos
I wrote a detailed sample of what works for me. I can answer questions about that. Not about some file you did not show me on an unknown platform. You say 'I created a filein formatted file but Pharo quietly did nothing when I tried importing it'. Right. What is one to make out of that? Where is your file or a snippet from it? Did you convert the linefeeds to carriage returns before you tried to file it in? What version of Pharo do you have? What platform are you running Pharo on? Windows/Linux/Mac OS X? What version? After 'Pharo did nothing', where did you look for your code?Halfwit

© 2022 - 2024 — McMap. All rights reserved.