-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support ADTs #10
Merged
Merged
Support ADTs #10
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extend contexts to prepare for deriving via TH Rust structs/unions and enums to match ADTs. All old examples still work.
It will need to be reused for deriving Rust types.
The Rust codegen that remains is the `impl`s.
Added support for generating the right pairs of `From<...> for ...` impl's for the ADT case. There are still a handful of small TODOs before this is testable though.
I've manually verified that the generated code compiles.
The one major hiccup: Haskell's FFI supports a very limited number of types. Consequently, I'm shoving any other type into a pointer (alloca/with) and passing the pointer instead. For complex return values, that means passing in a pointer and assigning to that pointer.
Added a context for unboxed types too.
Couple points now that I've got an MVP:
|
Couple points now that I've got an MVP:
|
Replaced uses of 'Into' with a custom 'MarshalInto'. Obviously this isn't great, but it does mean I can make the struct impl's I want (without conflicting with some more general impl).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Extend contexts support passing Haskell ADTs directly into Rust enums. The core insights are that
Storable
lets us reorganize what exactly gets passed through the FFI. On the Rust side, we need to make that explicit by having an intermediate#[repr(C)]
type and some conversions to and from that type.Storable
instances forPtr a
andFunPtr a
do not impose superclassStorable
constraints)When merged, this PR will go a long way to helping on #1.
#[repr(C)]
unions/structs corresponding to the derivedStorable
instances for ADTsInto
/From
trait impls for converting between the#[repr(C)]
union/struct form and the enum form