Alternative (and simpler) workflow for binding constants#296
Conversation
yallop
added a commit
that referenced
this pull request
May 7, 2016
Preparatory refactoring work for the simpler constant-binding interface (#296)
This file contains hidden or 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
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.
This pull request adds a second way of binding compile-time constants such as enumeration constants, macro values, struct offsets, union sizes, etc..
Bindings written using the old interface can be reused without change. For example, to create a type corresponding to the following C enum declaration
you might write:
Here's how to use the
Typesfunctor with the existing existing interface (see also #62):Typesfunctor toCstubs.Types.write_c
to generate a C program
Cstubs.TYPES.Typesto the generated module to make the compile-time constants available to your program.Here's how to use the
Typesfunctor with the new interface in this pull request:Typesfunctor toCstubs_structs.Easy.write_c
and
Cstubs_structs.Easy.write_ml
to generate C stubs and an ML module of type
Cstubs.TYPES.Typesto the generated module to make the compile-time constants available to your program.There's a tradeoff: the new interface is easier to integrate into a build, since the dependencies are less linear. The existing interface generates slightly faster code, since it inlines the values of the C constants into the ML program.
(This isn't quite ready for merge: it doesn't yet support binding the same constant multiple times under different types.)
Closes #266.