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

Cannot capitalize symbols using rename and renameCallback. #67

Open
nayr7 opened this issue Apr 25, 2023 · 1 comment
Open

Cannot capitalize symbols using rename and renameCallback. #67

nayr7 opened this issue Apr 25, 2023 · 1 comment

Comments

@nayr7
Copy link

nayr7 commented Apr 25, 2023

Hello! This is a very nice tool for C interop, unfortunately while wrapping libvips, I tried to make futhark generate nep1 compliant symbols using rename and renameCallback but capitalizing anything but the first word of a symbol is ineffective.

Example:

  • rename "VipsPrecision", "PrecisionTest" generates Precisiontest
  • rename "VipsPrecision", "precisiontest" generates precisiontest

Setup:
Distro: Ubuntu 23.04
Nim Version: 1.6.10
Futhark Version: 0.9.1

Code Prototype:

when defined(useFuthark):
  import futhark
  importc:
    outputPath currentSourcePath.parentDir / "private/generated.nim"

    sysPath "/usr/lib/clang/15/include"
    sysPath "/usr/include/glib-2.0"
    sysPath "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
    path "/usr/local/include/vips"

    rename "VipsPrecision", "PrecisionTest"                           # does not work
    rename "vips_object_get_type", "vipsObjectGetType1" # does not work
    "vips.h"

else:
  include private/generated

Ideally we should be able to tell futhark to generate nep1 compliant symbols for us through a define option, but this is merely a convenience and we should be able to use rename and renameCallback for this, if only they did work ...

@PMunch
Copy link
Owner

PMunch commented Jun 13, 2023

The reason why this doesn't work is that Futhark internally uses these identifiers in a hash table. So the representation that is kept is the most cleaned version (capital letters kept, all underscores removed, and all other letters made lowercase). Since Nim is style agnostic this shouldn't make a difference to how you can use the code, but it can make it a bit more confusing to read the documentation or code generated.

In order to fix this I think it would be best to create a table of identifiers to "pretty names" and then as the code is about to be written substitute the names for these ones. This should give the wanted effect at the lowest overhead.

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

No branches or pull requests

2 participants