Re: Thinking (again) about an Objective-C bridge
Bruce Mitchener <[email protected]>
| Newsgroups | gmane.comp.lang.dylan.gwydion.devel |
|---|---|
| Message-ID | <CA+esKjNuQPnHkem6hFMpMctp1bOM-3H-SWF7B_0NZK8zkmnrEg@mail.gmail.com> |
Maybe I'm having a failure of imagination, but I'm having trouble seeing a
macro doing something like:
objc/send(receiver, someMessage)
into:
%call-c-function("objc_msgSend")
(id :: <raw-machine-word>, sel :: <raw-machine-word>)
=> (obj :: <raw-machine-word>)
(primitive-unwrap-machine-word(c.raw-class),
primitive-unwrap-machine-word(s.raw-selector))
end;
Much less handling:
objc/send(receiver, someMessage: arg, withValue: value)
How do you see that working?
I wouldn't want it doing the string concatenations at run-time. It'd be
nice if we could avoid the selector lookups at each invocation of the call
as well.
- Bruce
On Fri, Jun 14, 2013 at 10:25 AM, Bruce Hoult <[email protected]> wrote:
> Ideally, what you want is:
>
> - grab the symbols for the method and additional argument names
> - convert to strings and concatenate
> - create a global variable with that name (prefixed) to hold the selector
> value.
> - add the var and string to a hash table (or generate code) to look up the
> selector value at program startup
>
> I don't think there's anything there that Dylan macros can't do.
>
>
> On Fri, Jun 14, 2013 at 3:07 PM, Bruce Mitchener <
> [email protected]> wrote:
>
>> One of the issues to solve in doing an Objective-C bridge for Dylan is
>> how to represent a method invocation on the Dylan side.
>>
>> In C, we have %call-c-function, which looks like:
>>
>> %call-c-function (?name:expression, #key ?c-modifiers:expression = "")
>> (?parameters:*) => (?results:*)
>> (?arguments:*)
>> end;
>>
>> In LispWorks, they use this sort of syntax:
>>
>> (invoke window "close")
>> (invoke box "setWidth:height:" 10 20)
>>
>> In ClozureCL, this is the syntax:
>>
>> (send w :set-alpha-value 0.5)
>> (send v :mouse p :in-rect r)
>>
>> In Python:
>>
>> anObject.modifyArg_andAnother_(arg1, arg2)
>>
>> Overall, I like the approach used by ClozureCL as it seems much more
>> natural and more like the Objective-C that one would see. They've also got
>> variants of sending to the superclass, sending when a structure is
>> returned, etc. Having the keywords and the arguments alternate makes it
>> nicely readable (much more so than the LispWorks example).
>>
>> In ClozureCL, a lot of the work is done by macros, but I don't think our
>> macros in Dylan are powerful enough to do the same work. So what can we get
>> away with? We don't want a lot of work being done at run-time as we'd like
>> for this to be as efficient as possible.
>>
>> My thinking is that we might need a custom converter, much like
>> %call-c-function has, with the corresponding compiler support. I'd love to
>> be proved wrong though, so what thoughts do any of you have on this?
>>
>> - Bruce
>>
>>
>> --
>> This message has been scanned for viruses and
>> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and
>> is
>> believed to be clean.
>> _______________________________________________
>> hackers mailing list
>> [email protected]
>> https://lists.opendylan.org/mailman/listinfo/hackers
>>
>>
>
> _______________________________________________
> hackers mailing list
> [email protected]
> https://lists.opendylan.org/mailman/listinfo/hackers
>
>
_______________________________________________
hackers mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/hackers