[squeak-dev] The Inbox: Kernel-ct.1451.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Mar 25 17:47:43 UTC 2022


A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1451.mcz

==================== Summary ====================

Name: Kernel-ct.1451
Author: ct
Time: 25 March 2022, 6:47:25.617514 pm
UUID: 94732d1b-58e4-9f4b-a1b3-c950af711c77
Ancestors: Kernel-nice.1447

Revises fallback code for primitive 188 (primitiveExecuteMethodArgsArray) in Object>>#withArgs:executeMethod: and eliminates any side-effects to the method dictionary. This also adds support for Objects as Methods (OaM) in this place. To achieve this, extract and reuse the simulation of method execution from Context>>#send:to:with:lookupIn:.

Thanks to Eliot for the idea! This is the next iteration of Kernel-ct.1449 (inbox). The second part of that version (arity checks in sim of primitivePerform[WithArgs]) still remains relevant, though.

=============== Diff against Kernel-nice.1447 ===============

Item was added:
+ ----- Method: Context>>executeMethod:forSelector:withArgs:receiver: (in category 'controlling') -----
+ executeMethod: meth forSelector: selector withArgs: arguments receiver: rcvr
+ 
+ 	| primIndex val ctxt |
+ 	(self objectClass: meth) isCompiledCodeClass ifFalse:
+ 		["Object as Methods (OaM) protocol: 'The contract is that, when the VM encounters an ordinary object (rather than a compiled method) in the method dictionary during lookup, it sends it the special selector #run:with:in: providing the original selector, arguments, and receiver.'. DOI: 10.1145/2991041.2991062."
+ 		^self send: #run:with:in:
+ 			to: meth
+ 			with: {selector. arguments. rcvr}].
+ 	
+ 	meth numArgs = arguments size ifFalse:
+ 		[^ self error: ('Wrong number of arguments in simulated method {1}' translated format: {meth})].
+ 	(primIndex := meth primitive) > 0 ifTrue:
+ 		[val := self doPrimitive: primIndex method: meth receiver: rcvr args: arguments.
+ 		(self isPrimFailToken: val) ifFalse:
+ 			[^val]].
+ 	
+ 	ctxt := self activateMethod: meth withArgs: arguments receiver: rcvr.
+ 	(primIndex isInteger and: [primIndex > 0]) ifTrue:
+ 		[ctxt failPrimitiveWith: val].
+ 	
+ 	^ctxt!

Item was changed:
  ----- Method: Context>>send:to:with:lookupIn: (in category 'controlling') -----
  send: selector to: rcvr with: arguments lookupIn: lookupClass
  	"Simulate the action of sending a message with selector and arguments to rcvr. The argument, lookupClass, is the class in which to lookup the message. This is the receiver's class for normal messages, but for super messages it will be some specific class related to the source method."
  
+ 	| meth |
- 	| meth primIndex val ctxt |
  	(meth := lookupClass lookupSelector: selector) ifNil:
  		[selector == #doesNotUnderstand: ifTrue:
  			[self error: 'Recursive message not understood!!' translated].
  		^self send: #doesNotUnderstand:
  				to: rcvr
  				with: {(Message selector: selector arguments: arguments) lookupClass: lookupClass}
  				lookupIn: lookupClass].
  	
+ 	^ self
+ 		executeMethod: meth
+ 		forSelector: selector
+ 		withArgs: arguments
+ 		receiver: rcvr!
- 	(self objectClass: meth) isCompiledCodeClass ifFalse:
- 		["Object as Methods (OaM) protocol: 'The contract is that, when the VM encounters an ordinary object (rather than a compiled method) in the method dictionary during lookup, it sends it the special selector #run:with:in: providing the original selector, arguments, and receiver.'. DOI: 10.1145/2991041.2991062."
- 		^self send: #run:with:in:
- 			to: meth
- 			with: {selector. arguments. rcvr}].
- 	
- 	meth numArgs = arguments size ifFalse:
- 		[^ self error: ('Wrong number of arguments in simulated message {1}' translated format: {selector})].
- 	(primIndex := meth primitive) > 0 ifTrue:
- 		[val := self doPrimitive: primIndex method: meth receiver: rcvr args: arguments.
- 		(self isPrimFailToken: val) ifFalse:
- 			[^val]].
- 	
- 	ctxt := self activateMethod: meth withArgs: arguments receiver: rcvr.
- 	(primIndex isInteger and: [primIndex > 0]) ifTrue:
- 		[ctxt failPrimitiveWith: val].
- 	
- 	^ctxt!

Item was changed:
  ----- Method: Object>>withArgs:executeMethod: (in category 'message handling') -----
  withArgs: argArray executeMethod: compiledMethod
  	"Execute compiledMethod against the receiver and args in argArray"
  
+ 	| context |
- 	| selector |
  	<primitive: 188>
+ 	context := thisContext
+ 		executeMethod: compiledMethod
+ 		forSelector: Symbol new
+ 		withArgs: argArray
+ 		receiver: self.
+ 	^ context == thisContext
+ 		ifTrue: ["quick return" thisContext top]
+ 		ifFalse: [context jump]!
- 	selector := Symbol new.
- 	self class addSelectorSilently: selector withMethod: compiledMethod.
- 	^ [self perform: selector withArguments: argArray]
- 		ensure: [self class basicRemoveSelector: selector]!



More information about the Squeak-dev mailing list