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

[WIP] Added foreign proc def #371

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

jimbxb
Copy link
Collaborator

@jimbxb jimbxb commented Dec 30, 2022

Closes #366

@jimbxb jimbxb marked this pull request as ready for review December 30, 2022 03:32
@jimbxb
Copy link
Collaborator Author

jimbxb commented Jan 29, 2023

This is unfinished. I'd like to make it such that the order of which resources are specified is the order they're passed to the foreign proc. I think I can also make the parsing a little cleaner.

@pschachte
Copy link
Owner

If we want this to be fairly general (ie, able to interface to pretty much any C function), then it's not just the order of resources that needs to be flexible. It should also be possible to interleave the resources among the positional parameters in any order. Also, we should probably support pass by reference for outputs. Perhaps a Wybe in/out parameter should to translated to a single pass-by-reference C parameter.

But maybe it's better to handle the simple cases first, and extend it in later PRs as time and inspiration dictate.

@jimbxb
Copy link
Collaborator Author

jimbxb commented Jan 31, 2023

Interleaving can just be done in the verbose way, like:

def foreign c interleave(x, y) use foo {
    foreign c interleave(x, foo, y)
}

I don't think there's a very clean way of doing this in the shorthand definition form.

Now that I think about it, we should probably require parameters have their types specified because there's no way of inferring them :)

@pschachte
Copy link
Owner

Yes, types must definitely be specified for all parameters.

Offhand, we could support resources interleaved with normal arguments by forbidding a use clause in the definition, and instead allowing the use keyword to appear in front of a parameter spec, in which case the parameter name is instead interpreted as a resource name (and omitting the type).

Supporting return by reference, while continuing to support normal C return, seems like a trickier issue.

As you say, none of this is really necessary, since you can do without this feature by using explicit foreign calls. But it would definitely be a convenience for people interfacing to C code.

@jimbxb jimbxb marked this pull request as draft April 9, 2023 12:24
@jimbxb
Copy link
Collaborator Author

jimbxb commented Apr 9, 2023

Converting to draft while I havent made the relevant changes required.

@jimbxb jimbxb changed the title Added foreign proc def [WIP] Added foreign proc def Nov 29, 2023
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

Successfully merging this pull request may close these issues.

Improve the foreign interface by allowing for foreign functions to be declared
2 participants