logo       

Re: Re: Adding methods to Integers...: msg#00101

lang.smalltalk.squeak.beginners

Subject: Re: Re: Adding methods to Integers...


On Apr 13, 2007, at 13:27 , Klaus D. Witzel wrote:

Hi Bert,

on Thu, 12 Apr 2007 18:31:55 +0200, you wrote:

This is actually wrong.

:)

Only SmallIntegers are special [*].

What happens is this: When you add two SmallIntegers (like "3 + 4"), and the result is a SmallInteger, the result is calculated in the bytecode directly. Otherwise, a regular send of #+ is performed.

Right.

From there, everything else happens in the image,

Not really. (Integer>>#+ aNumber) sends (self digitAdd: aNumber) which is implemented as <primitive: 'primDigitAdd' module: 'LargeIntegers'> which is part of the VM. Of course the LargeIntegers module may be absent, have failed to load, may not like the argument, etc.

No, this is an *optional* primitive. It's there purely to speed up computation and can be safely removed.

You could change the Integer classes to handle subclasses properly (via species etc.). So far, this has not been necessary. My point was that this (unlike SmallIntegers) is *not* hard-coded in the VM.

- Bert -


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise