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

Truffle cext sketch #3803

Merged
merged 2 commits into from
Apr 15, 2016
Merged

Truffle cext sketch #3803

merged 2 commits into from
Apr 15, 2016

Conversation

chrisseaton
Copy link
Contributor

Depends on graalvm/sulong#157

This is a sketch of how I think we could support the Ruby C API using interop. When we used Truffle C, we had several intrinsic nodes, so Ruby functionality implemented in Truffle C. I guess we want to avoid that? Otherwise we'll have to define an API that Sulong provides to register those intrinsics. If we can do it with just normal interop that's probably better.

We have a header that describes the Ruby C API.

We then have a library that implements that in terms of the interop functions that Sulong can provide. That library is compiled into a .su and shipped with JRuby+Truffle, and loaded whenever the first C extension is loaded.

Most of the C API is implemented by INVOKEing methods that are implemented by JRuby+Truffle, in a Truffle::CExt module, that is exported by default as ruby_cext.

There are a lot of open questions here.

If the return type of interop functions like READ are void*, to read it do I do *((int*) READ, or (int) READ? What do I do with variadic arguments to pass them on a second time? RSTRING_PTR needs to provide what appears to be a char* but actually allows me to intercept read and write operations, and that needs to work with pointer arithmetic. We solved all these with Truffle C, so they're all do-able.

@chrisseaton chrisseaton self-assigned this Apr 14, 2016
@chrisseaton chrisseaton added this to the truffle-dev milestone Apr 14, 2016
extern VALUE Qnil;
VALUE get_Qfalse();
VALUE get_Qtrue();
VALUE get_Qnil();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make them functions? Could the constructor below assign them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an extern variable escapes. I'm not even sure my static void *ruby_cext; below is going to PE.

@chrisseaton chrisseaton merged commit fce464d into truffle-head-next Apr 15, 2016
@chrisseaton chrisseaton deleted the truffle-cext-sketch branch April 15, 2016 17:50
@enebo enebo added this to the Non-Release milestone Dec 7, 2017
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.

None yet

3 participants