What is a primitive method?

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

What is a primitive method?

oscar

Hi all,

     I have a (basic) question:

What is a primitive method?

In pharo 1.1.1, we have CompiledMethod>>primitive that basically return:

0 if the method is not a primitive method
>0 otherwise

But if you execute this on i.e. Number>>isNumber or Morph>>#model compiled methods you get that these two are primitive methods. Are they primitive methods?

Other (related) question is: When I executed the expression:

SystemNavigation default allPrimitiveMethods

, I get a OrderedCollection with 5581 elements. Are all those methods, primitive methods?


Thanks in advance
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: What is a primitive method?

oscar

On 21-10-2010, at 13:18, Oscar E A Callau wrote:

>
> Hi all,
>
>     I have a (basic) question:
>
> What is a primitive method?
>
> In pharo 1.1.1, we have CompiledMethod>>primitive that basically return:
>
> 0 if the method is not a primitive method
>> 0 otherwise

"This must be, as follow"
0 if the method is not a primitive method
(greater than 0) otherwise

"(mail.app changes greater than symbol)"


>
> But if you execute this on i.e. Number>>isNumber or Morph>>#model compiled methods you get that these two are primitive methods. Are they primitive methods?
>
> Other (related) question is: When I executed the expression:
>
> SystemNavigation default allPrimitiveMethods
>
> , I get a OrderedCollection with 5581 elements. Are all those methods, primitive methods?
>
>
> Thanks in advance
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: What is a primitive method?

Eliot Miranda-2
In reply to this post by oscar
Hi Oscar,

    see Object class>>whatIsAPrimitive.  Further, most of the primitive methods you're seeing are methods that answer self, nil, true false or an inst var.  See the difference between these:

SystemNavigation new browseAllSelect: [:m| m isQuick]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not]]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not and: [(#(117 120) includes: m primitive) not]]]

HTH
Eliot

On Thu, Oct 21, 2010 at 9:18 AM, Oscar E A Callau <[hidden email]> wrote:

Hi all,

    I have a (basic) question:

What is a primitive method?

In pharo 1.1.1, we have CompiledMethod>>primitive that basically return:

0 if the method is not a primitive method
>0 otherwise

But if you execute this on i.e. Number>>isNumber or Morph>>#model compiled methods you get that these two are primitive methods. Are they primitive methods?

Other (related) question is: When I executed the expression:

SystemNavigation default allPrimitiveMethods

, I get a OrderedCollection with 5581 elements. Are all those methods, primitive methods?


Thanks in advance
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: What is a primitive method?

Mariano Martinez Peck
THanks Eliot for the explanation.
So....The compiler checks and for these kind of special quick methods it creates a CompiledMethod that has in its header, a primitive value ?

So...if I would be able to put a "self halt" (but I cannot do it becaue otherwise it won't be quick anymore)  in Number>>isNumber, the debugger would never stop there?

Interesting!  Thanks Oscar for the question, it make me learn.

Mariano

2010/10/22 Eliot Miranda <[hidden email]>
Hi Oscar,

    see Object class>>whatIsAPrimitive.  Further, most of the primitive methods you're seeing are methods that answer self, nil, true false or an inst var.  See the difference between these:

SystemNavigation new browseAllSelect: [:m| m isQuick]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not]]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not and: [(#(117 120) includes: m primitive) not]]]

HTH
Eliot


On Thu, Oct 21, 2010 at 9:18 AM, Oscar E A Callau <[hidden email]> wrote:

Hi all,

    I have a (basic) question:

What is a primitive method?

In pharo 1.1.1, we have CompiledMethod>>primitive that basically return:

0 if the method is not a primitive method
>0 otherwise

But if you execute this on i.e. Number>>isNumber or Morph>>#model compiled methods you get that these two are primitive methods. Are they primitive methods?

Other (related) question is: When I executed the expression:

SystemNavigation default allPrimitiveMethods

, I get a OrderedCollection with 5581 elements. Are all those methods, primitive methods?


Thanks in advance
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: What is a primitive method?

Eliot Miranda-2


2010/10/22 Mariano Martinez Peck <[hidden email]>
THanks Eliot for the explanation.
So....The compiler checks and for these kind of special quick methods it creates a CompiledMethod that has in its header, a primitive value ?

A number, yes.  The number answered by CompiledMethod>primitive.


So...if I would be able to put a "self halt" (but I cannot do it becaue otherwise it won't be quick anymore)  in Number>>isNumber, the debugger would never stop there?

 

The way to put a break-point around a primitive is to rewrite it as a wrapper method around the actual primitive, e.g.

SmallInteger>>+ aNumber
    <primitive: 1>
    ^super + aNumber

=> SmallInteger>>primitivePlus: aNumber
        <primitive: 1>
        ^super + aNumber

    SmallInteger>>+ aNumber
        FirstTime == nil ifTrue: [FirstTime := false. self halt].
        ^self primitivePlus: aNumber

you absolutely need the FirstTime approach (where FirstTie is some global you define for the purpose)  to cause the halt to fire once if you're trying to break-point a method that is in wide-spread use.  Otherwise the system will die a recursive death ;)

best
Eliot
 

Interesting!  Thanks Oscar for the question, it make me learn.

Mariano

2010/10/22 Eliot Miranda <[hidden email]>

Hi Oscar,

    see Object class>>whatIsAPrimitive.  Further, most of the primitive methods you're seeing are methods that answer self, nil, true false or an inst var.  See the difference between these:

SystemNavigation new browseAllSelect: [:m| m isQuick]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not]]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not and: [(#(117 120) includes: m primitive) not]]]

HTH
Eliot


On Thu, Oct 21, 2010 at 9:18 AM, Oscar E A Callau <[hidden email]> wrote:

Hi all,

    I have a (basic) question:

What is a primitive method?

In pharo 1.1.1, we have CompiledMethod>>primitive that basically return:

0 if the method is not a primitive method
>0 otherwise

But if you execute this on i.e. Number>>isNumber or Morph>>#model compiled methods you get that these two are primitive methods. Are they primitive methods?

Other (related) question is: When I executed the expression:

SystemNavigation default allPrimitiveMethods

, I get a OrderedCollection with 5581 elements. Are all those methods, primitive methods?


Thanks in advance
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: What is a primitive method?

Mariano Martinez Peck


2010/10/22 Eliot Miranda <[hidden email]>


2010/10/22 Mariano Martinez Peck <[hidden email]>

THanks Eliot for the explanation.
So....The compiler checks and for these kind of special quick methods it creates a CompiledMethod that has in its header, a primitive value ?

A number, yes.  The number answered by CompiledMethod>primitive.


Ok...thanks Eliot.
 

So...if I would be able to put a "self halt" (but I cannot do it becaue otherwise it won't be quick anymore)  in Number>>isNumber, the debugger would never stop there?

 

The way to put a break-point around a primitive is to rewrite it as a wrapper method around the actual primitive, e.g.

SmallInteger>>+ aNumber
    <primitive: 1>
    ^super + aNumber

=> SmallInteger>>primitivePlus: aNumber
        <primitive: 1>
        ^super + aNumber

    SmallInteger>>+ aNumber
        FirstTime == nil ifTrue: [FirstTime := false. self halt].
        ^self primitivePlus: aNumber

Ahhh that's true :)
I forget about that...once I did exactly this for FFI calls.
 

you absolutely need the FirstTime approach (where FirstTie is some global you define for the purpose)  to cause the halt to fire once if you're trying to break-point a method that is in wide-spread use.  Otherwise the system will die a recursive death ;)


I guess  we can also use self haltOnce ?   which implementations does exactly that you suggested :)

Thanks!

mariano
 
best
Eliot
 

Interesting!  Thanks Oscar for the question, it make me learn.

Mariano

2010/10/22 Eliot Miranda <[hidden email]>

Hi Oscar,

    see Object class>>whatIsAPrimitive.  Further, most of the primitive methods you're seeing are methods that answer self, nil, true false or an inst var.  See the difference between these:

SystemNavigation new browseAllSelect: [:m| m isQuick]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not]]

SystemNavigation new browseAllSelect: [:m| m primitive > 0 and: [m isQuick not and: [(#(117 120) includes: m primitive) not]]]

HTH
Eliot


On Thu, Oct 21, 2010 at 9:18 AM, Oscar E A Callau <[hidden email]> wrote:

Hi all,

    I have a (basic) question:

What is a primitive method?

In pharo 1.1.1, we have CompiledMethod>>primitive that basically return:

0 if the method is not a primitive method
>0 otherwise

But if you execute this on i.e. Number>>isNumber or Morph>>#model compiled methods you get that these two are primitive methods. Are they primitive methods?

Other (related) question is: When I executed the expression:

SystemNavigation default allPrimitiveMethods

, I get a OrderedCollection with 5581 elements. Are all those methods, primitive methods?


Thanks in advance
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project