Skip to content

Instantly share code, notes, and snippets.

@flaviut
Last active Aug 29, 2015
Embed
What would you like to do?
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