{"action":"created","issue":{"url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/4321","labels_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/4321/labels{/name}","comments_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/4321/comments","events_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/4321/events","html_url":"https://github.com/D-Programming-Language/dmd/pull/4321","id":54937335,"number":4321,"title":"Implement basic support for Objective-C methods.","user":{"login":"jacob-carlborg","id":306980,"avatar_url":"https://avatars.githubusercontent.com/u/306980?v=3","gravatar_id":"","url":"https://api.github.com/users/jacob-carlborg","html_url":"https://github.com/jacob-carlborg","followers_url":"https://api.github.com/users/jacob-carlborg/followers","following_url":"https://api.github.com/users/jacob-carlborg/following{/other_user}","gists_url":"https://api.github.com/users/jacob-carlborg/gists{/gist_id}","starred_url":"https://api.github.com/users/jacob-carlborg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacob-carlborg/subscriptions","organizations_url":"https://api.github.com/users/jacob-carlborg/orgs","repos_url":"https://api.github.com/users/jacob-carlborg/repos","events_url":"https://api.github.com/users/jacob-carlborg/events{/privacy}","received_events_url":"https://api.github.com/users/jacob-carlborg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":57,"created_at":"2015-01-20T20:48:19Z","updated_at":"2015-07-11T11:06:10Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/dmd/pulls/4321","html_url":"https://github.com/D-Programming-Language/dmd/pull/4321","diff_url":"https://github.com/D-Programming-Language/dmd/pull/4321.diff","patch_url":"https://github.com/D-Programming-Language/dmd/pull/4321.patch"},"body":"Some return types does not work, those are: `long double`, `_Complex long double` and structs that are too large to fit in registers. The runtime part of this pull is in https://github.com/D-Programming-Language/druntime/pull/1111.\r\n\r\nThe below text is in the commit message as well. I don't know if it's too long for a commit message or if there's a better place to document this.\r\n\r\nBasic support for classes, interfaces and instance methods.\r\nThis is implemented by adding a new linkage attribute, `Objective-C`,\r\nand a compiler recognized UDA, `@selector`. The linkage attribute is\r\nto be used on a class or interface. The UDA is attached to a method.\r\n\r\nThe linkage attribute tells the compiler that the class should use the\r\nname mangling that matches the one used by Objective-C\r\n(same as C, no mangling) and that all methods in the class\r\nshould use the Objective-C way of calling methods, see below.\r\nThe calling convention for Objective-C methods and functions is the\r\nsame as for C.\r\n\r\nThe selector UDA tells the compiler what Objective-C selector the\r\nmethod should have. The selector is used in the Objective-C runtime\r\nto find the implementation of a given method.\r\n\r\nAn Objective-C method call is implemented by making a regular C call\r\nto the `objc_msgSend` function in the Objective-C runtime.\r\nThe signature of `objc_msgSend` looks something like this:\r\n\r\n`id objc_msgSend(id self, SEL op, ...);`\r\n\r\n* The first parameter is the object (this/self pointer)\r\n* The second parameter is the selector attached to the method\r\n* The last parameter is for all the arguments that the\r\nimplementation expects\r\n\r\nThe call to `objc_msgSend` should not be performed as a variadic\r\ncall but instead as if it had the same signature as the method\r\nthat should be called but with the two additional parameter,\r\n`self` and `op`, added first. The implementation of `objc_msgSend`\r\nwill jump to the method instead of calling it.\r\n\r\nBecause of the above, multiple versions exist of `objc_msgSend`.\r\nDepending on the return type of the method that is called the correct\r\nversion need to be used. This depends on the ABI. This is a list of\r\nfunctions and for which types they're used on OS X 64bit:\r\n\r\n* objc_msgSend_stret - Used for structs too large to be returned in\r\nregistries\r\n* objc_msgSend_fpret - Used for `long double`\r\n* objc_msgSend_fp2ret - Used for `_Complex long double`\r\n* objc_msgSend - Used for everything else"},"comment":{"url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/comments/120604106","html_url":"https://github.com/D-Programming-Language/dmd/pull/4321#issuecomment-120604106","issue_url":"https://api.github.com/repos/D-Programming-Language/dmd/issues/4321","id":120604106,"user":{"login":"jacob-carlborg","id":306980,"avatar_url":"https://avatars.githubusercontent.com/u/306980?v=3","gravatar_id":"","url":"https://api.github.com/users/jacob-carlborg","html_url":"https://github.com/jacob-carlborg","followers_url":"https://api.github.com/users/jacob-carlborg/followers","following_url":"https://api.github.com/users/jacob-carlborg/following{/other_user}","gists_url":"https://api.github.com/users/jacob-carlborg/gists{/gist_id}","starred_url":"https://api.github.com/users/jacob-carlborg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacob-carlborg/subscriptions","organizations_url":"https://api.github.com/users/jacob-carlborg/orgs","repos_url":"https://api.github.com/users/jacob-carlborg/repos","events_url":"https://api.github.com/users/jacob-carlborg/events{/privacy}","received_events_url":"https://api.github.com/users/jacob-carlborg/received_events","type":"User","site_admin":false},"created_at":"2015-07-11T11:06:10Z","updated_at":"2015-07-11T11:06:10Z","body":"Is it possible to do some trick with the makefile to first port one of them and then the other one?"}}