GemTalk / Rowan

a new project/package manager for Smalltalk that supports FileTree and Tonel repositories, and is independent of Monticello and Metacello
MIT License
14 stars 7 forks source link

v2.4 topaz format packages for Rowan #820

Open dalehenrich opened 2 years ago

dalehenrich commented 2 years ago

There is no reason why a topaz .gs file cannot be managed as a Rowan package file. A topaz INPUT file is a superset of a Rowan package.

The primary requirement for a package file is that all of the elements in the .gs file must be elements that can be preserved in Rowan definitions. The primary properties of a Rowan package are:

  1. package name
  2. method definitions
  3. class definitions With the exception of explicit class definitions a topaz INPUT file has the necessary commands. The SET PACKAGE: command (currently only implemented in GsFileIn) defines a package name. The CATEGORY:, METHOD:, and CLASSMETHOD: commands combine to define Rowan method definitions:
    
    SET PACKAGE: Filein1A
    CATEGORY: 'Instance Creation'
    CLASSMETHOD: AbstractCollisionBucket
    new

"Returns an AbstractCollisionBucket with a default capacity of four key/value pairs."

^ self new: 4 % CATEGORY: 'Comparing' METHOD: AbstractCollisionBucket = anObject

"Reimplemented to compare by identity."

^ self == anObject %

For class defititions, it should be possible to derive a class definition by parsing the expressions in a DOIT. The following is the standard class creation pattern, used by Rowan when writing out a .gs file:

doit (PrivateObject subclass: 'Upgrade1B' instVarNames: #( ) classVars: #( doit err ) classInstVars: #( ) poolDictionaries: #() inDictionary: Globals options: #( #logCreation ) ) category: nil; comment: 'Upgrade1B is a class used during image upgrade.
Methods should only be executed via the image upgrade scripts.'; immediateInvariant. true. %

and it is possible to extract the necessary information from the message sends in the class creation DOIT to construct the following tonel format class definition:

" Upgrade1B is a class used during image upgrade. Methods should only be executed via the image upgrade scripts. " Class {

name : 'Upgrade1B',

#superclass : 'PrivateObject',
#classVars : [
    'doit',
    'err'
],
#gs_options : [
    'logCreation'
],
#category : nil

}

I've done a proof of concept using a subclass of GsFileIn that produces the above results and it should be possible to support additional fileout patterns. 
------------------------------
load using topaz INPUT command 
------------------------------
A topaz file containing SET PACKAGE:  and CLASSDEFINITION commands may be  loaded into an image using the topaz INPUT command with or without Rowan installed. 

If Rowan is not installed when the INPUT command is used, then the SET PACKAGE: command is ignored and there is no restriction on the number of SET PACKAGE: commands present in the INPUT file.

If Rowan is installed when the INPUT command is used, then METHOD:, CLASSMETHOD: and class creation DOIIT  commands will create new methods and classes in the package defined by the most recent SET PACKAGE: command. Existing methods and classes will be updated if already in package as defined by the most recent SET PACKAGE: command. If the SET PACKAGE: command does not match the existing package, then the methods and classes will be updated and moved to the package as defined by the most recent SET PACKAGE: command.

As currently implemented in GsFilein, a session temp is used to record the SET PACKAGE: package and the following expressions can be used to set and access the session temp:

Rowan gemstoneTools topaz currentTopazPackageName Rowan gemstoneTools topaz currentTopazPackageName:


The implication is that a user may set the SET PACKAGE: in the image without needing to embed a SET PACKAGE: command in a topaz INPUT file.

-----------------------------------
topaz Package Format
-----------------------------------
For topaz pakcage format in Rowan, the packages directory would simply contain a collection of topaz input files sporting a .gs extension. To qualify as a valid .gs package file, the first topaz command in the file must be a SET PACKAGE: command. Only one SET PACKAGE: command is allowed. The remainder of the file will be constrained to the following commands:
- CATEGORY:
- METHOD:
- CLASSMETHOD:
- DOIT that match a limited set of class creation patterns
It is an error if any other topaz commands appear in the file. It is also an error if there is more than one class definition DOIT per class or more than one METHOD: or CLASSMETHOD: command for the same method.

When Rowan exports a .gs file, the class definition DOIT commands will come first in class hierarchy order, followed by the method definitions for each class. Class-side methods in selector order followed by instance-side methods in selector order.

The .gs files in the Rowan package directory may be loaded using the topaz INPUT but it should be noted that when Rowan does a package load all of the package files in the directory are read into the image as definitions and ALL classes in all packages are created in class hiearchy order before creating/updating the methods, so is is up to the users to manage the package content themselves if they expect to use the topaz INPUT command
dalehenrich commented 2 years ago

Created GsFileinPackager (in internal git repo for now) that appears to successfully create the correct Rowan definitions by parsing the .gs files that were created from packages ... GsFileinPackager can use either the RB or GsCompiler classes (GsCompilerIRNode and friends) ... added workspace parser to RB and added accessor methods GsCompiler classes ... since the GsCompiler classes are hidden in 3.7.0 (I think) will need to arrange to add the accessor methods to the base image ...

dalehenrich commented 2 years ago

Rowan implementation looks complete ... still need to hook this up with topaz ...