Skip to content

Commit b1a1837

Browse files
committed
should be able to use RwGsPackageSymbolDictionary>>addNewCompiledMethod:for:protocol:toPackageNamed: and RwGsPackageSymbolDictionary>>addRecompiledMethod: almost interchangeable ... with the exception when the class has not been packaged and no target package was specified (addRecompiledMethod: to an unpackaged class) ... consider adding packageName: to selector ... fine tuning can be deferred until later
1 parent 13ba508 commit b1a1837

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

tonel/Rowan-GemStone/RwGsPackageSymbolDictionary.class.st

+31-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Class {
99
#category : 'Rowan-GemStone'
1010
}
1111

12+
{ #category : 'accessing' }
13+
RwGsPackageSymbolDictionary class >> defaultProtocolString [
14+
15+
^ 'as yet unclassified'
16+
]
17+
1218
{ #category : 'instance creation' }
1319
RwGsPackageSymbolDictionary class >> newNamed: aSymbol [
1420

@@ -129,8 +135,9 @@ RwGsPackageSymbolDictionary >> addExtensionCompiledMethod: compiledMethod for: b
129135
loadedPackage := self packageRegistry
130136
at: packageName
131137
ifAbsent: [
132-
self
133-
error: 'Internal error -- attempt to add a method to a nonexistent package.' ].
138+
self packageRegistry
139+
at: packageName
140+
put: (RwGSLoadedSymbolDictPackage newNamed: packageName) ].
134141

135142
loadedClassOrExtension := loadedPackage
136143
loadedClassExtensionForClass: behavior
@@ -166,6 +173,14 @@ RwGsPackageSymbolDictionary >> addNewCompiledMethod: compiledMethod for: behavio
166173
| methodDictionary selector protocolSymbol existing loadedMethod loadedPackage loadedClassOrExtension properties |
167174
methodDictionary := behavior persistentMethodDictForEnv: 0.
168175
selector := compiledMethod selector.
176+
methodDictionary
177+
at: selector
178+
ifPresent: [ :oldCompiledMethod |
179+
"there is an existing compiled method ... that means we're adding a recompiled methoded and moving it to the (possibly new) protocol"
180+
^ self
181+
addRecompiledMethod: compiledMethod;
182+
moveCompiledMethod: compiledMethod toProtocol: protocolString;
183+
yourself ].
169184
methodDictionary at: selector put: compiledMethod.
170185

171186
protocolSymbol := protocolString asSymbol.
@@ -207,17 +222,23 @@ RwGsPackageSymbolDictionary >> addRecompiledMethod: newCompiledMethod [
207222
oldCompiledMethod := methodDictionary
208223
at: selector
209224
ifAbsent: [
210-
self
211-
error:
212-
'Internal error -- no existing CompileMethod found for patched method: '
213-
, selector printString ].
225+
| loadedClass |
226+
loadedClass := classRegistry
227+
at: behavior theNonMetaClass classHistory
228+
ifAbsent: [
229+
self
230+
error:
231+
'Internal error -- The class is not in any known package and no package has been specified' ].
232+
^ self
233+
addNewCompiledMethod: newCompiledMethod
234+
for: behavior
235+
protocol: self class defaultProtocolString
236+
toPackageNamed: loadedClass packageName ].
214237

215238
oldCompiledMethod == newCompiledMethod
216239
ifTrue: [
217-
self
218-
error:
219-
'Internal error -- The new recompiled method is identical to the installed method '
220-
, selector printString ].
240+
"exit early, no more work to be done"
241+
^ self ].
221242
methodDictionary at: selector put: newCompiledMethod.
222243

223244
loadedMethod := methodRegistry

tonel/Rowan-Tests/RwSymbolDictionaryTest.class.st

+19-6
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,13 @@ RwSymbolDictionaryTest >> testMethodAdditionPatch [
387387

388388
methodSelector := #'foo'.
389389
methodSource := 'foo ^ ''foo'''.
390-
methodProtocol := 'accessing'.
390+
methodProtocol := RwGsPackageSymbolDictionary defaultProtocolString.
391391
compiledMethod := self
392392
_compileMethodIn: class
393393
source: methodSource
394394
dictionaries: GsCurrentSession currentSession symbolList.
395395

396-
dict
397-
addNewCompiledMethod: compiledMethod
398-
for: class
399-
protocol: methodProtocol
400-
toPackageNamed: packageName.
396+
dict addRecompiledMethod: compiledMethod. "this should work, ends up using the package of the class"
401397

402398
self assert: testInstance foo = 'foo'.
403399
self
@@ -670,6 +666,23 @@ RwSymbolDictionaryTest >> testMethodSourcePatch [
670666
self
671667
assert: (x := testClass categoryOfSelector: #'foo') = methodProtocol asSymbol.
672668

669+
methodSource := 'foo ^ ''who'''.
670+
methodProtocol := 'the accessing'.
671+
newCompiledMethod := self
672+
_compileMethodIn: class
673+
source: methodSource
674+
dictionaries: GsCurrentSession currentSession symbolList.
675+
676+
dict
677+
addNewCompiledMethod: newCompiledMethod
678+
for: class
679+
protocol: methodProtocol
680+
toPackageNamed: packageName. "account for using wrong method to update a method --- perhaps the selector is incorrect?"
681+
682+
self assert: testInstance foo = 'who'.
683+
self
684+
assert: (x := testClass categoryOfSelector: #'foo') = methodProtocol asSymbol.
685+
673686
expectedPackageSet := self
674687
packageSetDefinition: packageName
675688
classNamed: className

0 commit comments

Comments
 (0)