[squeak-dev] Re: [Pharo-project] Why does
CompiledMethod>>hasLiteral: use ==
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Tue Jul 19 17:44:27 UTC 2011
Hmm, there's the tricky edge case:
0.5s2 = 0.5s3
0.5s2 class = 0.5s3 class.
But they should be different literals.
I think there is a test case for it.
Same goes for arrays
#( 0 ) = #( 0.0 )
I think we defined a #literalEquals: or something like that to handle this
kind of cases.
Nicolas
2011/7/19 Eliot Miranda <eliot.miranda at gmail.com>
>
>
> On Mon, Jul 18, 2011 at 2:40 PM, Sean P. DeNigris <sean at clipperadams.com>wrote:
>
>> I tried:
>>
>> aMethod hasLiteral: #DateAndTime->DateAndTime
>>
>> and got false, even though an "=" literal is indeed there.
>>
>> Why doesn't #hasLiteral: use #=?
>>
>
> Well, the tricky thing with literals is that 0.0 = 0 and 'one' = #one but
> these are all different literals. That said, it looks like a bug to me. It
> should surely be
>
> !CompiledMethod methodsFor: 'literals' stamp: 'eem 7/19/2011 09:19'!
> hasLiteral: literal
> | litClass lit |
> "Answer whether the receiver references the argument, literal."
> litClass := literal class.
> 2 to: self numLiterals - 1 do: "exclude superclass + selector/properties"
> [:index |
> lit := self objectAt: index.
> (litClass == lit class and: [literal = lit]) ifTrue: [^true]].
> ^false! !
> !Array methodsFor: 'private' stamp: 'eem 7/19/2011 09:20'!
> hasLiteral: literal
> "Answer true if literal is identical to any literal in this array, even
> if imbedded in further array structure. This method is only intended
> for private use by CompiledMethod hasLiteralSymbol:"
>
> | litClass lit |
> litClass := literal class.
> 1 to: self size do:
> [:index |
> (litClass == (lit := self at: index) class
> and: [literal = lit]) ifTrue: [^true].
> (Array == lit class
> and: [lit hasLiteral: literal]) ifTrue: [^true]].
> ^false! !
>
> I've run all the tests in a trunk 4.2 before and after and making the above
> change makes no difference. So I think I'll go ahead and commit the change
> to Squeak trunk. I'll leave the Pharo folks to apply it there-in. Files
> attached.
>
>
>> Thanks.
>> Sean
>>
>> --
>> View this message in context:
>> http://forum.world.st/Why-does-CompiledMethod-hasLiteral-use-tp3676573p3676573.html
>> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>>
>>
>
>
> --
> best,
> Eliot
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20110719/78148037/attachment.htm
More information about the Squeak-dev
mailing list
|