[Squeak-fr] Relecture document sur la syntaxe Smalltalk
Bernard Pottier
pottier at univ-brest.fr
Dim 19 Fév 11:53:51 UTC 2006
stéphane ducasse a écrit :
> Exact
> Je pense (mais c'est une hypothese) qu'en sqeuak le code n'est jamais
> execute.
> J'ai demande dans la mailing-list.
> Il faudrait que je regarde le compilation mais je n'ai pas le temps
> de vraiment plonger dedans
>
> Stef
> On 19 févr. 06, at 11:27, Loïs Lherbier wrote:
>
>> Merci bien.
>> Je trouve le commentaire qui explique comment le compilateur
>> optimise le
>> code trés intérressant (et cela explique aussi le commentaire dans le
>> code de Squeak). Moi qui trouvait justement que la définition récursive
>> du whileTrue était un peu barbare :)
>> Mais cela ne m'explique toujours pas l'implémentation du whileTrue dans
>> Squeak ?
>>
>> Loïs
>>
>>
>> Le dimanche 19 février 2006 à 10:08 +0100, stéphane ducasse a écrit :
>>
>>> en VisualWorks
>>>
>>> ils ont la definition suivante
>>>
>>>
>>>
>>>
>>> whileTrue: aBlock
>>> "Evaluate the argument, aBlock, as long as the value
>>> of the receiver is true."
>>>
>>> ^self value
>>> ifTrue:
>>> [aBlock value.
>>> [self value] whileTrue: [aBlock value]]
>>>
>>> "This method is inlined if both the receiver and the argument are
>>> literal
>>> blocks. In all other cases, the code above is run. Note that
>>> the code
>>> above is defined recursively. However, to avoid actually
>>> building an
>>> activation record each time this method is invoked recursively,
>>> we have
>>> used the '[...] whileTrue: [..]' form in the last line, rather than
>>> the more
>>> concise 'self whileTrue: aBlock'. Using literal blocks for both the
>>> receiver
>>> and the argument allows the compiler to inline #whileTrue:, which
>>> (in the
>>> absence of type inferencing) could not be done if we were to use
>>> 'self whileTrue: aBlock'."
>>> _______________________________________________
>>> Squeak-fr mailing list
>>> Squeak-fr at lists.squeakfoundation.org
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-fr
>>
>>
>> _______________________________________________
>> Squeak-fr mailing list
>> Squeak-fr at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-fr
>
>
> _______________________________________________
> Squeak-fr mailing list
> Squeak-fr at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-fr
>
>
> .
>
Les while, to:do: sont interceptés par le compilateur et traduits en sauts
tout a fait classiques par le compilateur.
Comment on retrouve une méthode compilée dans une classe (VW):
> Trucx methodDictionary at: #ahaha
Méthode de Trucx:
> ahaha
> | x |
> x := 10.
> [x = 0] whileFalse:
> [x := x - 1.
> x = 5 ifTrue: [x := x - 2]].
> ^x
Code désassemblé montrant la structure séquentielle:
> normal CompiledMethod numArgs=0 numTemps=1 frameSize=12
>
> literals: ()
>
> 1 <D8 0A> push 10
> 3 <4C> store local 0; pop
> 4 <67> loop head
> 5 <10> push local 0
> 6 <49> push 0
> 7 <A6> send =
> 8 <EC 0F> jump true 25
> 10 <10> push local 0
> 11 <4A> push 1
> 12 <A1> send -
> 13 <4C> store local 0; pop
> 14 <10> push local 0
> 15 <D8 05> push 5
> 17 <A6> send =
> 18 <C3> jump false 23
> 19 <10> push local 0
> 20 <4B> push 2
> 21 <A1> send -
> 22 <4C> store local 0; pop
> 23 <E3 EB> jump 4
> 25 <10> push local 0
> 26 <65> return
======================== b.
>
>
> _______________________________________________
> Squeak-fr mailing list
> Squeak-fr at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-fr
>
>
> .
>
More information about the Squeak-fr
mailing list