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

Possible to override the definitions created by nimterop? [low priority feature request] #56

Closed
kaushalmodi opened this issue Jan 21, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@kaushalmodi
Copy link

Hello,

This feature request is a spin-off off #50.

I was wondering if something like this can be made to work:

import nimterop/cimport

# ...

const
  xlmIncludePath = getEnv("XCELIUM_ROOT") / ".." / "include"
static:
  doAssert fileExists(xlmIncludePath / "svdpi.h")
  doAssert fileExists(xlmIncludePath / "svdpi_compatibility.h")

const
  headersvdpiLocal = xlmIncludePath / "svdpi.h"
type
  svOpenArrayHandle* = pointer
proc svGetArrElemPtr*(a1: svOpenArrayHandle; indx1: cint): pointer {.
    importc: "svGetArrElemPtr", header: headersvdpiLocal.}
proc svGetArrElemPtr1*(a1: svOpenArrayHandle; indx1: cint): pointer {.
    importc: "svGetArrElemPtr1", header: headersvdpiLocal.}
proc svGetArrElemPtr2*(a1: svOpenArrayHandle; indx1: cint; indx2: cint): pointer {.
    importc: "svGetArrElemPtr2", header: headersvdpiLocal.}
proc svGetArrElemPtr3*(a1: svOpenArrayHandle; indx1: cint; indx2: cint; indx3: cint): pointer {.
    importc: "svGetArrElemPtr3", header: headersvdpiLocal.}

cAddSearchDir(xlmIncludePath)
cImport(cSearchPath("svdpi.h"))

The idea is that cImport skips defining svOpenArrayHandle, svGetArrElemPtr, etc. which already got defined before cImport got called.

Without that, right now I get the below expected error:

/home/kmodi/stow/pkgs/nim/devel/lib/core/macros.nim(528, 3) Error: redefinition of 'svOpenArrayHandle'; previous declaration here: ../../svdpi.nim(22, 3)

So nimterop needs to check if an identifier is already defined, and proceed adding its definition only if that identifier doesn't already exist. Is that possible?

@kaushalmodi kaushalmodi changed the title Possible to override the definitions created by nimterop? [feature request] Possible to override the definitions created by nimterop? [low priority feature request] Jan 21, 2019
@genotrance
Copy link
Collaborator

There's no way to find out what's declared already to tell toast to skip those identifiers. But it may be possible to get the AST of the generated code and skip adding things that are already system.defined().

Needs some AST magic but just might be possible. Worthwhile cause nimterop fixes may introduce a symbol that was previous skipped, breaking a wrapper author's workarounds.

@genotrance genotrance added the enhancement New feature or request label Jan 21, 2019
genotrance added a commit that referenced this issue Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants