[squeak-dev] Re: [Pharo-project] How about atomic value-swap bytecode?

Eliot Miranda eliot.miranda at gmail.com
Wed Oct 13 17:46:08 UTC 2010


On Wed, Oct 13, 2010 at 9:22 AM, Igor Stasenko <siguctua at gmail.com> wrote:

> On 13 October 2010 18:54, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> >
> > Right.  And because Smalltak can't reify variables and CAS is an
> operation
> > on a variable CAS can't be implemented as a primitive on variables.
>  There's
> > no way to express "pass a variable to a primitive", only "pass an
> expression
> > (which may be the value of a variable)" to a primitive".  One could do it
> > with a primitive on an object, e.g. thisContext at: tempIndex
> compareWith:
> > match andSetTo: expr, or anObject instVarAt: varIndex compareWith: match
> > andSetTo: expr but that's soooo ugly.  Hence I think it is better done
> using
> > a special assignment operator.
>
> Eliot, if this not a bytecode (which is much more lightweigth to
> primitive),
> then why bother ?
>

I'm sorry; I thought it was obvious that the above would be implemented as a
bytecode since := is a (set of) bytecode(s).  In fact it would be three
bytecodes, e.g. cassignTemp, cassingnInstVar and cassingnLitVar.




>
> It is trivial to implement a primitive like:
>
> Array>>compareAt: index with: value andStore: anObject
>  <primitive: 'primitiveCAS' >
>

Yes, but that requires two primitives (inst vars and indexed vars) and
doesn't work elegantly on temp vars so I think expressively it's very poor.
 Whereas the bytecode is elegant and operates where I want it on variables.
 Do you see much utility for cas on arrays instead of cas on inst, temp and
global vars?

best
Eliot


...
>
> so, then you can do:
>
> moo := Array with: 100.
>
> oldValue := moo compareAt: 1 with: 100 andStore: 2.
> self assert: oldValue == 100.
> self assert: moo first == 2
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20101013/1a919bf8/attachment.htm


More information about the Squeak-dev mailing list