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

Add C++ backend. #47

Merged
merged 3 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/genny.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import genny/internal, genny/languages/c, genny/languages/nim,
genny/languages/node, genny/languages/python, macros, strformat
import genny/internal, genny/languages/c, genny/languages/cpp,
genny/languages/nim, genny/languages/node, genny/languages/python, macros,
strformat

template discard2(f: untyped): untyped =
when(compiles do: discard f):
Expand Down Expand Up @@ -36,6 +37,7 @@ macro exportConstsTyped(body: typed) =
exportConstPy(sym)
exportConstNode(sym)
exportConstC(sym)
exportConstCpp(sym)

template exportConsts*(body: untyped) =
## Exports a list of constants.
Expand All @@ -58,6 +60,7 @@ macro exportEnumsTyped(body: typed) =
exportEnumPy(sym)
exportEnumNode(sym)
exportEnumC(sym)
exportEnumCpp(sym)

template exportEnums*(body: untyped) =
## Exports a list of enums.
Expand Down Expand Up @@ -114,6 +117,7 @@ proc procTyped(
exportProcPy(procSym, owner, prefixes)
exportProcNode(procSym, owner, prefixes)
exportProcC(procSym, owner, prefixes)
exportProcCpp(procSym, owner, prefixes)

macro exportProcsUntyped(body: untyped) =
result = newNimNode(nnkStmtList)
Expand Down Expand Up @@ -173,6 +177,7 @@ macro exportObjectTyped(body: typed) =
exportObjectPy(sym, constructor)
exportObjectNode(sym, constructor)
exportObjectC(sym, constructor)
exportObjectCpp(sym, constructor)

if procsBlock[1].len > 0:
var procsSeen: seq[string]
Expand All @@ -191,6 +196,9 @@ macro exportObjectTyped(body: typed) =
exportProcPy(procSym, sym, prefixes)
exportProcNode(procSym, sym, prefixes)
exportProcC(procSym, sym, prefixes)
exportProcCpp(procSym, sym, prefixes)

exportCloseObjectCpp()

template exportObject*(sym, body: untyped) =
## Exports an object, with these sections:
Expand Down Expand Up @@ -225,10 +233,13 @@ macro exportSeqTyped(body: typed) =
exportSeqPy(sym)
exportSeqNode(sym)
exportSeqC(sym)
exportSeqCpp(sym)

for entry in body.asStmtList()[1 .. ^1]:
procTyped(entry, sym)

exportCloseObjectCpp()

template exportSeq*(sym, body: untyped) =
## Exports a regular sequence.
## * procs section
Expand Down Expand Up @@ -299,6 +310,7 @@ macro exportRefObjectTyped(body: typed) =
exportRefObjectPy(sym, fields, constructor)
exportRefObjectNode(sym, fields, constructor)
exportRefObjectC(sym, fields, constructor)
exportRefObjectCpp(sym, fields, constructor)

if procsBlock[1].len > 0:
var procsSeen: seq[string]
Expand All @@ -317,6 +329,9 @@ macro exportRefObjectTyped(body: typed) =
exportProcPy(procSym, sym, prefixes)
exportProcNode(procSym, sym, prefixes)
exportProcC(procSym, sym, prefixes)
exportProcCpp(procSym, sym, prefixes)

exportCloseObjectCpp()

template exportRefObject*(sym, body: untyped) =
## Exports a ref object, with these sections:
Expand All @@ -333,3 +348,4 @@ macro writeFiles*(dir, lib: static[string]) =
writePy(dir, lib)
writeNode(dir, lib)
writeC(dir, lib)
writeCpp(dir, lib)
Loading