Nik*_*iki 4 smalltalk compilation pharo
打开一个新的Pharo 5图像,打开Finder并搜索+选择器.然后选择+并单击发件人.得到了大约5000个结果,其中大多数似乎都很好,但是经过仔细检查后,一些结果似乎缺少我的消息发送的任何参考.
我可能会补充一点,其中约有1700个似乎是错误的,并且没有任何参考.您认为这个问题是什么?这是一个例子:
搜索通过文本源代码和字节码进行; 所以它显示了方法,因为它#+在字节码中找到,但是浏览器太有限了,无法显示文本和字节,所以它只显示文本(即使匹配是在字节码上完成的)
至于字节码本身,Pharo(重新)每次保存时都会编译一个方法; 例如,当您保存以下方法时
Something>>loop
1 to: 10 do: [ :each | ]
Run Code Online (Sandbox Code Playgroud)
系统会编译它,当你检查方法并查看字节码时,你会看到这一点
我相信你也可以手工编写字节码.
因为对于某些特殊选择器,它还会查看字节码,您可以在检查方法本身时看到该字节码.
通过查看Pharo本身的代码(一旦你对Pharo更熟悉),可以在不到一分钟的时间内轻松发现这一点:
#+ senders 为您提供选择器的发件人列表,senders并通过可用的调用链(你可以用鼠标选择选择器或双击和ctrl + n来显示发件人浏览器)
senders→交通allSendersOf:→交通thoroughWhichSelectorsReferTo:.
thoroughWhichSelectorsReferTo: literal
"Answer a set of selectors whose methods access the argument as a
literal. Dives into the compact literal notation, making it slow but
thorough "
| selectors special byte |
"for speed we check the special selectors here once per class"
special := Smalltalk
hasSpecialSelector: literal
ifTrueSetByte: [ :value | byte := value ].
selectors := OrderedCollection new.
self selectorsAndMethodsDo: [ :sel :method |
((method refersToLiteral: literal) or: [special and: [method scanFor: byte]]) ifTrue: [selectors add: sel]].
^ selectors
Run Code Online (Sandbox Code Playgroud)