[squeak-dev] becomeForward: alternative

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

[squeak-dev] becomeForward: alternative

Rob Withers
I am trying to becomeForward with an object and a small integer.  This of
course doesn't work.  Is there an alternative that would allow me to do
this?

thanks,
Rob


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: becomeForward: alternative

Paolo Bonzini-2
Rob Withers wrote:
> I am trying to becomeForward with an object and a small integer.  This
> of course doesn't work.  Is there an alternative that would allow me to
> do this?

There's actually no reason why the *destination* of a becomeForward:
cannot be a SmallInteger.  It's a VM bug in my opinion.

Paolo

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Rob Withers

----- Original Message -----
From: "Paolo Bonzini" <[hidden email]>
To: "The general-purpose Squeak developers list"
<[hidden email]>
Sent: Tuesday, September 16, 2008 3:59 PM
Subject: [squeak-dev] Re: becomeForward: alternative


> Rob Withers wrote:
>> I am trying to becomeForward with an object and a small integer.  This
>> of course doesn't work.  Is there an alternative that would allow me to
>> do this?
>
> There's actually no reason why the *destination* of a becomeForward:
> cannot be a SmallInteger.  It's a VM bug in my opinion.
>

Thanks, Paolo.

I tried looking into this a bit and here is what I have found.  First off,
this will only work with
    #elementsForwardIdentityTo: anArrayWithSmallIntegers copyHash: false.
It would not work to copy the source hash to a SmallInteger.

Next is understanding forwarding blocks and the process of remapping objects
using them.  There are three steps:
    1) #prepareForwardingTableForBecoming:with:twoWay:  "create and init
forwarding blocks, and install into original headers"
    2) #mapPointersInObjectsFrom:to:  "point pointers to forwarded oop"
    3) #restoreHeadersAfterForwardBecome: "restore original headers"
The question seems to come down to the following.  Can forwarding blocks
point to SmallIntegers?

Rob

> Paolo
>


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Eliot Miranda-2
Things work fine provided the become is one-way and hashes are not copied.  Simply change

        (self containOnlyOops: array1 and: array2) ifFalse: [^false]

in ObjectMemory>>become:with:twoWay:copyHash: to

(twoWayFlag or: [copyHashFlag])
ifTrue: [(self containOnlyOops: array1 and: array2) ifFalse: [^false]]
ifFalse: [(self containOnlyOops: array1) ifFalse: [^false]].

along with the obvious implementation of containOnlyOops:.
If so,
| foo bar |
foo := 1@2.
bar := { foo. foo }.
foo becomeForward: 0 copyHash: false.
{ foo. bar }
produces
#(0 #(0 0))

On Thu, Sep 18, 2008 at 9:09 AM, Rob Withers <[hidden email]> wrote:

----- Original Message ----- From: "Paolo Bonzini" <[hidden email]>
To: "The general-purpose Squeak developers list" <[hidden email]>
Sent: Tuesday, September 16, 2008 3:59 PM
Subject: [squeak-dev] Re: becomeForward: alternative



Rob Withers wrote:
I am trying to becomeForward with an object and a small integer.  This
of course doesn't work.  Is there an alternative that would allow me to
do this?

There's actually no reason why the *destination* of a becomeForward:
cannot be a SmallInteger.  It's a VM bug in my opinion.


Thanks, Paolo.

I tried looking into this a bit and here is what I have found.  First off, this will only work with
  #elementsForwardIdentityTo: anArrayWithSmallIntegers copyHash: false.
It would not work to copy the source hash to a SmallInteger.

Next is understanding forwarding blocks and the process of remapping objects using them.  There are three steps:
  1) #prepareForwardingTableForBecoming:with:twoWay:  "create and init forwarding blocks, and install into original headers"
  2) #mapPointersInObjectsFrom:to:  "point pointers to forwarded oop"
  3) #restoreHeadersAfterForwardBecome: "restore original headers"
The question seems to come down to the following.  Can forwarding blocks point to SmallIntegers?

Rob

Paolo






Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Rob Withers
:-)
 
I just compiled with:
 
 (twoWayFlag not and: [copyHashFlag not])
  ifTrue: [(self containOnlyOops: array1) ifFalse: [^false]]
  ifFalse: [(self containOnlyOops: array1 and: array2) ifFalse: [^false]].
but I like your positive logic better.  Thanks!
 
