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

VM-level FFI architecture #19

Open
hawkw opened this issue Mar 16, 2015 · 3 comments
Open

VM-level FFI architecture #19

hawkw opened this issue Mar 16, 2015 · 3 comments

Comments

@hawkw
Copy link
Owner

hawkw commented Mar 16, 2015

I'd love for the VM to contain a native foreign-function interface. Ideally, it should be possible to link in and execute functions from arbitrary compiled native C code, but there should definitely at least be a way to access core C library functions.

@hawkw hawkw self-assigned this Mar 16, 2015
@hawkw hawkw added this to the svm v0.3.0 milestone Mar 16, 2015
@hawkw
Copy link
Owner Author

hawkw commented Mar 16, 2015

I don't know very much about how a foreign-function interface works - this is an advanced topic we weren't able to cover in CMPSC420. Hopefully @janyljumadinova can offer some advice.

@hawkw
Copy link
Owner Author

hawkw commented Mar 16, 2015

Here's some documentation on C FFI in Rust. Might be helpful.

@hawkw
Copy link
Owner Author

hawkw commented Apr 9, 2015

The potential issue with providing low-level core OS functionality through hooks into libc rather than through hand-rolled fake syscalls on the VM (which seems like the other option here) is that a lot of the C standard library functions return C stuff. Currently, the VM has no idea what to do with a pointer or a struct, and it's likely that any Scheme programs that want to use FFI would have the same problem.

The options at this point are either to add VM instructions for working with Weird C Things directly, which breaks compatibility with other Scheme implementations (which is problematic if I want to claim to be 100% R6RS-compliant and if I want to implement my standard library by compiling the standard lib from some other Scheme implementation (as discussed in #16)); or, to give the FFI the ability to somehow munge Weird C Things into something the VM understands (i.e. breaking apart a struct into a list or what have you).

The main drawback of the second approach is that some C things lose semantic meaning if destructured - if I turn a pointer into a number, I now just have a weird number, while if I go get whatever it points to and put it on the VM stack, I no longer have the thing that the C library I'm talking to thinks that I have. There's also the issue that there would have to be some way to un-munge Weird C Things back into their original form for when I want to send them back to other C functions; which means that there would be a need to ensure anything mangled into a Seax-friendly form would have to be demangled deterministically into the same thing. This could be tricky.

Neither of these options are exactly good, and I still have to weigh the entire idea of providing core OS functions via FFI vs. making my own "fake syscalls" on the VM (which is what I believe Java does essentially). Hmm.

I'll have to think about this (and probably do more research).

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

No branches or pull requests

1 participant