[英]How can I dump all the source code from a Squeak Smalltalk image?
[英]How do I debug Squeak source code?
這是Squeak 4.1中的除法:
/t1
| t2 |
t1 isInteger
ifTrue: [t2 := self digitDiv: t1 abs neg: self negative ~~ t1 negative.
(t2 at: 2)
= 0
ifTrue: [^ (t2 at: 1) normalize].
^ (Fraction numerator: self denominator: t1) reduced].
^ t1 adaptToInteger: self andSend: #/
我不懂代碼。 您能否給我一些有關如何調試代碼的提示,以便我可以跟蹤代碼行為? 像打開4/3類型的工作區一樣,我可以檢查Fraction。 有對象self,分子,分母等。如何進入4/3,並查看Smalltalk如何實現除法?
首先,您的來源有問題。 方法Integer >> /實際上看起來像這樣:
/ aNumber
"Refer to the comment in Number / "
| quoRem |
aNumber isInteger ifTrue:
[quoRem := self digitDiv: aNumber abs "*****I've added abs here*****"
neg: self negative ~~ aNumber negative.
(quoRem at: 2) = 0
ifTrue: [^ (quoRem at: 1) normalize]
ifFalse: [^ (Fraction numerator: self denominator: aNumber) reduced]].
^ aNumber adaptToInteger: self andSend: #/
其次,此代碼僅用於大整數。 如果您評估4 / 3
不使用這種方法,而是SmallInteger >> /直接創建一個分數。
要調用所需的方法,您需要使用大量的方法,例如:
12345678901234567890 / 2
選擇此表達式,然后從上下文菜單中選擇“調試”。 或者,您可以使用“暫停”消息來調用調試器:
12345678901234567890 halt / 2
當調試器彈出時,單擊其“進入”按鈕以進入該方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.