diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-04 16:46:16 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-04 16:46:16 -0600 |
| commit | 8d9bc5adbd9c3368295c7e7c920fb0c166f29c29 (patch) | |
| tree | 8eb85199aee7be0cbf2cfc5be958eb005dd0a017 | |
| parent | e77792ceb71cd85c2615d2f5136810bbd3cb302c (diff) | |
| download | nimterop-8d9bc5adbd9c3368295c7e7c920fb0c166f29c29.tar.gz nimterop-8d9bc5adbd9c3368295c7e7c920fb0c166f29c29.zip | |
Fix qualifiers, preproc only literals, remove _, struct field issue, print preproc output
| -rw-r--r-- | nimterop.nimble | 3 | ||||
| -rw-r--r-- | nimterop/getters.nim | 15 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 20 | ||||
| -rw-r--r-- | toast.nim | 2 |
4 files changed, 27 insertions, 13 deletions
diff --git a/nimterop.nimble b/nimterop.nimble index 3bfd982..a504ffc 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -19,6 +19,9 @@ proc execCmd(cmd:string)= task test, "Test": execCmd "nim c -r tests/tnimterop_c.nim" execCmd "nim cpp -r tests/tnimterop_cpp.nim" + when defined(windows): + execCmd "nim c -r tests/tmath.nim" + execCmd "nim cpp -r tests/tmath.nim" task installWithDeps, "install dependencies": for a in ["http://github.com/genotrance/nimtreesitter?subdir=treesitter", diff --git a/nimterop/getters.nim b/nimterop/getters.nim index 1e76429..e3e00c2 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -17,13 +17,18 @@ proc getType*(str: string): string = return "object" result = str.strip(chars={'_'}). - replace("unsigned ", "u"). + multiReplace([ + ("unsigned ", "cu"), + ("double ", "cdouble"), + ("long ", "clong"), + ]). replace(re"([u]?int[\d]+)_t", "$1") - if result == "uchar": - result = "cuchar" - elif result == "double": - result = "cdouble" + case result: + of "long": + result = "clong" + of "double": + result = "cdouble" proc getLit*(str: string): string = if str.contains(re"^[\-]?[\d]+$") or diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index 7876ca3..2233609 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -15,7 +15,7 @@ proc initGrammar() = proc () {.closure, locks: 0.} = let name = gStateRT.data[0].val.getIdentifier() - val = gStateRT.data[1].val + val = gStateRT.data[1].val.getLit() if name notin gStateRT.consts and val.nBl: gStateRT.consts.add(name) @@ -44,7 +44,7 @@ proc initGrammar() = proc () {.closure, locks: 0.} = var name = gStateRT.data[1].val.getIdentifier() - typ = gStateRT.data[0].val + typ = gStateRT.data[0].val.getIdentifier() if name notin gStateRT.types: gStateRT.types.add(name) @@ -58,11 +58,14 @@ proc initGrammar() = gStateRT.types.add(nname) gStateRT.typeStr &= &" {nname}* {{.importc: \"{prefix}{name}\", header: {gStateRT.currentHeader}, bycopy.}} = object\n" - for i in fstart .. gStateRT.data.len-fend: + var + i = fstart + while i < gStateRT.data.len-fend: let - ftyp = gStateRT.data[i].val + ftyp = gStateRT.data[i].val.getIdentifier() fname = gStateRT.data[i+1].val.getIdentifier() gStateRT.typeStr &= &" {fname}*: {ftyp}\n" + i += 2 # struct X {} gStateRT.grammar.add((""" @@ -86,7 +89,7 @@ proc initGrammar() = ) """, proc () {.closure, locks: 0.} = - pStructCommon(gStateRT.data[0].val, 1, 2, "struct ") + pStructCommon(gStateRT.data[0].val, 1, 0, "struct ") )) # typedef struct X {} @@ -113,7 +116,7 @@ proc initGrammar() = ) """, proc () {.closure, locks: 0.} = - pStructCommon(gStateRT.data[^1].val, 0, 3) + pStructCommon(gStateRT.data[^1].val, 0, 1) )) proc pEnumCommon(name: string, fstart, fend: int, prefix="") = @@ -231,7 +234,7 @@ proc initGrammar() = """, proc () {.closure, locks: 0.} = let - ftyp = gStateRT.data[0].val + ftyp = gStateRT.data[0].val.getIdentifier() fname = gStateRT.data[1].val fnname = fname.getIdentifier() @@ -242,13 +245,14 @@ proc initGrammar() = if gStateRT.data.len > 2: while i < gStateRT.data.len-1: let - ptyp = gStateRT.data[i].val + ptyp = gStateRT.data[i].val.getIdentifier() pname = gStateRT.data[i+1].val.getIdentifier() pout &= &"{pname}: {ptyp}," i += 2 if pout.len != 0 and pout[^1] == ',': pout = pout[0 .. ^2] + gStateRT.procs.add(fnname) if ftyp != "object": gStateRT.procStr &= &"proc {fnname}({pout}): {ftyp} {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n" else: @@ -100,6 +100,8 @@ proc process(path: string) = printLisp(root) elif gStateRT.pnim: printNim(path, root) + elif gStateRT.preprocess: + echo gStateRT.code proc main( mode = modeDefault, |
