Skip to content

Instantly share code, notes, and snippets.

@flaviut
Last active August 29, 2015 13:59
Show Gist options
  • 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
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