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

Marcel Taeumel marcel.taeumel at hpi.de
Mon Oct 26 06:49:19 UTC 2020


Hi all!

Can we merge this into Trunk?

(Also see a discussion here: http://forum.world.st/Debugger-Simulator-cannot-simulate-some-objects-as-methods-td5123791.html)

Best,
Marcel
Am 04.09.2020 21:09:30 schrieb commits at source.squeak.org <commits at source.squeak.org>:
A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-ct.1339.mcz

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

Name: Kernel-ct.1339
Author: ct
Time: 4 September 2020, 9:09:14.713421 pm
UUID: edc35a82-ce03-014c-85de-13d68c7fc46f
Ancestors: Kernel-ct.1338

Implement missing simulation of objects as methods.

In the past, it was not possible to debug/simulate code that used objects as methods properly. (Thanks to Marcel for the hint!) This very simple commit adds support of the OaM protocol [1] to the simulation machinery. Now you can debug all tests in TestObjectsAsMethods as you would expect, instead of crashing your image!

Update: Uploaded again, this time with additional documentation comment, reformatted code, and multilingual support/fix of typös. Replaces Kernel-ct.1306, which can be moved to the treated inbox.

[1] "The [Objects as Methods] 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.

=============== Diff against Kernel-ct.1338 ===============

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."
- "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 primIndex val ctxt |
+ (meth := lookupClass lookupSelector: selector) ifNil: [
+ ^ self
+ send: #doesNotUnderstand:
+ to: rcvr
+ with: {(Message selector: selector arguments: arguments) lookupClass: lookupClass}
+ lookupIn: lookupClass].
+
+ meth isCompiledMethod 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 ifTrue: [
+ ^ 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]].
+
+ (selector == #doesNotUnderstand: and: [lookupClass == ProtoObject]) ifTrue: [
+ ^ self error: ('Simulated message {1} not understood' translated format: {arguments first selector})].
+
- (meth := lookupClass lookupSelector: selector) ifNil:
- [^self send: #doesNotUnderstand:
- to: rcvr
- with: {(Message selector: selector arguments: arguments) lookupClass: lookupClass}
- lookupIn: lookupClass].
- meth numArgs ~= arguments size ifTrue:
- [^self error: 'Wrong number of arguments in simulated message ', selector printString].
- (primIndex := meth primitive) > 0 ifTrue:
- [val := self doPrimitive: primIndex method: meth receiver: rcvr args: arguments.
- (self isPrimFailToken: val) ifFalse:
- [^val]].
- (selector == #doesNotUnderstand: and: [lookupClass == ProtoObject]) ifTrue:
- [^self error: 'Simulated message ', arguments first selector, ' not understood'].
ctxt := Context sender: self receiver: rcvr method: meth arguments: arguments.
+ (primIndex notNil and: [primIndex > 0]) ifTrue: [
+ ctxt failPrimitiveWith: val].
+
+ ^ ctxt!
- primIndex > 0 ifTrue:
- [ctxt failPrimitiveWith: val].
- ^ctxt!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20201026/76da3d97/attachment.html>


More information about the Squeak-dev mailing list