Last active
August 29, 2015 13:59
-
-
Save flaviut/10515205 to your computer and use it in GitHub Desktop.
C in nimrod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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