Hey. I started this thread due to my corrupting my image and changes when generating classes and compiling methods incorrectly.
Would someone be able to guide me through correct class and method generation, please?
Gratefully, rabbit â¤ď¸âđĽđ°
On Sun, Jul 9, 2023 at 11:55, rabbit via Cuis-dev <[cuis-dev@lists.cuis.st](mailto:On Sun, Jul 9, 2023 at 11:55, rabbit via Cuis-dev <<a href=)> wrote:
Hey, I am a touch frustrated. Recovered with <49>. The code I wrote to generate classes and methods has been corrupting my image, or rather mucking to the changes. I was having old code versions being loaded and breaking bad. I was publishing a lot of garbage because when running the BoxOfKittens, I was generating several SharedNears, now called Neighbors. This subclass generation and the method compilation is being done it the following methods...I am just going to leave it turned off for now and stay focused on my objective. It is an example of corruption occurring, if that helps anyone. If one could tell me how to better generate these artifacts, that would be outstanding!â˘
â˘â˘â˘
The #buildOnClass is called from a class creation method
buildOnClass: eClazz
|refClass | refClass := self stubClass subclass: (eClazz name, 'Stub') asSymbol instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: self userClassCategoryString.
"Copy all methods, up to Object, to the new refClass, with redirectMessage forwarding." self copyMethodsToClass: refClass fromClass: eClazz upToClass: Object.
^ refClass
â˘â˘â˘
copyMethodsToClass: refClass fromClass: valueClazz upToClass: rootClass
| arguments classes newMethodString | "Collect classes to contribute message protocol." classes := valueClazz allSuperclasses select: [ :clazz | (Object ~~ rootClass) and: [ Object inheritsFrom: clazz] ].
"contribute message protocols." classes do: [:thisClazz | thisClazz methodDictionary keysAndValuesDo: [:selector :method | arguments := method tempNames first: method numArgs. newMethodString := self buildForwardingMethod: selector contents arguments: arguments. Compiler compile: newMethodString environment: refClass environment notifying: nil trailer: method trailer ifFail: [nil]]].
â˘â˘â˘
buildForwardingMethod: selector arguments: arguments
| argumentString selectorStream | argumentString := ((arguments inject: ''writeStream into: [:stream :argument | stream nextPutAll: argument, ' ']) contents). selectorStream := '' writeStream. (selector subStrings: $:) with: arguments do: [:keyword :argument | selectorStream nextPutAll: keyword, ': ', argument, ' ']. ^ selectorStream contents, '
^self redirectMessage: (Message selector: ', selector asSymbol printString, ' arguments: #{', argumentString, '}).'
Alright then,
-- â˘â˘â˘ rabbit â¤ď¸âđĽđ°
cryptography@lists.squeakfoundation.org