Live data from Hacker News

Can you recreate Objective-C in C?

orangejuiceliberationfront.com

1–10 of 41 posts

Re: Can you recreate Objective-C in C?

#2
> Objective-C under the hood compiles every method call into a call to the function objc_msgSend().

Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc_msgSend really has no idea what the types of function it's calling is, the compiler must call an appropriate function based on the type information it has.

Re: Can you recreate Objective-C in C?

#3

> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…

When you think about it it's bonkers that this language is doing dynamic method calls without any inline caching and I presume no inlining?!. You would think this was intractable for good performance, but it seems to work fine!

Re: Can you recreate Objective-C in C?

#4

> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…

When you think about it it's bonkers that this language is doing dynamic method calls without any inline caching and I presume no inlining ?!. You would think this was intractable for good performance, but it seems to work fine!

There's a lot of caching involved. And it brings a lot of benefits.

Re: Can you recreate Objective-C in C?

#6

> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…

This is also why dynamic languages like PyObjC, RubyObjC, RubyCocoa, MacRuby, Nu, and F# had difficulty bridging certain functions and methods, because you have to either create an insanely complex function that's able to take any @encoding and turn it into a runtime type, or you have to shimmy it with guesses for the most common ones like NSRect et al.

Re: Can you recreate Objective-C in C?

#7
post #6

> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…

This is also why dynamic languages like PyObjC, RubyObjC, RubyCocoa, MacRuby, Nu, and F# had difficulty bridging certain functions and methods, because you have to either create an insanely complex function that's able to take any @encoding and turn it into a runtime type, or you have to shimmy it with guesses for the most common ones like NSRect et al.

[deleted]

Re: Can you recreate Objective-C in C?

#8
post #4

Earlier quoted context omitted.

When you think about it it's bonkers that this language is doing dynamic method calls without any inline caching and I presume no inlining ?!. You would think this was intractable for good performance, but it seems to work fine!

There's a lot of caching involved. And it brings a lot of benefits.

There's no inline caching is there though? And so no 'mother of all optimisations' inlining. Or is my understanding of how Objective C works mistaken?

You wouldn't dream of implementing a dynamic language these days designed for performance without basic polymorphic inline caching. But Objective C seems to get by fine without it. Maybe it's not as essential as we think.

Re: Can you recreate Objective-C in C?

#10
post #4

Earlier quoted context omitted.

There's a lot of caching involved. And it brings a lot of benefits.

There's no inline caching is there though? And so no 'mother of all optimisations' inlining. Or is my understanding of how Objective C works mistaken? You wouldn't dream of implementing a dynamic language these days designed for performance without basic polymorphic inline caching. But Objective C seems to get by fine without it. Maybe it's not as essential as we think.

There’s no inlining, because determining whether inlining wpuld be safe is probably Turing-complete. However, IMP cacheing is a thing and that’s enough for most cases. For the rest there is C and (Objective-)C++.
Post reply on HN