我知道一切都是一个对象,你向Smalltalk中的对象发送消息来做几乎所有事情.现在我们如何实现一个对象(内存表示和基本操作)来表示原始数据类型?例如,如何+实现整数?
我查看了Smalltalk的源代码并发现了这一点Smallint.st.有人可以解释这段代码吗?
+ arg [
"Sum the receiver and arg and answer another Number"
<category: 'built ins'>
<primitive: VMpr_SmallInteger_plus>
^self generality == arg generality
ifFalse: [self retrySumCoercing: arg]
ifTrue: [(LargeInteger fromInteger: self) + (LargeInteger fromInteger: arg)]
]
Run Code Online (Sandbox Code Playgroud)
以下是上述代码的链接:https://github.com/gnu-smalltalk/smalltalk/blob/62dab58e5231909c7286f1e61e26c9f503b2b3df/kernel/SmallInt.st