About Primitives

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 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.




_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: 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


_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
Reply | Threaded
Open this post in threaded view
|

Re: 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



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