Rob
----- Original Message -----
Sent: Thursday, September 18, 2008 12:41 PM
Subject: Re: [squeak-dev] Re: becomeForward: alternative

Things work fine provided the become is one-way and hashes are not copied.  Simply change

        (self containOnlyOops: array1 and: array2) ifFalse: [^false]

in ObjectMemory>>become:with:twoWay:copyHash: to

(twoWayFlag or: [copyHashFlag])
ifTrue: [(self containOnlyOops: array1 and: array2) ifFalse: [^false]]
ifFalse: [(self containOnlyOops: array1) ifFalse: [^false]].

along with the obvious implementation of containOnlyOops:.
If so,
| foo bar |
foo := 1@2.
bar := { foo. foo }.
foo becomeForward: 0 copyHash: false.
{ foo. bar }
produces
#(0 #(0 0))

On Thu, Sep 18, 2008 at 9:09 AM, Rob Withers <[hidden email]> wrote:

----- Original Message ----- From: "Paolo Bonzini" <[hidden email]>
To: "The general-purpose Squeak developers list" <[hidden email]>
Sent: Tuesday, September 16, 2008 3:59 PM
Subject: [squeak-dev] Re: becomeForward: alternative



Rob Withers wrote:
I am trying to becomeForward with an object and a small integer.  This
of course doesn't work.  Is there an alternative that would allow me to
do this?

There's actually no reason why the *destination* of a becomeForward:
cannot be a SmallInteger.  It's a VM bug in my opinion.


Thanks, Paolo.

I tried looking into this a bit and here is what I have found.  First off, this will only work with
  #elementsForwardIdentityTo: anArrayWithSmallIntegers copyHash: false.
It would not work to copy the source hash to a SmallInteger.

Next is understanding forwarding blocks and the process of remapping objects using them.  There are three steps:
  1) #prepareForwardingTableForBecoming:with:twoWay:  "create and init forwarding blocks, and install into original headers"
  2) #mapPointersInObjectsFrom:to:  "point pointers to forwarded oop"
  3) #restoreHeadersAfterForwardBecome: "restore original headers"
The question seems to come down to the following.  Can forwarding blocks point to SmallIntegers?

Rob

Paolo








Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Eliot Miranda-2


On Thu, Sep 18, 2008 at 9:44 AM, Rob Withers <[hidden email]> wrote:
:-)
 
I just compiled with:
 
 (twoWayFlag not and: [copyHashFlag not])
  ifTrue: [(self containOnlyOops: array1) ifFalse: [^false]]
  ifFalse: [(self containOnlyOops: array1 and: array2) ifFalse: [^false]].
but I like your positive logic better.  Thanks!

Forgive me, you've got me started :)  I hate it when people don't cut down on their conditionals.  I saw this the other day (won't tell you where) and it drives me *batty*.

    if((options & LINK_OPTION_PRIVATE) == LINK_OPTION_PRIVATE)
        object_image->image.private = TRUE;
    else
        object_image->image.private = FALSE;

the following takes 25% of the vertical real estate and says it better.

        object_image->image.private = options & LINK_OPTION_PRIVATE) == LINK_OPTION_PRIVATE;

Even worse is the following idiom:

        if(print_addresses == TRUE)

I mean if you're that doubtful surely you want to use belt-and-braces and write

        if(((print_addresses == TRUE) == TRUE) == TRUE)

to be free of anxiety.

 
Rob
----- Original Message -----
Sent: Thursday, September 18, 2008 12:41 PM
Subject: Re: [squeak-dev] Re: becomeForward: alternative

Things work fine provided the become is one-way and hashes are not copied.  Simply change

        (self containOnlyOops: array1 and: array2) ifFalse: [^false]

in ObjectMemory>>become:with:twoWay:copyHash: to

(twoWayFlag or: [copyHashFlag])
ifTrue: [(self containOnlyOops: array1 and: array2) ifFalse: [^false]]
ifFalse: [(self containOnlyOops: array1) ifFalse: [^false]].

along with the obvious implementation of containOnlyOops:.
If so,
| foo bar |
foo := 1@2.
bar := { foo. foo }.
foo becomeForward: 0 copyHash: false.
{ foo. bar }
produces
#(0 #(0 0))

On Thu, Sep 18, 2008 at 9:09 AM, Rob Withers <[hidden email]> wrote:

