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

C ABI support #89

Open
guysv opened this issue Sep 22, 2020 · 4 comments
Open

C ABI support #89

guysv opened this issue Sep 22, 2020 · 4 comments
Labels
core library Related to Oak's core library enhancement New feature or request foreign function interface Related to Oak's FFI system

Comments

@guysv
Copy link

guysv commented Sep 22, 2020

Oak's FFI supports calling C functions, only if the target function follows the oak FFI protocol (e.g. receive a vm object, and interact with it)

As Oak is advertised to be more portable than C (not relevant, but still), being able to call any C function is a useful feature.

I guess a better description for the feature would be: "Be compatible with C's calling conventions on a variety of C-capable architectures"

Any thoughts on that?

@kevinramharak
Copy link
Contributor

I made a similar suggestion in a different issue. Any ideas on how to implement this? And what the rules of such an interaction should be?

@guysv
Copy link
Author

guysv commented Sep 26, 2020

Well, for the C backend, implementation is simple. All we need to do is to define some syntax that maps between oak's types and C types, and generate C function calls. That way don't even care about the interworking of certain C calling conventions, we rely on the C compiler for the implementation.

I guess this feature should not be part of the standard, as it ranges from being tricky to implement (go) to impossible without major dependencies (typescript).

@adam-mcdaniel adam-mcdaniel added core library Related to Oak's core library enhancement New feature or request foreign function interface Related to Oak's FFI system labels Sep 26, 2020
@kevinramharak
Copy link
Contributor

I'm not sure I understand. Would this require additional syntax in the Oak language? I think It should be somewhat abstract so that each backend can implement it. For example:

  • Pop arguments off the tape into memory allocated at runtime
  • transfer execution to native function while passing the arguments
  • Push return value back on the tape

These are abstract definitions thus they can be implemented by any backend.

@guysv
Copy link
Author

guysv commented Sep 26, 2020

Yes! I was thinking about generalizing the new behavior too! So, to summerize:

  1. define a new syntax to call "native" functions
  2. every backend gets to define what "native" means
    • e.g. for typescript: call a typescript function.

I guess you'll also want to pass some metadata to the compiler (cdecl/stdcall pops into mind)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core library Related to Oak's core library enhancement New feature or request foreign function interface Related to Oak's FFI system
Projects
None yet
Development

No branches or pull requests

3 participants