[squeak-dev] printing literals exactly (was isSelfEvaluating)

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Sat Oct 31 17:09:41 UTC 2009


2009/10/31 Eliot Miranda <eliot.miranda at gmail.com>:
>
>
> On Sat, Oct 31, 2009 at 8:55 AM, Nicolas Cellier
> <nicolas.cellier.aka.nice at gmail.com> wrote:
>>
>> 2009/10/31 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
>> > 2009/10/31 Stéphane Rollandin <lecteur at zogotounga.net>:
>> >>>> If the meaning of #isLiteral is to indicate that what is printed can
>> >>>> be
>> >>>> read back (i.e. will be correctly parsed) then I think it is a very
>> >>>> useful
>> >>>> message that we should keep.
>> >>>
>> >>> #isLiteral mainly indicates which objects can be created at compile
>> >>> time.
>> >>> They are literally inserted in the compiled method. This must match
>> >>> the
>> >>> syntax definition of Squeak. There is no question about not keeping
>> >>> it.
>> >>
>> >> now I'm confused. are all objects anwering true to #isLiteral also have
>> >> a
>> >> printed form that can be read back ? should they ?
>> >>
>> >> Stef
>> >>
>> >
>> > I think this is used as a feature at least in Decompiler.
>> >
>> > But can they all be read back ?
>> > Float can't always with the current implementation (they don't print
>> > exactly).
>> >
>> > (Compiler evaluate: Float halfPi printString) = Float halfPi
>> >
>> > Nicolas
>> >
>>
>> By the way, there is a workaround in CompiledMethod>>#=
>>
>> self isFloat ifTrue: [...]
>>
>> The #halt: in there sounds like calling for a better fix.
>> For example, the workaround does not work with a literal Array of Float...
>
> Right.  It doesn't deal with NaNs either.  But it was good enough for my
> needs (checking that modifications to the compiler did or did not produce
> different compiled methods).  I could live with the false positive of Float
> class>>initialize.  One thing that could work here is to extend
> analogousCodeTo: to literals and then use it.  For Float it could compare
> the bit patterns except for NaN, and arrange that NaNs compare as equal, or
> it could compare the bit patterns so that different NaNs compare
> differently.  I suspect that comparing NaNs as equal is the right thing to
> do.  As far as execution goes one NaN should be as good as another right?

Hi Eliot,

NaNs are not valid literals anyway, so we should not bother too much.
Since http://bugs.squeak.org/view.php?id=6983 Float nan isLiteral -> false.

Well, there is a way to produce a NaN literal, but that is a bug!
See http://bugs.squeak.org/view.php?id=6982
It will go away when using SqNumberParser.

Nicolas


>>
>> Nor does it deal with infinity:
>> (Float class compile: (Float class >> #initialize) decompileString
>>                classified: nil
>>                notifying: requestor
>>                trailer: Float class defaultMethodTrailer
>>                ifFail: [^nil]) method = (Float class >> #initialize)
>>
>> We have an excellent absPrintExactlyOn:base: that avoids extra digits
>> when unnecessary...
>> ...but it is 3x to 10x slower and nobody dared generalizing its usage.
>>
>> {0.0. Float pi. Float pi   * 1.0e200. Float pi   * 1.0e-200 . 10.0 .
>> 0.1 . 237.128} collect: [:e |
>>        [String streamContents: [:s | e absPrintExactlyOn: s base: 10]]
>> bench
>>        ->[String streamContents: [:s | e printOn: s base: 10]] bench]
>>
>> {'12131.77364527095 per second.'->'63358.65653738505 per second.'.
>> '1535.292941411718 per second.'->'6756.64867026595 per second.'.
>> '653.669266146771 per second.'->'6667.066586682664 per second.'.
>> '1004.199160167966 per second.'->'5857.82843431314 per second.'.
>> '8732.85342931414 per second.'->'26025.3949210158 per second.'.
>> '8635.87282543491 per second.'->'19715.45690861827 per second.'.
>> '2666.26674665067 per second.'->'13040.99180163967 per second.'}
>>
>> Nicolas
>>
>
>
>
>
>



More information about the Squeak-dev mailing list