Skip to content

Commit

Permalink
Add LanguagePlatform for cross-language compatibility when there's no…
Browse files Browse the repository at this point in the history
… place to extend
  • Loading branch information
gcotelli committed Aug 18, 2023
1 parent 2678b16 commit bb2f55a
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/Buoy-GS64-Compatibility/GsCurrentSession.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"
In GS64, GsCurrentSession provides a public interface to the current GemStone session.
There is only one instance of GsCurrentSession in each GemStone session.
The GemStone server creates it automatically when a user logs into GemStone.
The instance is transient and cannot be accessed after the user logs out of
GemStone.
This version is just a placeholder so we can easily create extensions methods to load in GS64 specific
packages.
"
Class {
#name : #GsCurrentSession,
#superclass : #Object,
#category : #'Buoy-GS64-Compatibility'
}
12 changes: 12 additions & 0 deletions source/Buoy-GS64-Compatibility/GsSocket.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
"
In GS64, GsSocket provides the means for creating and binding TCP sockets through the
operating system of the machine that is running the session's Gem process, and
for communicating across those sockets.
When the current GsProcess is suspended until a socket is ready to read or write,
other GsProcess that are ready to run will be run by the process scheduler.
Methods that suspend the current GsProcess until the socket operation completes
are interruptable by a hard break.
This version is just a placeholder so we can easily create extensions methods to load in GS64 specific
packages.
"
Class {
#name : #GsSocket,
#superclass : #Object,
Expand Down
28 changes: 28 additions & 0 deletions source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class {
#name : #LanguagePlatform,
#superclass : #Object,
#classInstVars : [
'Current'
],
#category : #'Buoy-Metaprogramming-Extensions'
}

{ #category : #accessing }
LanguagePlatform class >> current [

Current ifNil: [ Error signal: 'The language platform was not set' ].
^Current
]

{ #category : #accessing }
LanguagePlatform class >> setCurrentTo: aLanguagePlatform [

Current := aLanguagePlatform.
^Current
]

{ #category : #reflection }
LanguagePlatform >> globalNamed: aSymbol ifAbsent: absentBlock [

^ self subclassResponsibility
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class {
#name : #GemStone64Platform,
#superclass : #LanguagePlatform,
#category : #'Buoy-Metaprogramming-GS64-Extensions'
}

{ #category : #'class initialization' }
GemStone64Platform class >> initialize [

LanguagePlatform setCurrentTo: self new
]

{ #category : #reflection }
GemStone64Platform >> globalNamed: aSymbol ifAbsent: absentBlock [

^ (GsCurrentSession currentSession symbolList objectNamed: aSymbol)
ifNil: absentBlock
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Class {
#name : #PharoPlatform,
#superclass : #LanguagePlatform,
#category : #'Buoy-Metaprogramming-Pharo-Extensions'
}

{ #category : #'class initialization' }
PharoPlatform class >> initialize [

LanguagePlatform setCurrentTo: self new
]

{ #category : #reflection }
PharoPlatform >> globalNamed: aSymbol ifAbsent: absentBlock [

^ Smalltalk globals at: aSymbol ifAbsent: absentBlock
]
23 changes: 23 additions & 0 deletions source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Class {
#name : #LanguagePlatformTest,
#superclass : #TestCase,
#category : #'Buoy-Metaprogramming-Tests'
}

{ #category : #tests }
LanguagePlatformTest >> testGlobalNamedIfAbsent [

| sentinel |
self
assert: (LanguagePlatform current
globalNamed: self class name
ifAbsent: [ self fail ])
equals: self class.

sentinel := Object new.
self
assert: (LanguagePlatform current
globalNamed: #AnImplausibleGlobalName
ifAbsent: [ sentinel ])
identicalTo: sentinel
]

0 comments on commit bb2f55a

Please sign in to comment.