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

Alternative (and simpler) workflow for binding constants #296

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Alternative (and simpler) workflow for binding constants #296

wants to merge 2 commits into from

Conversation

yallop
Copy link
Owner

@yallop yallop commented May 4, 2015

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

enum color {
  red,
  blue,
  green
};

you might write:

module Types(T: Cstubs.TYPES) =
struct

  let colors_t = enum "color"
    [`Red, constant "red" int64;
     `Blue, constant "blue" int64;
     `Green, constant "green" int64]
end

Here's how to use the Types functor with the existing existing interface (see also #62):

  • Pass the Types functor to
    Cstubs.Types.write_c
    to generate a C program
  • Run the C program to generate an ML module of type Cstubs.TYPES.
  • Apply Types to the generated module to make the compile-time constants available to your program.

Here's how to use the Types functor with the new interface in this pull request:

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.

yallop added a commit that referenced this pull request May 7, 2016
Preparatory refactoring work for the simpler constant-binding interface (#296)
@yallop yallop closed this by deleting the head repository Sep 28, 2022
@yallop yallop reopened this Sep 28, 2022
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.

New constant function is hard to use.
1 participant