Skip to content

Instantly share code, notes, and snippets.

@micklat
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micklat/9009095 to your computer and use it in GitHub Desktop.
Save micklat/9009095 to your computer and use it in GitHub Desktop.

improve the automation of low-level C bindings

Desirable skills: Knowledge of C

Description: Nimrod's c2nim tool helps create nimrod bindings for C libraries. However, c2nim does not parse the whole C language, and is not currently supposed to import whole APIs into nimrod mechanically, but rather to serve as a starting point for manual definition of interfaces to C libraries. c2nim is particularly effective in dealing with C's preprocessor macros, but is not currently capable of parsing many C header files.

Make c2nim accept more C declarations than it currently does, and produce corresponding Nimrod declarations. This can be done either by directly filling-in the missing capabilities, or by interfacing it with a mature tool for parsing C code, such as LLVM's CLang or the GCC-XML tool. If one of these tools is used, then it is expected that it would not suffice by itself, but rather augment the current c2nim parser, since these tools have their own limitations. A possible implementation might pass the header file once through gcc-xml to parse C declarations, and would use the current c2nim parser on lines that start with '#' to parse preprocessor definitions. c2nim would then process the parsed headers and produce constants, types, macros and proc declarations similar to those that it produces now.

Although c2nim currently converts function implementations (and not only declarations), this functionality is outside the scope of this task.

Tasks: Depending on the chosen implementation technique, the tasks would be either:

  • detect individual deficiencies in c2nim support for .h files and fix them or:
  • interface with a feature-complete parser for C, such as that of GCC or CLANG.
  • refactor c2nim so that it can generate declarations from the parsed output of the above parser, rather than directly from .h files as it currently does.
  • combine the output from the previous task with the declarations that c2nim produces for preprocessor macros.

Difficulty: Medium

Bonus Points: support, in addition, a few common c++ constructs that c2nim does not currently support.

Mentor: Araq (@Araq)

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