[squeak-dev] New Window VM (Closures, FT2Plugin, Large Cursors)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
42 messages Options
123
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] New Window VM (Closures, FT2Plugin, Large Cursors)

Andreas.Raab
Folks -

Since I was in VM building mode today I figured I might as well make a
new Squeak VM. There is some interesting new stuff in it:

* Closure support. This VM is based on VMMaker-dtl.116 meaning it
includes support for the closure bytecodes. I have verified it by both
running a Qwaq image on this VM and and a converted closure image on our
Stack VM (this is useful since the Stack VM will die a horrible death
something goes wrong in the process). It worked fine both ways which
means that I no longer need to switch VMs (yay! ;-)

* Experimental large cursor support. Try the following for fun (but
don't do it in an image you care about):

        cursor := Cursor extent: 128@128 depth: 32.
        cursor offset: -64@-64.
        cursor getCanvas
                fillOval: cursor boundingBox color: (Color white alpha: 0.1);
                frameOval: cursor boundingBox width: 4 color: Color red;
                line: 62@64 to: 66@64 width: 1 color: Color blue;
                line: 64@62 to: 64@66 width: 1 color: Color blue.
        Cursor classPool at: #NormalCursor put: cursor.

This changes your normal cursor to be a 128x128 pixels large,
translucent cursor.

* FT2Plugin. The build includes an external FT2Plugin that has no
dependencies on extra DLLs.

The downloads are in the usual places:
http://squeakvm.org/win32/release/SqueakVM-Win32-3.11.1-bin.zip
http://squeakvm.org/win32/release/SqueakVM-Win32-3.11.1-src.zip

A closure image (for those interested):
http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip

Note that I consider this an "alpha" version since there is a goodly bit
of new and untested stuff in it. I'm in particular interested in finding
people to test large cursor support and the FT2Plugin.

Feedback is highly welcome.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Klaus D. Witzel
On Sat, 07 Mar 2009 08:38:32 +0100, Andreas Raab wrote:

> Folks -
>
> Since I was in VM building mode today I figured I might as well make a  
> new Squeak VM.

Hey, great :) thank you.

...

> The downloads are in the usual places:
> http://squeakvm.org/win32/release/SqueakVM-Win32-3.11.1-bin.zip

This VM also opens and runs Squeak3.10.2-7179-basic.image :) and fonts [I  
have some exotic fonts in use] are rendered fine :)

> http://squeakvm.org/win32/release/SqueakVM-Win32-3.11.1-src.zip
>
> A closure image (for those interested):
> http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip
>
> Note that I consider this an "alpha" version since there is a goodly bit  
> of new and untested stuff in it. I'm in particular interested in finding  
> people to test large cursor support and the FT2Plugin.
>
> Feedback is highly welcome.

I can't see why but the 3.11.1 VM refuses to open  
Squeak-3.10.2-Closures.image :( windoze (vista) pops up a small window  
with Squeak! in title bar and message text "Could not open image file".  
FWIW the .image file has 15.367 KB.

> Cheers,
>    - Andreas

Thanks again !

--
"If at first, the idea is not absurd, then there is no hope for it".  
Albert Einstein


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: [Vm-dev] New Window VM (Closures, FT2Plugin, Large Cursors)

Bert Freudenberg
In reply to this post by Andreas.Raab
On 07.03.2009, at 08:38, Andreas Raab wrote:

> Folks -
>
> Since I was in VM building mode today I figured I might as well make  
> a new Squeak VM. There is some interesting new stuff in it:
>
> * Closure support. This VM is based on VMMaker-dtl.116 meaning it  
> includes support for the closure bytecodes. I have verified it by  
> both running a Qwaq image on this VM and and a converted closure  
> image on our Stack VM (this is useful since the Stack VM will die a  
> horrible death something goes wrong in the process). It worked fine  
> both ways which means that I no longer need to switch VMs (yay! ;-)

John bumped the Mac VM's major version to 4 to signify closure  
support. Maybe the other platforms should follow suit?

> * Experimental large cursor support. Try the following for fun (but  
> don't do it in an image you care about):
>
> cursor := Cursor extent: 128@128 depth: 32.
> cursor offset: -64@-64.
> cursor getCanvas
> fillOval: cursor boundingBox color: (Color white alpha: 0.1);
> frameOval: cursor boundingBox width: 4 color: Color red;
> line: 62@64 to: 66@64 width: 1 color: Color blue;
> line: 64@62 to: 64@66 width: 1 color: Color blue.
> Cursor classPool at: #NormalCursor put: cursor.
>
> This changes your normal cursor to be a 128x128 pixels large,  
> translucent cursor.

Nice. Looks like it's time to add the image support? These changesets  
add a CursorWithAlpha that can be used for nice large colorful  
cursors. It has a "fallback" cursor used on VMs that do not support  
the new cursors yet.

http://tinlizzie.org/updates/olpc/updates/1252biggerCursors-bf.cs
http://tinlizzie.org/updates/olpc/updates/1260bigCursorFix-bf.cs
http://tinlizzie.org/updates/olpc/updates/1282bigTempCursor-bf.cs

- Bert -

> * FT2Plugin. The build includes an external FT2Plugin that has no  
> dependencies on extra DLLs.
>
> The downloads are in the usual places:
> http://squeakvm.org/win32/release/SqueakVM-Win32-3.11.1-bin.zip
> http://squeakvm.org/win32/release/SqueakVM-Win32-3.11.1-src.zip
>
> A closure image (for those interested):
> http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip
>
> Note that I consider this an "alpha" version since there is a goodly  
> bit of new and untested stuff in it. I'm in particular interested in  
> finding people to test large cursor support and the FT2Plugin.
>
> Feedback is highly welcome.
>
> Cheers,
>  - Andreas




Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: [Vm-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Andreas.Raab
In reply to this post by Klaus D. Witzel
Klaus D. Witzel wrote:

>> A closure image (for those interested):
>> http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip
>>
>> Note that I consider this an "alpha" version since there is a goodly
>> bit of new and untested stuff in it. I'm in particular interested in
>> finding people to test large cursor support and the FT2Plugin.
>>
>> Feedback is highly welcome.
>
> I can't see why but the 3.11.1 VM refuses to open
> Squeak-3.10.2-Closures.image :( windoze (vista) pops up a small window
> with Squeak! in title bar and message text "Could not open image file".
> FWIW the .image file has 15.367 KB.

That's very odd. I just tried a clean download and it works fine for me
here. The image size should be 15,735,052 bytes. Can you download the
image again and see if you still have that problem? Can someone else
confirm or deny whether that image works for them?

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: [Vm-dev] New Window VM (Closures, FT2Plugin, Large Cursors)

Andreas.Raab
In reply to this post by Bert Freudenberg
Bert Freudenberg wrote:
> John bumped the Mac VM's major version to 4 to signify closure support.
> Maybe the other platforms should follow suit?

I figured v4 would signify the Stack VM or later as this VM will no
longer be able to run v3 images. The current set of VMs are fully
backwards compatible so I consider them logically to be v3 VMs.

But I'm willing to reconsider if people prefer the v4 terminology.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Klaus D. Witzel
In reply to this post by Andreas.Raab
On Sat, 07 Mar 2009 17:10:13 +0100, Andreas Raab wrote:

> Klaus D. Witzel wrote:
>>> A closure image (for those interested):
>>> http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip
>>>
>>> Note that I consider this an "alpha" version since there is a goodly  
>>> bit of new and untested stuff in it. I'm in particular interested in  
>>> finding people to test large cursor support and the FT2Plugin.
>>>
>>> Feedback is highly welcome.
>>  I can't see why but the 3.11.1 VM refuses to open  
>> Squeak-3.10.2-Closures.image :( windoze (vista) pops up a small window  
>> with Squeak! in title bar and message text "Could not open image file".  
>> FWIW the .image file has 15.367 KB.
>
> That's very odd. I just tried a clean download and it works fine for me  
> here. The image size should be 15,735,052 bytes. Can you download the  
> image again and see if you still have that problem?

Did that, now it opens and shows "This is a closure-converted image. You  
will not be able to run this image with pre-3.11 VMs. etc" thanks again.

> Can someone else confirm or deny whether that image works for them?
>
> Cheers,
>    - Andreas

--
"If at first, the idea is not absurd, then there is no hope for it".  
Albert Einstein


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Eliot Miranda-2
Hi Klaus,

On Sat, Mar 7, 2009 at 8:54 AM, Klaus D. Witzel <[hidden email]> wrote:
On Sat, 07 Mar 2009 17:10:13 +0100, Andreas Raab wrote:

Klaus D. Witzel wrote:
A closure image (for those interested):
http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip

Note that I consider this an "alpha" version since there is a goodly bit of new and untested stuff in it. I'm in particular interested in finding people to test large cursor support and the FT2Plugin.

Feedback is highly welcome.
 I can't see why but the 3.11.1 VM refuses to open Squeak-3.10.2-Closures.image :( windoze (vista) pops up a small window with Squeak! in title bar and message text "Could not open image file". FWIW the .image file has 15.367 KB.

That's very odd. I just tried a clean download and it works fine for me here. The image size should be 15,735,052 bytes. Can you download the image again and see if you still have that problem?

Did that, now it opens and shows "This is a closure-converted image. You will not be able to run this image with pre-3.11 VMs. etc" thanks again.

You'll probably notice some oddities with the debugger as that change set is a little out of date and is missing some fixes I've made since we've put closures to everyday use at Qwaq.  I'll try and update the closure bootstrap change set real soon now.



Can someone else confirm or deny whether that image works for them?

Cheers,
  - Andreas

--
"If at first, the idea is not absurd, then there is no hope for it". Albert Einstein





Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: [Vm-dev] New Window VM (Closures, FT2Plugin, Large Cursors)

johnmci
In reply to this post by Andreas.Raab
Ah, I have a bias opinion for an answer, but I'll not discuss that here.

However the BIG issue for the 3.8.x and earlier series of macintosh  
carbon VM is their behaviour for opening a closure image.
What you will find is that if you attempt to open a closure image the  
squeak.app will start then terminate
It will print a diagnostic message to the console which you can see  
via Apple's Console.app found in Applications/Utilities.

07/03/09 11:11:51 AM [0x0-0x8d08d].org.squeak.Squeak[1894] This  
interpreter (vers. 6502) cannot read image file (vers. 6504).
07/03/09 11:11:51 AM [0x0-0x8d08d].org.squeak.Squeak[1894] Press CR to  
quit...

The reason for this behaviour is that 15 some years back John Maloney  
coded up the version checking logic and  there was a question
what to do now. At the time CodeWarrior under os-7.5.x would helpfully  
put up a dialog window if you printed to the *console* and did
a getchar for the answer, that code has moved forward for years now  
and no-one really has tested until now.

Interestingly the getchar on os-x does not block and returns null and  
we terminate the VM, but the behaviour is confusing if you don't
understand what is going on.

I will at some point push out a 3.8.22 VM that should put up a more  
helpful dialog message, but people who have older VMs underfoot
should realize this behaviour should be an indication that perhaps  
your VM is too old.


On 7-Mar-09, at 8:12 AM, Andreas Raab wrote:

> Bert Freudenberg wrote:
>> John bumped the Mac VM's major version to 4 to signify closure  
>> support. Maybe the other platforms should follow suit?
>
> I figured v4 would signify the Stack VM or later as this VM will no  
> longer be able to run v3 images. The current set of VMs are fully  
> backwards compatible so I consider them logically to be v3 VMs.
>
> But I'm willing to reconsider if people prefer the v4 terminology.
>
> Cheers,
>  - Andreas

--
=
=
=
========================================================================
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
=
=
=
========================================================================




Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Klaus D. Witzel
In reply to this post by Eliot Miranda-2
On Sat, 07 Mar 2009 18:51:01 +0100, Eliot Miranda wrote:

> Hi Klaus,

Hi Eliot,

great job, native closures-support was overdue and is appreciated by the  
Squeakers.

> On Sat, Mar 7, 2009 at 8:54 AM, Klaus D. Witzel wrote:
>
>> On Sat, 07 Mar 2009 17:10:13 +0100, Andreas Raab wrote:
>>
>>  Klaus D. Witzel wrote:
>>>
>>>> A closure image (for those interested):
>>>>> http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip
>>>>>
>>>>> Note that I consider this an "alpha" version since there is a goodly  
>>>>> bit
>>>>> of new and untested stuff in it. I'm in particular interested in  
>>>>> finding
>>>>> people to test large cursor support and the FT2Plugin.
>>>>>
>>>>> Feedback is highly welcome.
>>>>>
>>>>  I can't see why but the 3.11.1 VM refuses to open
>>>> Squeak-3.10.2-Closures.image :( windoze (vista) pops up a small  
>>>> window with
>>>> Squeak! in title bar and message text "Could not open image file".  
>>>> FWIW the
>>>> .image file has 15.367 KB.
>>>>
>>>
>>> That's very odd. I just tried a clean download and it works fine for me
>>> here. The image size should be 15,735,052 bytes. Can you download the  
>>> image
>>> again and see if you still have that problem?
>>>
>>
>> Did that, now it opens and shows "This is a closure-converted image. You
>> will not be able to run this image with pre-3.11 VMs. etc" thanks again.
>
>
> You'll probably notice some oddities with the debugger as that change  
> set is
> a little out of date and is missing some fixes I've made since we've put
> closures to everyday use at Qwaq.  I'll try and update the closure  
> bootstrap change set real soon now.

Okay, and thanks for the hint ;)

...

--
"If at first, the idea is not absurd, then there is no hope for it".  
Albert Einstein


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Rob Rothwell
On Sun, Mar 8, 2009 at 2:24 AM, Klaus D. Witzel <[hidden email]> wrote:
On Sat, 07 Mar 2009 18:51:01 +0100, Eliot Miranda wrote:

Hi Klaus,

Hi Eliot,

great job, native closures-support was overdue and is appreciated by the Squeakers.

Hi all,

This is really a newbie question; but I'd thought I'd ask everyone who is already talking about it anyway...

Can you explain exactly what IS native closures-support and why it will be appreciated by the Squeakers?

What will this allow you to do that was not previously possible?

Thank you,

Rob


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Bert Freudenberg

On 08.03.2009, at 16:10, Rob Rothwell wrote:
> This is really a newbie question; but I'd thought I'd ask everyone  
> who is already talking about it anyway...
>
> Can you explain exactly what IS native closures-support and why it  
> will be appreciated by the Squeakers?
>
> What will this allow you to do that was not previously possible?


Simply put, it makes working with blocks more general. Blocks are one  
of the "coolest" features of Smalltalk, but the way they work  
currently is limited. Consider this:

multiply := Array new: 4.
multiply at: 1 put: [:x | x * 1].
multiply at: 2 put: [:x | x * 2].
multiply at: 3 put: [:x | x * 3].
multiply at: 4 put: [:x | x * 4].

This creates an Array where each element is a Block that multiples an  
argument (x) by some constant. E.g.,

(multiply at: 3) value: 5.

would answer 15. So far, so good. Now you might want to put the  
creation of these blocks in a loop:

multiply := Array new: 4.
1 to: 4 do: [:i |
        multiply at: i put: [:x | x * i].
].

And you would rightfully assume that this is equivalent to the version  
above, just more concise. But now try again:

(multiply at: 3) value: 5.

The answer will, surprisingly, not be 15 in current Squeak. But with  
closures, the blocks would behave as expected. They are said to "close  
over" the state that the bound variables (i in this case) had at the  
time the block was created.

So basically, you can use blocks as you always have, but they will  
behave as you might have assumed they would.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Rob Rothwell
On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg <[hidden email]> wrote:
multiply := Array new: 4.
1 to: 4 do: [:i |
       multiply at: i put: [:x | x * i].
].

And you would rightfully assume that this is equivalent to the version above, just more concise. But now try again:

(multiply at: 3) value: 5.

The answer will, surprisingly, not be 15 in current Squeak.

You are right!  25, in fact...
 
But with closures, the blocks would behave as expected. They are said to "close over" the state that the bound variables (i in this case) had at the time the block was created.

So...VW does this "right," I guess, since I get 15 in VW NC 7.6? 

So basically, you can use blocks as you always have, but they will behave as you might have assumed they would.

So the recent VM work discussed handles this?  I will have to give that a try!

Thanks for the explanation!  The next question, of course, is WHY does it get 25 and not 15... ;)

Rob


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Bert Freudenberg
On 08.03.2009, at 18:13, Rob Rothwell wrote:

> On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg <[hidden email]
> > wrote:
>> multiply := Array new: 4.
>> 1 to: 4 do: [:i |
>>        multiply at: i put: [:x | x * i].
>> ].
>>
>> And you would rightfully assume that this is equivalent to the  
>> version above, just more concise. But now try again:
>>
>> (multiply at: 3) value: 5.
>>
>> The answer will, surprisingly, not be 15 in current Squeak.
>
> You are right!  25, in fact...
>
>> But with closures, the blocks would behave as expected. They are  
>> said to "close over" the state that the bound variables (i in this  
>> case) had at the time the block was created.
>
> So...VW does this "right," I guess, since I get 15 in VW NC 7.6?

Yes, it has block closures.

>> So basically, you can use blocks as you always have, but they will  
>> behave as you might have assumed they would.
>>
> So the recent VM work discussed handles this?  I will have to give  
> that a try!
>
> Thanks for the explanation!  The next question, of course, is WHY  
> does it get 25 and not 15... ;)


Because instead of "closing over" the current value of i when the  
block is created, all the blocks share the same reference to i, which  
is actually another temporary variable of the method, instead of being  
local to the block. So when the block is evaluated later, the last  
value of i is used.

Now you might still expect that last value of i to be 4, but actually  
"1 to: 4 do:" is expanded by the compiler to a while loop like "i :=  
1. [i <= 4] whileTrue: [i := i + 1]", so it actually is 5 after the  
loop terminates.

And all this is avoided by having real closures, the i would indeed be  
local to the block and not a shared temp.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Eliot Miranda-2
In reply to this post by Klaus D. Witzel


Eliot (phone)

On 7 Mar 2009, at 22:24, "Klaus D. Witzel" <[hidden email]>  
wrote:

> On Sat, 07 Mar 2009 18:51:01 +0100, Eliot Miranda wrote:
>
>> Hi Klaus,
>
> Hi Eliot,
>
> great job, native closures-support was overdue and is appreciated by  
> the Squeakers.

You're so welcome! I'm looking forward to the quality of the  
implementation improving with wider usage. Lukas has already sent me a  
bug report for which we have an acceptable fix.

Best
Eliot (mobile compromised)

>> On Sat, Mar 7, 2009 at 8:54 AM, Klaus D. Witzel wrote:
>>
>>> On Sat, 07 Mar 2009 17:10:13 +0100, Andreas Raab wrote:
>>>
>>> Klaus D. Witzel wrote:
>>>>
>>>>> A closure image (for those interested):
>>>>>> http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip
>>>>>>
>>>>>> Note that I consider this an "alpha" version since there is a  
>>>>>> goodly bit
>>>>>> of new and untested stuff in it. I'm in particular interested  
>>>>>> in finding
>>>>>> people to test large cursor support and the FT2Plugin.
>>>>>>
>>>>>> Feedback is highly welcome.
>>>>>>
>>>>> I can't see why but the 3.11.1 VM refuses to open
>>>>> Squeak-3.10.2-Closures.image :( windoze (vista) pops up a small  
>>>>> window with
>>>>> Squeak! in title bar and message text "Could not open image  
>>>>> file". FWIW the
>>>>> .image file has 15.367 KB.
>>>>>
>>>>
>>>> That's very odd. I just tried a clean download and it works fine  
>>>> for me
>>>> here. The image size should be 15,735,052 bytes. Can you download  
>>>> the image
>>>> again and see if you still have that problem?
>>>>
>>>
>>> Did that, now it opens and shows "This is a closure-converted  
>>> image. You
>>> will not be able to run this image with pre-3.11 VMs. etc" thanks  
>>> again.
>>
>>
>> You'll probably notice some oddities with the debugger as that  
>> change set is
>> a little out of date and is missing some fixes I've made since  
>> we've put
>> closures to everyday use at Qwaq.  I'll try and update the closure  
>> bootstrap change set real soon now.
>
> Okay, and thanks for the hint ;)
>
> ...
>
> --
> "If at first, the idea is not absurd, then there is no hope for it".  
> Albert Einstein
>
>

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Rob Rothwell
In reply to this post by Bert Freudenberg
Ok...thanks...this is making sense!

So...should I get the "right answer" with the new VM and the 3.10.2-Closures image?

Because...I still get 25!

Rob

On Sun, Mar 8, 2009 at 2:01 PM, Bert Freudenberg <[hidden email]> wrote:
On 08.03.2009, at 18:13, Rob Rothwell wrote:

On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg <[hidden email]> wrote:
multiply := Array new: 4.
1 to: 4 do: [:i |
      multiply at: i put: [:x | x * i].
].

And you would rightfully assume that this is equivalent to the version above, just more concise. But now try again:

(multiply at: 3) value: 5.

The answer will, surprisingly, not be 15 in current Squeak.

You are right!  25, in fact...

But with closures, the blocks would behave as expected. They are said to "close over" the state that the bound variables (i in this case) had at the time the block was created.

So...VW does this "right," I guess, since I get 15 in VW NC 7.6?

Yes, it has block closures.


So basically, you can use blocks as you always have, but they will behave as you might have assumed they would.

So the recent VM work discussed handles this?  I will have to give that a try!

Thanks for the explanation!  The next question, of course, is WHY does it get 25 and not 15... ;)


Because instead of "closing over" the current value of i when the block is created, all the blocks share the same reference to i, which is actually another temporary variable of the method, instead of being local to the block. So when the block is evaluated later, the last value of i is used.

Now you might still expect that last value of i to be 4, but actually "1 to: 4 do:" is expanded by the compiler to a while loop like "i := 1. [i <= 4] whileTrue: [i := i + 1]", so it actually is 5 after the loop terminates.

And all this is avoided by having real closures, the i would indeed be local to the block and not a shared temp.

- Bert -





Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Andreas.Raab
That is the bug Eliot was referring to earlier. The loop variable in
optimized to:do: loops wasn't handled correctly. Try this instead:

        multiply := Array new: 4.
        (1 to: 4) do: [:i |
                multiply at: i put: [:x | x * i].
        ].

Note the parens around "1 to: 4" which prevents the block from being
optimized.

Cheers,
   - Andreas


Rob Rothwell wrote:

> Ok...thanks...this is making sense!
>
> So...should I get the "right answer" with the new VM and the
> 3.10.2-Closures image?
>
> Because...I still get 25!
>
> Rob
>
> On Sun, Mar 8, 2009 at 2:01 PM, Bert Freudenberg <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     On 08.03.2009, at 18:13, Rob Rothwell wrote:
>
>         On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg
>         <[hidden email] <mailto:[hidden email]>> wrote:
>
>             multiply := Array new: 4.
>             1 to: 4 do: [:i |
>                   multiply at: i put: [:x | x * i].
>             ].
>
>             And you would rightfully assume that this is equivalent to
>             the version above, just more concise. But now try again:
>
>             (multiply at: 3) value: 5.
>
>             The answer will, surprisingly, not be 15 in current Squeak.
>
>
>         You are right!  25, in fact...
>
>             But with closures, the blocks would behave as expected. They
>             are said to "close over" the state that the bound variables
>             (i in this case) had at the time the block was created.
>
>
>         So...VW does this "right," I guess, since I get 15 in VW NC 7.6?
>
>
>     Yes, it has block closures.
>
>
>             So basically, you can use blocks as you always have, but
>             they will behave as you might have assumed they would.
>
>         So the recent VM work discussed handles this?  I will have to
>         give that a try!
>
>         Thanks for the explanation!  The next question, of course, is
>         WHY does it get 25 and not 15... ;)
>
>
>
>     Because instead of "closing over" the current value of i when the
>     block is created, all the blocks share the same reference to i,
>     which is actually another temporary variable of the method, instead
>     of being local to the block. So when the block is evaluated later,
>     the last value of i is used.
>
>     Now you might still expect that last value of i to be 4, but
>     actually "1 to: 4 do:" is expanded by the compiler to a while loop
>     like "i := 1. [i <= 4] whileTrue: [i := i + 1]", so it actually is 5
>     after the loop terminates.
>
>     And all this is avoided by having real closures, the i would indeed
>     be local to the block and not a shared temp.
>
>     - Bert -
>
>
>
>
> ------------------------------------------------------------------------
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Rob Rothwell
Perfect!

Thanks...sorry for missing that the two were the same...

Rob

On Sun, Mar 8, 2009 at 6:47 PM, Andreas Raab <[hidden email]> wrote:
That is the bug Eliot was referring to earlier. The loop variable in optimized to:do: loops wasn't handled correctly. Try this instead:


       multiply := Array new: 4.
       (1 to: 4) do: [:i |
               multiply at: i put: [:x | x * i].
       ].

Note the parens around "1 to: 4" which prevents the block from being optimized.

Cheers,
 - Andreas


Rob Rothwell wrote:
Ok...thanks...this is making sense!

So...should I get the "right answer" with the new VM and the 3.10.2-Closures image?

Because...I still get 25!

Rob

On Sun, Mar 8, 2009 at 2:01 PM, Bert Freudenberg <[hidden email] <mailto:[hidden email]>> wrote:

   On 08.03.2009, at 18:13, Rob Rothwell wrote:

       On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg
       <[hidden email] <mailto:[hidden email]>> wrote:

           multiply := Array new: 4.
           1 to: 4 do: [:i |
                 multiply at: i put: [:x | x * i].
           ].

           And you would rightfully assume that this is equivalent to
           the version above, just more concise. But now try again:

           (multiply at: 3) value: 5.

           The answer will, surprisingly, not be 15 in current Squeak.


       You are right!  25, in fact...

           But with closures, the blocks would behave as expected. They
           are said to "close over" the state that the bound variables
           (i in this case) had at the time the block was created.


       So...VW does this "right," I guess, since I get 15 in VW NC 7.6?


   Yes, it has block closures.


           So basically, you can use blocks as you always have, but
           they will behave as you might have assumed they would.

       So the recent VM work discussed handles this?  I will have to
       give that a try!

       Thanks for the explanation!  The next question, of course, is
       WHY does it get 25 and not 15... ;)



   Because instead of "closing over" the current value of i when the
   block is created, all the blocks share the same reference to i,
   which is actually another temporary variable of the method, instead
   of being local to the block. So when the block is evaluated later,
   the last value of i is used.

   Now you might still expect that last value of i to be 4, but
   actually "1 to: 4 do:" is expanded by the compiler to a while loop
   like "i := 1. [i <= 4] whileTrue: [i := i + 1]", so it actually is 5
   after the loop terminates.

   And all this is avoided by having real closures, the i would indeed
   be local to the block and not a shared temp.

   - Bert -




------------------------------------------------------------------------







Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Andreas.Raab
Rob Rothwell wrote:
> Perfect!
>
> Thanks...sorry for missing that the two were the same...

No worries. I've updated the image [1] with Eliot's patch so if you
download the latest all should work as you expected it to.

[1]http://squeakvm.org/win32/release/Squeak-3.10.2-Closures.zip

Cheers,
   - Andreas

> Rob
>
> On Sun, Mar 8, 2009 at 6:47 PM, Andreas Raab <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     That is the bug Eliot was referring to earlier. The loop variable in
>     optimized to:do: loops wasn't handled correctly. Try this instead:
>
>
>            multiply := Array new: 4.
>            (1 to: 4) do: [:i |
>                    multiply at: i put: [:x | x * i].
>            ].
>
>     Note the parens around "1 to: 4" which prevents the block from being
>     optimized.
>
>     Cheers,
>      - Andreas
>
>
>     Rob Rothwell wrote:
>
>         Ok...thanks...this is making sense!
>
>         So...should I get the "right answer" with the new VM and the
>         3.10.2-Closures image?
>
>         Because...I still get 25!
>
>         Rob
>
>         On Sun, Mar 8, 2009 at 2:01 PM, Bert Freudenberg
>         <[hidden email] <mailto:[hidden email]>
>         <mailto:[hidden email] <mailto:[hidden email]>>> wrote:
>
>            On 08.03.2009, at 18:13, Rob Rothwell wrote:
>
>                On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg
>                <[hidden email] <mailto:[hidden email]>
>         <mailto:[hidden email] <mailto:[hidden email]>>> wrote:
>
>                    multiply := Array new: 4.
>                    1 to: 4 do: [:i |
>                          multiply at: i put: [:x | x * i].
>                    ].
>
>                    And you would rightfully assume that this is
>         equivalent to
>                    the version above, just more concise. But now try again:
>
>                    (multiply at: 3) value: 5.
>
>                    The answer will, surprisingly, not be 15 in current
>         Squeak.
>
>
>                You are right!  25, in fact...
>
>                    But with closures, the blocks would behave as
>         expected. They
>                    are said to "close over" the state that the bound
>         variables
>                    (i in this case) had at the time the block was created.
>
>
>                So...VW does this "right," I guess, since I get 15 in VW
>         NC 7.6?
>
>
>            Yes, it has block closures.
>
>
>                    So basically, you can use blocks as you always have, but
>                    they will behave as you might have assumed they would.
>
>                So the recent VM work discussed handles this?  I will have to
>                give that a try!
>
>                Thanks for the explanation!  The next question, of course, is
>                WHY does it get 25 and not 15... ;)
>
>
>
>            Because instead of "closing over" the current value of i when the
>            block is created, all the blocks share the same reference to i,
>            which is actually another temporary variable of the method,
>         instead
>            of being local to the block. So when the block is evaluated
>         later,
>            the last value of i is used.
>
>            Now you might still expect that last value of i to be 4, but
>            actually "1 to: 4 do:" is expanded by the compiler to a while
>         loop
>            like "i := 1. [i <= 4] whileTrue: [i := i + 1]", so it
>         actually is 5
>            after the loop terminates.
>
>            And all this is avoided by having real closures, the i would
>         indeed
>            be local to the block and not a shared temp.
>
>            - Bert -
>
>
>
>
>         ------------------------------------------------------------------------
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Eliot Miranda-2
In reply to this post by Bert Freudenberg
 Bert,
 