----- Original Message ----- From: "Paolo Bonzini" <[hidden email]>
To: "The general-purpose Squeak developers list" <[hidden email]>
Sent: Tuesday, September 16, 2008 3:59 PM
Subject: [squeak-dev] Re: becomeForward: alternative



Rob Withers wrote:
I am trying to becomeForward with an object and a small integer.  This
of course doesn't work.  Is there an alternative that would allow me to
do this?

There's actually no reason why the *destination* of a becomeForward:
cannot be a SmallInteger.  It's a VM bug in my opinion.


Thanks, Paolo.

I tried looking into this a bit and here is what I have found.  First off, this will only work with
  #elementsForwardIdentityTo: anArrayWithSmallIntegers copyHash: false.
It would not work to copy the source hash to a SmallInteger.

Next is understanding forwarding blocks and the process of remapping objects using them.  There are three steps:
  1) #prepareForwardingTableForBecoming:with:twoWay:  "create and init forwarding blocks, and install into original headers"
  2) #mapPointersInObjectsFrom:to:  "point pointers to forwarded oop"
  3) #restoreHeadersAfterForwardBecome: "restore original headers"
The question seems to come down to the following.  Can forwarding blocks point to SmallIntegers?

Rob

Paolo












Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Randal L. Schwartz
>>>>> "Eliot" == Eliot Miranda <[hidden email]> writes:

Eliot>     if((options & LINK_OPTION_PRIVATE) == LINK_OPTION_PRIVATE)
object_image-> image.private = TRUE;
Eliot>     else
object_image-> image.private = FALSE;

Eliot> the following takes 25% of the vertical real estate and says it better.

Eliot> object_image-> image.private = options & LINK_OPTION_PRIVATE) ==
Eliot> LINK_OPTION_PRIVATE;

For an endless supply of these, check out thedailywtf.com, which should be
mandatory reading for anyone involved in code creation, review, or
maintenance, with "Don't let your code end up here!" as the goal.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: becomeForward: alternative

Paolo Bonzini-2
In reply to this post by Eliot Miranda-2

>         object_image->image.private = options & LINK_OPTION_PRIVATE) ==
> LINK_OPTION_PRIVATE;

Couldn't help it: if LINK_OPTION_PRIVATE is a single bit,

  object_image->image.private = (options & LINK_OPTION_PRIVATE) != 0;

Paolo

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Benjamin Pollack
On Fri, Sep 19, 2008 at 3:36 AM, Paolo Bonzini <[hidden email]> wrote:

>         object_image->image.private = options & LINK_OPTION_PRIVATE) ==
> LINK_OPTION_PRIVATE;

Couldn't help it: if LINK_OPTION_PRIVATE is a single bit,

 object_image->image.private = (options & LINK_OPTION_PRIVATE) != 0;

You can do better than that. Even if you really need to set image.private to TRUE or FALSE explicitly, you can just do

object_image->image.private = !!(options & LINK_OPTION_PRIVATE)

and if you don't, you can drop the !!.

I'd really rather just not write C though.

--Benjamin


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: becomeForward: alternative

Eliot Miranda-2
In reply to this post by Paolo Bonzini-2


On Fri, Sep 19, 2008 at 12:36 AM, Paolo Bonzini <[hidden email]> wrote:

>         object_image->image.private = options & LINK_OPTION_PRIVATE) ==
> LINK_OPTION_PRIVATE;

Couldn't help it: if LINK_OPTION_PRIVATE is a single bit,

 object_image->image.private = (options & LINK_OPTION_PRIVATE) != 0;

Right. And hence even
 
    object_image->image.private = options & LINK_OPTION_PRIVATE;

But this might fail because sizeof(options) might be greater than sizeof(image.private) and hence yours is preferred.



Paolo




Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: becomeForward: alternative

Paolo Bonzini-2
In reply to this post by Benjamin Pollack
> Even if you really need to set
> image.private to TRUE or FALSE explicitly, you can just do
>
> object_image->image.private = !!(options & LINK_OPTION_PRIVATE)
>
> and if you don't, you can drop the !!.
>
> I'd really rather just not write C though.

Then what about C++ (but actually C99 too):

 object_image->image.private = (bool) (options & LINK_OPTION_PRIVATE)

then? Hmmm... I guess this is not what you meant!

Paolo