["BUG"][FIX?]Incorrect Pseudo-Codefor#whileTrue:/#whileFalse:?

Bob Arning arning at charm.net
Sun Jan 7 03:40:34 UTC 2001


Hi Mark,

On Sat, 06 Jan 2001 16:47:21 -0600 Mark van Gulik <ghoul6 at home.net> wrote:
>> !BlockContext methodsFor: 'controlling' stamp: 'RAA 1/5/2001 23:10'!
>> repeatEndlessly
>> | loopAgain |
>> "Evaluate the receiver repeatedly, ending only if the block explicitly
>> returns."
>> 
>> loopAgain _ thisContext pc.
>> self value.
>> thisContext jumpTo: loopAgain stack: 1.
>> self halt.
>> ! !
>
>That's interesting, I was intially worried about the stack depths not
>corresponding too.  On a guess I'd say it failed some time around the 12th
>iteration (from my recollection of the short context size).  Did you ever
>crash the VM with such a test?  

Nope, although some of the walkbacks looked rather odd.

>Anyhow, this is fixed by using #realPc
>above.  Then the call site to #realPc is expecting one value on the stack,
>which matches the call site to #jumpTo:.

Thanks for explaining that. I did this without examining exactly what tricks the compiler/VM were using (I wasn't up for the headaches). I just tried things that ought to work and threw away those that didn't.

>> loopAgain _ thisContext pc + 5.    "5 is the size of the bytecodes for this
>
>Hm, that was a bit kludgy.

Yep, that was a performance tweak that your #realPC handles much better.

>
>> !BlockContext methodsFor: 'controlling' stamp: 'RAA 1/4/2001 10:21'!
>> whileTrue4: aBlock
>> 
>> "
>> | x |
>> x _ 0.
>> [(x _ x + 1) < 100] whileTrue4: [Transcript show: x printString; cr].
>> "
>> [
>> self value ifFalse: [^self].
>> aBlock value.
>> ] repeatEndlessly
>> ! !
>
>This is the cleanest implementation.  My vote is to add special compiler
>support for #repeatEndlessly (VisualWorks calls it #repeat), and have
>special compiler support for it.  Then the #whileTrue: operations don't need
>to have bodies that look recursive.  Instead, they can appear to invoke
>#repeatEndlessly (but really be implemented with branch bytecodes because of
>the way #repeatEndlessly is handled by the compiler).  The implementation of
>#repeatEndlessly can use #restart or whatever, as it only makes a
>performance difference if you send a non-literal block the #repeatEndlessly
>message (which is very easy to avoid).

My vote, too, if we decide this is broken enough to warrant fixing. WRT #repeatEndlessly, I picked that since #repeat was already used and relies on, guess what?, #whileTrue. If this change is accepted, then we could use either or pick something else.

Cheers,
Bob





More information about the Squeak-dev mailing list