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 hidden or 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 | |
| macro void(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)) | |
| #CurlyExpr | |
| # Call | |
| # Ident !"abc" | |
| # Command | |
| # Ident !"int" | |
| # Ident !"a" | |
| # Command | |
| # Ident !"string" | |
| # Ident !"b" | |
| # Command | |
| # Ident !"echo" | |
| # StrLit test | |
| # Command | |
| # Ident !"echo" | |
| # StrLit test1 | |
| void abc(int a, string b){ | |
| echo("test"), | |
| echo("test1"), | |
| echo($a), | |
| echo(b), | |
| } | |
| abc(1, "passed string") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment