Skip to content

Add varargs to defines, defines as C imports, and CLI mangle option #222

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

Merged
merged 11 commits into from
Dec 6, 2022

Conversation

elcritch
Copy link
Contributor

Hey! Thanks for keeping c2nim up and working!

I decided to take the time to fix/tweak a few things that I run into a lot and figure others might find them useful.

  • Importing C #defines macro functions as external C functions using importc pragma
  • Import C #defines constants as external C var's using importc
  • Add VARARGS support for #define macro functions supporting templates
    • Note this doesn't create a proper macro to handle the varargs but it creates filler args: seq[untyped]
  • Add VARARGS support for #define macro functions supporting C imports with {.varargs.} pragma
  • Add command line option to pass mangle directives (useful for all those uint8_t types from <stdint.h>)

I'll work on adding the test cases I'm using tomorrow. I haven't run the test suite yet, but I'll do that tomorrow. However, I wanted to get this up so I wouldn't forget to PR it later.

Also, any feedback/changes would be great. I tried to follow the coding style as much as I could. Still I'm not entirely familiar with the correct PNode structures for some of the items. Particularly if there's a "proper" way to handle some of the constructs.

@Araq
Copy link
Member

Araq commented Sep 17, 2021

Looks very good, will review it in more detail later. Feel free to ping me again in order to remind me.

@elcritch
Copy link
Contributor Author

Ok, nice. I used it on some bigger files and there is one issue so far. The "import as proc" seems to only spit out the first import if there's multiple definitions in a row without comments in between. That'll need fixed. I'll put it on my docket for next week.

@Araq Araq merged commit 3dfd742 into nim-lang:master Dec 6, 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.

2 participants