News for hackers. Stuff that matters.
Re:Mulle-objc: A New Objective-C Compiler and Runtime by chrisseaton on Saturday November 26, 2016 @08:07AM (#13043310)
No. Why? What's magic about assembly code that means you couldn't do the same thing in C?
Re:Mulle-objc: A New Objective-C Compiler and Runtime by ksherlock on Saturday November 26, 2016 @10:07PM (#13047469)
the objc_msgSend function doesn't know what it's return type is or how many arguments it has. It needs to lookup the actual function then jump to it without modifying the stack or any of the parameter registers. It simply doesn't follow the calling conventions and C can't handle it.
Re:Mulle-objc: A New Objective-C Compiler and Runtime by chrisseaton on Sunday November 27, 2016 @06:40AM (#13048719)
Right, true. I guess I'm used to working on languages where you can stick everything into a uint64, but that isn't the case with something like returned structs. if you controlled the calling convention you could do it in C.
Re:Mulle-objc: A New Objective-C Compiler and Runtime by lilyball on Monday November 28, 2016 @03:50PM (#13058300)
It appears that controlling the calling convention is exactly what Mulle-objc is doing. It's layering a new convention on top of C calling conventions, where objc_msgSend() is given a pointer to a struct containing the arguments. This way the compiler can synthesize the struct for you, and objc_msgSend() itself can be written in vanilla C.
Re:Mulle-objc: A New Objective-C Compiler and Runtime by jamessu on Saturday November 26, 2016 @09:58AM (#13043795)
While in this case I can't think of any specific reasons beyond performance to need to implement objc_msgSend in assembly, there are absolutely instances where assembly is the only option.

Example: when performing a context switch in a kernel, assembly is required since C abstracts away architecture-specific details necessary to swap out the register set, swap the page directory pointer, etc.

Re:Mulle-objc: A New Objective-C Compiler and Runtime by david-given on Saturday November 26, 2016 @12:05PM (#13044622)
My ObjC-fu is pretty old --- the last time I looked at it seriously was when poc was still a thing --- but my understanding is:

Traditionally objc_msgSend is in assembly because it doesn't know how many and what types the message parameters are. So it can't portably preserve them while it does the computations to find out where to send the message to.

This project's alternative obj_msgSend always passes parameters in a structure. That helps, because now you know that all message calls have three parameters; the destination object, the selector, and the parameter block.

However... they don't always pass the return value in the message block; instead it coerces any integer types to void* and returns them in the usual way, only using an extra field in the parameter block for those values which aren't coerceable to void.

This does make me kinda unhappy. I don't think* it'll be a problem, but... it's definitely pushing the limits of what C allows; round-tripping arbitrary integers through pointers is one of those things that's not technically allowed but all real-world compilers support, so, um. I'd much rather they just pass everything through the parameter block.

But yeah, it's a decent enough idea, which simplifies things considerably at not a lot of performance hit. I'm kind of surprised that ObjC doesn't already do that.

My main disappointment is that this is a clang variant and not a standalone preprocessor. Since poc died there isn't a working ObjC preprocessor, which means if you want to use ObjC you're limited to gcc or clang. An ObjC->C preprocessor would solve that.

Re:Mulle-objc: A New Objective-C Compiler and Runtime by chrisseaton on Saturday November 26, 2016 @12:10PM (#13044653)
I think any real world systems C project will have undefined behaviour. I'm sure HotSpot, V8, .net etc are all totally undefined.