-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LanguagePlatform for cross-language compatibility when there's no…
… place to extend
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
source/Buoy-Metaprogramming-Extensions/LanguagePlatform.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
18 changes: 18 additions & 0 deletions
18
source/Buoy-Metaprogramming-GS64-Extensions/GemStone64Platform.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
17 changes: 17 additions & 0 deletions
17
source/Buoy-Metaprogramming-Pharo-Extensions/PharoPlatform.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
source/Buoy-Metaprogramming-Tests/LanguagePlatformTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |