Odd literal in metaclasses methods

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

Odd literal in metaclasses methods

Henrik Nergaard-2
Every method implemented in the class side includes a literal: “nil->theMetaClass”.
Object class methods collect: [ :cm | cm literals last ]. 
 
What is it used for?
 
Best regards,
Henrik
 
Reply | Threaded
Open this post in threaded view
|

Re: Odd literal in metaclasses methods

Nicolas Cellier
Because CompiledMethod>>methodClass expects a classical literal binding className->class

methodClass
    "answer the class that I am installed in"
    ^(self literalAt: self numLiterals) value.

But there ain't no binding for the metaclass which is accessible only indirectly thru the class (you write Object class, not ObjectClass).
So it is a kind of hack to unify class and metaclass behavior...

Note that the hack is necessary and used by the VM for resolving super send, so think twice if you want to come with a better hack, it's possible but also and advanced topic.

2016-10-29 18:23 GMT+02:00 Henrik Nergaard <[hidden email]>:
Every method implemented in the class side includes a literal: “nil->theMetaClass”.
Object class methods collect: [ :cm | cm literals last ]. 
 
What is it used for?
 
Best regards,
Henrik