|
Re: Adding methods to Integers...: msg#00100lang.smalltalk.squeak.beginners
Hi Bert, on Thu, 12 Apr 2007 18:31:55 +0200, you wrote: This is actually wrong. :) Only SmallIntegers are special [*]. 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. Only if (LargeIntegers>>#primDigitAdd: secondInteger) fails [whatever the reason, must not have anything to do with arithmetics] then "everything else" may happen in the image. Back to the situation I had in mind (assuming MyPositiveInteger is a subclass of LargePositiveInteger): | x y | x := LargePositiveInteger initializedInstance. y := (MyPositiveInteger basicNew: x basicSize) replaceFrom: 1 to: x basicSize with: x startingAt: 1. (1 + y) class => LargePositiveInteger But not: (y + 1) class => MyPositiveInteger See, associativity at work ;-) I have not checked whether the LargeIntegers module really does not like the argument (would seem plausible but it looks like it all relies on the #isInteger check in Integer>>#+, since from there on it "normally" is a SmallInteger or a #variableByteSubclass:). including conversion to LargeIntegers - see implementors of #+. Like, if the receiver was a SmallInteger, it tries the "add" primitive, which fails, and then the implementation of #+ in class Integer is invoked. This method then creates a large integer. It looks like in the (1 + y) case the LargeIntegers module creates the large integer. A simple test would be, to subclass ByteArray and have that respond true for #isInteger when used as argument in Integer>>#+ (but I haven't tried that). For the implementation of all this see #bytecodePrimAdd and #primitiveAdd. You may have to load VMMaker first. Sure, almost always have loaded that ;-) /Klaus - Bert -
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Re: Squeak Firefox plugin on Linux, Bert Freudenberg |
|---|---|
| Next by Date: | Re: Re: Adding methods to Integers..., Bert Freudenberg |
| Previous by Thread: | Re: Re: Adding methods to Integers..., Bert Freudenberg |
| Next by Thread: | Re: Re: Adding methods to Integers..., Bert Freudenberg |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |