About Primitives

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

About Primitives

Santiago Bragagnolo
 
Hi All

Im analyzing primtives to use them for the concrete type inference project.

Im currently working with primitiveArrayBecomeOneWayCopyHash


primitiveArrayBecomeOneWayCopyHash
      "Similar to primitiveArrayBecomeOneWay but accepts a third argument whether to copy
      the receiver's identity hash over the argument's identity hash."

      | copyHashFlag arg rcvr |
      copyHashFlag := self booleanValueOf: (self stackTop).
      arg := self stackValue: 1.
      rcvr := self stackValue: 2.
      self success: (self become: rcvr with: arg twoWay: false copyHash: copyHashFlag).
      successFlag ifTrue: [ self pop: 2 ].


Well, i'm seeing that pop:2, in a method which don't receive any argument. If pop was 1, i could think in self, but is 2, so the questions are:

1) what is pop:2 in this context
2) why? there's any generalization or rules for understand the stack manage?

Thanks!

Santiago.



Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] About Primitives

Mariano Martinez Peck
 


On Fri, May 25, 2012 at 8:46 PM, Santiago Bragagnolo <[hidden email]> wrote:
Hi All

Im analyzing primtives to use them for the concrete type inference project.

Im currently working with primitiveArrayBecomeOneWayCopyHash


primitiveArrayBecomeOneWayCopyHash
      "Similar to primitiveArrayBecomeOneWay but accepts a third argument whether to copy
      the receiver's identity hash over the argument's identity hash."

      | copyHashFlag arg rcvr |
      copyHashFlag := self booleanValueOf: (self stackTop).
      arg := self stackValue: 1.
      rcvr := self stackValue: 2.
      self success: (self become: rcvr with: arg twoWay: false copyHash: copyHashFlag).
      successFlag ifTrue: [ self pop: 2 ].


Well, i'm seeing that pop:2, in a method which don't receive any argument

yes it receieves! two arguments indeed
if you see #initializePrimitiveTable you see the number of this primitive is 249. So if you browse your iamge, you find:

Array >> #elementsForwardIdentityTo: otherArray copyHash: copyHash
    "This primitive performs a bulk mutation, causing all pointers to the elements of this array to be replaced by pointers to the corresponding elements of otherArray.  The identityHashes remain with the pointers rather than with the objects so that the objects in this array should still be properly indexed in any existing hashed structures after the mutation."
    <primitive: 249>
    self primitiveFailed


so poping 2 means you will let "self" in the top, so it will actually be the return value.
the last time I was hacking in this side of the moon was one year ago...so some validation from someone else would be nice :)
 
. If pop was 1, i could think in self, but is 2, so the questions are:

1) what is pop:2 in this context
2) why? there's any generalization or rules for understand the stack manage?


The rule is that you have to always take care of balance the stack. Be careful to pop according to what you push ;)

 
Thanks!

Santiago.




_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners




--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] About Primitives

Santiago Bragagnolo
 
Thanks Mariano! :)

2012/5/25 Mariano Martinez Peck <[hidden email]>


On Fri, May 25, 2012 at 8:46 PM, Santiago Bragagnolo <[hidden email]> wrote:
Hi All

Im analyzing primtives to use them for the concrete type inference project.

Im currently working with primitiveArrayBecomeOneWayCopyHash


primitiveArrayBecomeOneWayCopyHash
      "Similar to primitiveArrayBecomeOneWay but accepts a third argument whether to copy
      the receiver's identity hash over the argument's identity hash."

      | copyHashFlag arg rcvr |
      copyHashFlag := self booleanValueOf: (self stackTop).
      arg := self stackValue: 1.
      rcvr := self stackValue: 2.
      self success: (self become: rcvr with: arg twoWay: false copyHash: copyHashFlag).
      successFlag ifTrue: [ self pop: 2 ].


Well, i'm seeing that pop:2, in a method which don't receive any argument

yes it receieves! two arguments indeed
if you see #initializePrimitiveTable you see the number of this primitive is 249. So if you browse your iamge, you find:

Array >> #elementsForwardIdentityTo: otherArray copyHash: copyHash
    "This primitive performs a bulk mutation, causing all pointers to the elements of this array to be replaced by pointers to the corresponding elements of otherArray.  The identityHashes remain with the pointers rather than with the objects so that the objects in this array should still be properly indexed in any existing hashed structures after the mutation."
    <primitive: 249>
    self primitiveFailed


so poping 2 means you will let "self" in the top, so it will actually be the return value.
the last time I was hacking in this side of the moon was one year ago...so some validation from someone else would be nice :)
 
. If pop was 1, i could think in self, but is 2, so the questions are:

1) what is pop:2 in this context
2) why? there's any generalization or rules for understand the stack manage?


The rule is that you have to always take care of balance the stack. Be careful to pop according to what you push ;)

 
Thanks!

Santiago.




_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners




--
Mariano
http://marianopeck.wordpress.com


Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] About Primitives

Sean P. DeNigris
Administrator
In reply to this post by Mariano Martinez Peck
Mariano Martinez Peck wrote
yes it receieves! two arguments indeed
plus self is passed implicitly first, right?

Mariano Martinez Peck wrote
if you see #initializePrimitiveTable you see the number of this primitive
is 249. So if you browse your iamge, you find:
How did you "browse the image" for the primitive? I ended up searching sources for "<primitive: 249>". Is there a better/faster way?

Mariano Martinez Peck wrote
so popping 2 means you will let "self" in the top, so it will actually be
the return value.
the last time I was hacking in this side of the moon was one year ago...so
some validation from someone else would be nice :)
That's what it looked like to me.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] About Primitives

Mariano Martinez Peck
 


On Sat, May 26, 2012 at 3:21 AM, Sean P. DeNigris <[hidden email]> wrote:


Mariano Martinez Peck wrote
>
> yes it receieves! two arguments indeed
>
plus self is passed implicitly first, right?


You see? we start to help us each other :)
yes, the receiver is always put in the stack "implicitly"
 

Mariano Martinez Peck wrote
>
> if you see #initializePrimitiveTable you see the number of this primitive
> is 249. So if you browse your iamge, you find:
>
How did you "browse the image" for the primitive? I ended up searching
sources for "<primitive: 249>". Is there a better/faster way?


That's one slow possibily and the hacky and fast one is: CompiledMethod allInstances select: [:each | each primitive = 249]
 

Mariano Martinez Peck wrote
>
> so popping 2 means you will let "self" in the top, so it will actually be
> the return value.
> the last time I was hacking in this side of the moon was one year ago...so
> some validation from someone else would be nice :)
>
That's what it looked like to me.

excellent
 

--
View this message in context: http://forum.world.st/About-Primitives-tp4631848p4631889.html
Sent from the Squeak VM mailing list archive at Nabble.com.



--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] About Primitives

Bert Freudenberg
 

On 26.05.2012, at 10:38, Mariano Martinez Peck wrote:



On Sat, May 26, 2012 at 3:21 AM, Sean P. DeNigris <[hidden email]> wrote:


Mariano Martinez Peck wrote
>
> yes it receieves! two arguments indeed
>
plus self is passed implicitly first, right?


You see? we start to help us each other :)
yes, the receiver is always put in the stack "implicitly"

And and self is put on the stack firs, then the other arguments. So if the primitive only wants to return self, it just pops the 2 arguments off the stack. If it needs to return something else, it also has to pop off self.

How did you "browse the image" for the primitive? I ended up searching
sources for "<primitive: 249>". Is there a better/faster way?


That's one slow possibily and the hacky and fast one is: CompiledMethod allInstances select: [:each | each primitive = 249]
 

Or the less hacky, equally fast

SystemNavigation default browseAllSelect: [:m | m primitive = 249]

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: [Vm-beginners] About Primitives

Sean P. DeNigris
Administrator
Bert Freudenberg wrote
        SystemNavigation default browseAllSelect: ...
Thanks, Bert! I needed that somewhere else, too :)
Cheers,
Sean