So basically, you can use blocks as you always have, but they will behave as you might have assumed they would.

that's the best summary ever!

E.


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New Window VM (Closures, FT2Plugin, Large Cursors)

Eliot Miranda-2
In reply to this post by Rob Rothwell
Hi Rob,

On Sun, Mar 8, 2009 at 10:13 AM, Rob Rothwell <[hidden email]> wrote:
On Sun, Mar 8, 2009 at 12:38 PM, Bert Freudenberg <[hidden email]> wrote:
multiply := Array new: 4.
1 to: 4 do: [:i |
       multiply at: i put: [:x | x * i].
].

And you would rightfully assume that this is equivalent to the version above, just more concise. But now try again:

(multiply at: 3) value: 5.

The answer will, surprisingly, not be 15 in current Squeak.

You are right!  25, in fact...
 
But with closures, the blocks would behave as expected. They are said to "close over" the state that the bound variables (i in this case) had at the time the block was created.

So...VW does this "right," I guess, since I get 15 in VW NC 7.6? 

So basically, you can use blocks as you always have, but they will behave as you might have assumed they would.

So the recent VM work discussed handles this?  I will have to give that a try!

Thanks for the explanation!  The next question, of course, is WHY does it get 25 and not 15... ;)

My blog goes into the excruciating details:


and the other posts starting with "Closures"

HTH

Eliot.


Rob






123