Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uhog.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Impementation of WhileTrue: ?
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <D9r232.K89@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <3r0gfu$knr@crl3.crl.com> <3r148l$12g6@zen.hursley.ibm.com>
Date: Tue, 6 Jun 1995 11:47:26 GMT
Lines: 32

In article <3r148l$12g6@zen.hursley.ibm.com>,  <Paul_Gover@uk.ibm.com> wrote:
>In <3r0gfu$knr@crl3.crl.com>, mtsuzuki@crl.com (Michael Suzuki) writes:
>  
>>...
>>I'm having a bit of a problem understanding Digitalk's current implementation
>>of WhileTrue:.  
>
>Don't believe everything you read (including this statement, of course :-).
>Smalltalk compilers cheat on some methods for improved performance,
>particularly the control constructions (ifTrue: whileTrue: and so forth).
>The source code is dummy, to satisfy the curious.

The source code for this method isn't actually dummy.  You are quite
correct that the compiler cheats on this (and other) methods by
directly compiling them into the bytecodes. The actual Smalltalk
method, however, will be invoked if you ever run it with a perform,
eg:

   [i<10] perform: #whileTrue: with: [i := i + 1]

In this case, the implementation works as advertised.  The perform
calls the real whileTrue: method which in turn inlines the call to
whileTrue: to make it work.

David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|
