June 23, 2013 D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
As some of you might know Michel Fortin created a fork of DMD a couple of years ago which add support for using Objective-C classes and calling Objective-C method. That is making D ABI compatible with Objective-C. I have now updated it to the latest version of DMD and druntime. All D/Objective-C tests pass and all standard tests pass. I'm planning to create a DIP for this and would really like this to be folded into main line. For know you can read the design document created by Michel: http://michelf.ca/projects/d-objc/syntax/ Original project page: http://michelf.ca/projects/d-objc/ My forks: DMD: https://github.com/jacob-carlborg/dmd/tree/d-objc druntime: https://github.com/jacob-carlborg/druntime/tree/d-objc Phobos: standard Phobos, commit f85bd54ef5615986960fdd68ea87c8aaf5c5118d Currently I have limited bandwidth and cannot upload a pre-compiled binary. To compile use the following commands: cd dmd/src make -f posix.mak MODEL=32 D_OBJC=1 cd druntime make -f posix.mak DMD=../dmd/src/dmd MODEL=32 D_OBJC=1 cd phobos make -f posix.mak DMD=../dmd/src/dmd MODEL=32 Currently D/Objc only works for 32bit. You can use Michel's example application, Chocolate, to try it out. It's a bit cumbersome to compile without Xcode but it's possible. http://littoral.michelf.ca/code/d-objc/chocolate-dobjc-a1.zip -- /Jacob Carlborg |
June 23, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Jacob Carlborg: > http://michelf.ca/projects/d-objc/syntax/ Instead of: extern (Objective-C) Is it better to use a naming more D-idiomatic? extern (Objective_C) Regarding this syntax: void insertItem(ObjcObject object, NSInteger value) [insertItemWithObjectValue:atIndex:]; Is it possible and good to replace it with some UDA? > I'm planning to create a DIP for this and would really like this to be folded into main line. It seems contain some different things/syntax. I don't know how much Walter&Co will appreciate it. Bye, bearophile |
June 23, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 6/23/2013 1:24 PM, Jacob Carlborg wrote:
> As some of you might know Michel Fortin created a fork of DMD a couple of years
> ago which add support for using Objective-C classes and calling Objective-C
> method. That is making D ABI compatible with Objective-C.
>
> I have now updated it to the latest version of DMD and druntime. All
> D/Objective-C tests pass and all standard tests pass. I'm planning to create a
> DIP for this and would really like this to be folded into main line. For know
> you can read the design document created by Michel:
Thank you for reviving this. Please carry on!
|
June 23, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 2013-06-23, 23:02, bearophile wrote: > Jacob Carlborg: > >> http://michelf.ca/projects/d-objc/syntax/ > > Instead of: > extern (Objective-C) > > Is it better to use a naming more D-idiomatic? > > extern (Objective_C) There's already some precedence in extern (C++). -- Simen |
June 24, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 2013-06-23 23:02, bearophile wrote: > Instead of: > extern (Objective-C) > > Is it better to use a naming more D-idiomatic? > > extern (Objective_C) As Simen said, we already have extern (C++). But I can absolutely change this if people wants to. > Regarding this syntax: > > void insertItem(ObjcObject object, NSInteger value) > [insertItemWithObjectValue:atIndex:]; > > Is it possible and good to replace it with some UDA? We could use an attribute. But I don't think it would be possible to use an UDA. Currently the compiler doesn't know anything about a particular UDA, all UDA's are treated the same. It it's either a built in attribute or an UDA. Doing something in between would be a lot harder. > It seems contain some different things/syntax. I don't know how much > Walter&Co will appreciate it. I would say that it's very little new syntax, surprisingly. But semantically there's a lot of new stuff. But the core things are just the same as with extern (C), making D ABI compatible with another language, Objective-C. I think that this is mostly is a non-breaking change. All new keywords are prefix with two underscores, which is reserved by the compiler. A lot of stuff only apply for classes/methods declared as extern (Objective-C). * extern (Objective-C) - I wouldn't really consider this new syntax * [foo:bar:] - New syntax. Does not have to use this exact syntax but the functionality it provides is essential. * Constructors in interfaces - Not really a new syntax. Just allows an existing syntax to be used in a new place. * Foo.class - I guess this technically is new syntax. The only thing making this new syntax is the use of keyword. I we really don't want this we could rename it to __class or similar. * __classext - Not implement yet, so that's up for discussion * String literals - No new syntax. Just an implicit conversion added * BOOL __selector(NSString) - New syntax. Kind of essential to have. * Foo.protocolof - Not really a new syntax either. I don't think this is as essential as the other features. * @IBOutlet and @IBAction - Not implemented. This could possibly be implemented as dummy UDA's. * Blocks - Not implemented. I'm wondering if we could use the delegate keyword for this. If a delegate is marked as extern (Objective-C) it's a block. Or that might perhaps be confusing. -- /Jacob Carlborg |
June 24, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2013-06-23 23:12, Walter Bright wrote: > Thank you for reviving this. Please carry on! Is there a chance we can get this into main line? -- /Jacob Carlborg |
June 24, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 2013-06-23 20:24:41 +0000, Jacob Carlborg <doob@me.com> said: > As some of you might know Michel Fortin created a fork of DMD a couple of years ago which add support for using Objective-C classes and calling Objective-C method. That is making D ABI compatible with Objective-C. > > I have now updated it to the latest version of DMD and druntime. All D/Objective-C tests pass and all standard tests pass. I know it was significant work to make it both play nice with the most recent OS X linker and port it to the newest DMD code base. Great achievement. -- Michel Fortin michel.fortin@michelf.ca http://michelf.ca/ |
June 24, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 2013-06-24 10:04:01 +0000, Jacob Carlborg <doob@me.com> said: >> Regarding this syntax: >> >> void insertItem(ObjcObject object, NSInteger value) >> [insertItemWithObjectValue:atIndex:]; >> >> Is it possible and good to replace it with some UDA? > > We could use an attribute. But I don't think it would be possible to use an UDA. Currently the compiler doesn't know anything about a particular UDA, all UDA's are treated the same. It it's either a built in attribute or an UDA. Doing something in between would be a lot harder. Not necessarily. There's a couple of Objective-C classes that get special treatment by the compiler (identified by a pragma). One could do the same for an UDA so the compiler would know where to get that value. I'd surely have implemented it as an UDA if such a thing existed at the time. Perhaps we should use a string UDA. ;-) (joke) >> It seems contain some different things/syntax. I don't know how much >> Walter&Co will appreciate it. > > I would say that it's very little new syntax, surprisingly. But semantically there's a lot of new stuff. But the core things are just the same as with extern (C), making D ABI compatible with another language, Objective-C. I think that this is mostly is a non-breaking change. It indeed is an additive and non-breaking change. > All new keywords are prefix with two underscores, which is reserved by the compiler. A lot of stuff only apply for classes/methods declared as extern (Objective-C). > > * extern (Objective-C) - I wouldn't really consider this new syntax > > * [foo:bar:] - New syntax. Does not have to use this exact syntax but the functionality it provides is essential. > > * Constructors in interfaces - Not really a new syntax. Just allows an existing syntax to be used in a new place. And it's only allowed in extern (Objective-C) interfaces because it does not make much sense for D interfaces. > * Foo.class - I guess this technically is new syntax. The only thing making this new syntax is the use of keyword. I we really don't want this we could rename it to __class or similar. It is a new syntax. This "function" needs special semantic treatment by the compiler because it returns an object of a different class depending on the type or object you're calling it on. It also mirrors the method named "class" in Objective-C. Given these data points, it seemed appropriate to use the class keyword, which hints at the compiler magic. Hence why I tweaked the syntax to allow ".class" on Objective-C classes and objects. > * __classext - Not implement yet, so that's up for discussion > > * String literals - No new syntax. Just an implicit conversion added I'm particularly proud of those string literals. They're way cleaner than their Objective-C counterparts. :-) > * BOOL __selector(NSString) - New syntax. Kind of essential to have. Those too are better than their Objective-C counterpart too as they carry the argument and return type, making them less error-prone. > * Foo.protocolof - Not really a new syntax either. I don't think this is as essential as the other features. It gives you the pointer for protocol (interface) Foo. You need that if you want to check at runtime if a class conforms to this protocol (or implements this interface in D parlance). > * @IBOutlet and @IBAction - Not implemented. This could possibly be implemented as dummy UDA's. > > * Blocks - Not implemented. I'm wondering if we could use the delegate keyword for this. If a delegate is marked as extern (Objective-C) it's a block. Or that might perhaps be confusing. Blocks are reference-counted and don't share the two-pointer layout of a delegate. I'm not sure it'd be wise to call them delegates. But this needs some more thinking. Finally, there is a couple of features that were added to Objective-C since then that should be added to the todo list to keep feature parity. Some of those, if implemented right, could benefit the rest of D too. For instance: ARC (automatic reference counting) which is becoming a must in Objective-C. -- Michel Fortin michel.fortin@michelf.ca http://michelf.ca/ |
June 24, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On 2013-06-24 14:49, Michel Fortin wrote: > I know it was significant work to make it both play nice with the most > recent OS X linker and port it to the newest DMD code base. Great > achievement. Thank you for all the help I've got and for you starting with this whole project. -- /Jacob Carlborg |
June 24, 2013 Re: D/Objective-C, extern (Objective-C) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 6/24/2013 3:04 AM, Jacob Carlborg wrote:
> On 2013-06-23 23:12, Walter Bright wrote:
>
>> Thank you for reviving this. Please carry on!
>
> Is there a chance we can get this into main line?
Yes, but since I don't know much about O-C programming, the feature should be labeled "experimental" until we're sure it's the right design.
|
Copyright © 1999-2021 by the D Language Foundation