Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantics for varargs of different types to ccall. #32758

Closed
ninjaaron opened this issue Aug 1, 2019 · 6 comments
Closed

Add semantics for varargs of different types to ccall. #32758

ninjaaron opened this issue Aug 1, 2019 · 6 comments

Comments

@ninjaaron
Copy link
Contributor

ninjaaron commented Aug 1, 2019

I'm working on a PR, #32748, for a macro wraps ccall in more Julia-like syntax. An issue that's being discussed a lot is the accommodation of varargs of different types. I had the impression from @vtjnash that this was supported by foreigncall, but in retrospect, it's possible I misunderstood what he was saying.

I'm not in a position to implement this myself without first learning Scheme and LLVM. I should really do those things, but it may not be the most efficient way to get this change in.

@ninjaaron
Copy link
Contributor Author

ninjaaron commented Aug 1, 2019

And as for syntax, I have no strong opinions, but I can suggest this as a starting point for the conversation, based on what we currently have:

ccall(:printf, Cint, (Cstring, (Cstring, Cint)...), "%s = %d\n", "value of x", x)

It ain't pretty, but it's backward compatible.

@vtjnash
Copy link
Member

vtjnash commented Aug 2, 2019

sort of a duplicate of #6661, but I'm not a particular fan of that syntax proposal anymore

@StefanKarpinski
Copy link
Member

The semicolon-based alternative syntax would be this:

ccall(:printf, Cint, (Cstring; Cstring, Cint), "%s = %d\n", "value of x", x)

Note that this could potentially be combined with an ellipsis to indicate that all varargs arguments are of the same type, e.g.:

ccall(:printf, Cint, (Cstring; Cint...), "%d = %d + %d\n", x + y, x, y)
ccall(:printf, Cint, (Cstring, Cint...), "%d = %d + %d\n", x + y, x, y) # might mean the same thing

It's unclear how that would be written in the @ccall syntax since arguments and their types are paired—this syntax leverages the fact that the type tuple and the args are separate.

@ninjaaron ninjaaron mentioned this issue Aug 2, 2019
@vtjnash
Copy link
Member

vtjnash commented Aug 3, 2019

I do kind of like that. Seems like @ccall would just work the exact same way in that case, since the parser sees these forms as basically the same just inside different wrappers (:tuple vs :call).

Note that you need a , there still to make that a tuple during parsing:

ccall(:printf, Cint, (Cstring,; Cstring, Cint), "%s = %d\n", "value of x", x)
``

@ninjaaron
Copy link
Contributor Author

ninjaaron commented Aug 3, 2019

Looks like it sees a tuple if there is a comma somewhere on either side of the semicolon. Otherwise, it sees a "block".

julia> :( (this; that) ).head
:block

julia> :( (this; that, theother) ).head
:tuple

@StefanKarpinski
Copy link
Member

Seems like we could also teach ccall to understand the expressions sequence form, although that’s a bit of a cheat and would probably allow other unintentional syntaxes too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants