Skip to content

Instantly share code, notes, and snippets.

@flaviut
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flaviut/10515205 to your computer and use it in GitHub Desktop.
Save flaviut/10515205 to your computer and use it in GitHub Desktop.
C in nimrod
import macros
template ctypedef(name: expr): stmt {.immediate.} =
macro `name`(body: expr): stmt {.immediate.} =
let head = body[0]
let procname = head[0]
var params = newSeq[PNimrodNode]()
for node in head.children:
case node.kind
of nnkCommand:
params.add(newIdentDefs(node[1], node[0]))
else:
continue
params = newIdentNode("void") & params
var inside = newSeq[PNimrodNode]()
for i in 1..(body.len - 1):
inside.add(body[i])
result = newProc(procname, params, newStmtList(inside))
ctypedef void
void abc(int a, string b){
echo("test"),
echo("test1"),
echo($a),
echo($b),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment