Marcel Taeumel uploaded a new version of Kernel to project The Trunk: http://source.squeak.org/trunk/Kernel-mt.1539.mcz
==================== Summary ====================
Name: Kernel-mt.1539 Author: mt Time: 7 December 2023, 12:40:17.241684 pm UUID: cbf2bf83-08df-3940-b367-09dec0f14945 Ancestors: Kernel-ct.1538
Refines Kernel-ct.1538 with some commentary and an extra: - Message >> #arguments: - MessageSend >> #sendTo: - WeakMessageSend >> #sendTo:
For WeakMessageSend, guard #asMessageSend conversion with a warning if arguments or recevier got already collected.
For WeakMessageSend, guard #asMessage conversion with a warning if arguments got already collected.
=============== Diff against Kernel-dtl.1537 ===============
Item was added: + ----- Method: Message>>arguments: (in category 'accessing') ----- + arguments: anArray + + args := anArray.!
Item was changed: ----- Method: MessageSend>>asMessage (in category 'converting') ----- asMessage + "Convert the receiver into a message, which has its 'receiver' variable dropped. Note that messages are rather low-level objects and primarily used for #doesNotUnderstand: as they have a #lookupClass: as a special feature. The difference between #sendTo: and #sentTo: can be confusing. Therefore, be aware that you can always use message-sends with a temporary 'nil' receiver." + + ^ Message selector: selector arguments: arguments! - ^ Message selector: selector arguments: arguments.!
Item was added: + ----- Method: MessageSend>>asMessageSend (in category 'converting') ----- + asMessageSend + + ^ self + !
Item was added: + ----- Method: MessageSend>>asWeakMessageSend (in category 'converting') ----- + asWeakMessageSend + "Convert the receiver into a similar representation, but which only references weakly to its receiver and arguments." + + ^ WeakMessageSend + receiver: self receiver + selector: self selector + arguments: (Array withAll: self arguments) + !
Item was added: + ----- Method: MessageSend>>sendTo: (in category 'sending') ----- + sendTo: anotherReceiver + "Compatibility with Message protocol. Evaluate the receiver (i.e., message send) with anotherReceiver instead of the current 'receiver' instVar." + + | originalReceiver | + originalReceiver := self receiver. + ^ [self receiver: anotherReceiver. self value] + ensure: [self receiver: originalReceiver]!
Item was changed: ----- Method: MessageSend>>valueOtherwise: (in category 'evaluating') ----- valueOtherwise: aBlock + "Compatibility with WeakMessageSend. Send the message and answer the return value" - "Send the message and answer the return value"
^self value!
Item was changed: ----- Method: MessageSend>>valueWithArguments:otherwise: (in category 'evaluating') ----- valueWithArguments: anArray otherwise: aBlock + "Compatibility with WeakMessageSend."
^ self valueWithArguments: anArray!
Item was changed: ----- Method: WeakMessageSend class>>new (in category 'instance creation') ----- new + "Overwritten to use the first (weak) slot for the receiver. Arguments are managed dynamically with an extra weak array." + + ^ self new: 1 - ^self new: 1 !
Item was added: + ----- Method: WeakMessageSend>>asMessage (in category 'converting') ----- + asMessage + "Convert the receiver into a message, which has its 'receiver' variable dropped. Note that messages are rather low-level objects and primarily used for #doesNotUnderstand: as they have a #lookupClass: as a special feature. The difference between #sendTo: and #sentTo: can be confusing. Therefore, be aware that you can always use message-sends with a temporary 'nil' receiver." + + self isAnyArgumentGarbage ifTrue: [self notify: 'Should not convert. Some arguments got collected. Proceed with caution.' translated]. + ^ Message selector: selector arguments: arguments!
Item was changed: ----- Method: WeakMessageSend>>asMessageSend (in category 'converting') ----- asMessageSend + "Convert the receiver into a similar representation, but which references strongly to its receiver and arguments. Raise a warning if objects got already garbage-collected. Use #on:do: if you automatically want to ignore this warning." + + self isReceiverOrAnyArgumentGarbage ifTrue: [self notify: 'Should not convert. Receiver or some arguments got collected. Proceed with caution.' translated]. ^MessageSend receiver: self receiver selector: selector arguments: (Array withAll: self arguments) !
Item was added: + ----- Method: WeakMessageSend>>asWeakMessageSend (in category 'converting') ----- + asWeakMessageSend + + ^ self!
Item was added: + ----- Method: WeakMessageSend>>cull: (in category 'evaluating') ----- + cull: firstArg + "Send the message with these optional arguments and answer the return value" + + selector numArgs >= 1 ifTrue: [ ^self value: firstArg ]. + ^self value!
Item was added: + ----- Method: WeakMessageSend>>cull:cull: (in category 'evaluating') ----- + cull: firstArg cull: secondArg + "Send the message with these optional arguments and answer the return value" + + | numArgs | + (numArgs := selector numArgs) >= 2 ifTrue: [ ^self value: firstArg value: secondArg ]. + numArgs = 1 ifTrue: [ ^self value: firstArg ]. + ^self value!
Item was added: + ----- Method: WeakMessageSend>>cull:cull:cull: (in category 'evaluating') ----- + cull: firstArg cull: secondArg cull: thirdArg + "Send the message with these optional arguments and answer the return value" + + | numArgs | + (numArgs := selector numArgs) >= 2 ifTrue: [ + numArgs >= 3 ifTrue: [ ^self value: firstArg value: secondArg value: thirdArg ]. + ^self value: firstArg value: secondArg ]. + numArgs = 1 ifTrue: [ ^self value: firstArg ]. + ^self value!
Item was added: + ----- Method: WeakMessageSend>>cull:cull:cull:cull: (in category 'evaluating') ----- + cull: firstArg cull: secondArg cull: thirdArg cull: fourthArg + "Send the message with these optional arguments and answer the return value" + + | numArgs | + (numArgs := selector numArgs) >= 3 ifTrue: [ + numArgs >= 4 ifTrue: [ + ^self value: firstArg value: secondArg value: thirdArg value: fourthArg ]. + ^self value: firstArg value: secondArg value: thirdArg ]. + numArgs = 2 ifTrue: [ ^self value: firstArg value: secondArg ]. + numArgs = 1 ifTrue: [ ^self value: firstArg ]. + ^self value!
Item was added: + ----- Method: WeakMessageSend>>cull:cull:cull:cull:cull: (in category 'evaluating') ----- + cull: firstArg cull: secondArg cull: thirdArg cull: fourthArg cull: fifthArg + "Send the message with these optional arguments and answer the return value" + + ^ selector numArgs caseOf: { + [5] -> [self value: firstArg value: secondArg value: thirdArg value: fourthArg value: fifthArg]. + [4] -> [self value: firstArg value: secondArg value: thirdArg value: fourthArg]. + [3] -> [self value: firstArg value: secondArg value: thirdArg]. + [2] -> [self value: firstArg value: secondArg]. + [1] -> [self value: firstArg]. + [0] -> [self value] }!
Item was added: + ----- Method: WeakMessageSend>>numArgs (in category 'accessing') ----- + numArgs + ^ selector numArgs!
Item was added: + ----- Method: WeakMessageSend>>sendTo: (in category 'sending') ----- + sendTo: anotherReceiver + "Compatibility with Message protocol. Evaluate the receiver (i.e., weak message send) with anotherReceiver instead of the current 'receiver' instVar." + + | originalReceiver | + originalReceiver := self receiver. + ^ [self receiver: anotherReceiver. self value] + ensure: [self receiver: originalReceiver]!
Item was added: + ----- Method: WeakMessageSend>>value: (in category 'evaluating') ----- + value: firstArg + "Send the message with these arguments and answer the return value" + + ^ self valueWithArguments: {firstArg}!
Item was added: + ----- Method: WeakMessageSend>>value:value: (in category 'evaluating') ----- + value: firstArg value: secondArg + "Send the message with these arguments and answer the return value" + + ^ self valueWithArguments: {firstArg. secondArg}!
Item was added: + ----- Method: WeakMessageSend>>value:value:value: (in category 'evaluating') ----- + value: firstArg value: secondArg value: thirdArg + "Send the message with these arguments and answer the return value" + + ^ self valueWithArguments: {firstArg. secondArg. thirdArg}!
Item was added: + ----- Method: WeakMessageSend>>value:value:value:value: (in category 'evaluating') ----- + value: firstArg value: secondArg value: thirdArg value: fourthArg + "Send the message with these arguments and answer the return value" + + ^ self valueWithArguments: {firstArg. secondArg. thirdArg. fourthArg}!
Item was added: + ----- Method: WeakMessageSend>>value:value:value:value:value: (in category 'evaluating') ----- + value: firstArg value: secondArg value: thirdArg value: fourthArg value: fifthArg + "Send the message with these arguments and answer the return value" + + ^ self valueWithArguments: {firstArg. secondArg. thirdArg. fourthArg. fifthArg}!
Item was added: + ----- Method: WeakMessageSend>>valueWithPossibleArgs: (in category 'evaluating') ----- + valueWithPossibleArgs: anArray + "Send selector to the receiver with arguments in anArray. Only use enough arguments for the arity of the selector; supply nils for missing ones." + + ^self + withEnsuredReceiverDo: [ :r | + r + perform: selector + withEnoughArguments: anArray ] + otherwise: [ ]!
packages@lists.squeakfoundation.org