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

Use C function pointer argument names in proc types #117

Open
jon-edward opened this issue Aug 8, 2024 · 2 comments
Open

Use C function pointer argument names in proc types #117

jon-edward opened this issue Aug 8, 2024 · 2 comments

Comments

@jon-edward
Copy link
Contributor

Currently, futhark replaces argument names of function pointers with a[some number].

This can be seen with the simple example:

// ./include/testlib.h

typedef struct ContainsFunctionPointer {
    int (*myFunc)(int descriptiveParameter1, int descriptiveParameter2);
} ContainsFunctionPointer;
# ./test.nim

import std/os

import futhark

const currentDir = currentSourcePath.parentDir

importc:
    outputPath currentDir / "generated.nim"
    path currentDir / "include"
    "testLib.h"

The result of generated.nim after nim r -d:nodeclguards ./test.nim (no declaration guards for readability, the existence or nonexistence of this flag does not change the resulting type):

# ./generated.nim

type
  struct_ContainsFunctionPointer* {.pure, inheritable, bycopy.} = object
    myFunc*: proc (a0: cint; a1: cint): cint {.cdecl.}
  ContainsFunctionPointer* = struct_ContainsFunctionPointer

It might be nicer for library usage if the resulting generated.nim was something more like:

type
  struct_ContainsFunctionPointer* {.pure, inheritable, bycopy.} = object
    myFunc*: proc (descriptiveParameter1: cint; descriptiveParameter2: cint): cint {.cdecl.}
  ContainsFunctionPointer* = struct_ContainsFunctionPointer

For users of the wrapper, it will offer more insight into what kind of objects should be passed to procs (more than just type information).

@jon-edward
Copy link
Contributor Author

This seems to be an issue with opir, perhaps at

futhark/src/opir.nim

Lines 322 to 326 in 783f2af

var aname = ""
if funcDecl.isSome:
aname = funcDecl.get.Cursor_getArgument(i).getName
if aname == "":
aname = "a" & $i

@AmjadHD
Copy link

AmjadHD commented Aug 31, 2024

This needs to be passed a cursor

futhark/src/opir.nim

Lines 126 to 127 in 8b55098

of CXType_FunctionProto, CXType_FunctionNoProto:
ct.genProcDecl()

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