diff options
author | Araq <rumpf_a@web.de> | 2012-08-24 01:18:03 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-24 01:18:03 +0200 |
commit | c7ba6f5eb6f555ae650417c6f3bf9cdc0bad1427 (patch) | |
tree | e76ddea5dc65e48b16854fa69905f5618998acc1 /lib/core | |
parent | bdf3bee05510718581510cb78fa70ca183039d55 (diff) | |
download | Nim-c7ba6f5eb6f555ae650417c6f3bf9cdc0bad1427.tar.gz |
implemented 'bind' for macros
Diffstat (limited to 'lib/core')
-rwxr-xr-x | lib/core/macros.nim | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 1881faf63..d02aba0ca 100755 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -91,7 +91,7 @@ type const nnkLiterals* = {nnkCharLit..nnkNilLit} nnkCallKinds* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand, - nnkCallStrLit} + nnkCallStrLit} # Nodes should be reference counted to make the `copy` operation very fast! # However, this is difficult to achieve: modify(n[0][1]) should propagate to @@ -185,6 +185,10 @@ proc newIdentNode*(i: string): PNimrodNode {.compileTime.} = ## creates an identifier node from `i` result = newNimNode(nnkIdent) result.ident = !i + +proc bindSym*(ident: string): PNimrodNode {.magic: "NGetBoundSym".} + ## creates a node that binds `ident` to a symbol node. The bound symbol + ## needs to be predeclared in a ``bind`` statement! proc toStrLit*(n: PNimrodNode): PNimrodNode {.compileTime.} = ## converts the AST `n` to the concrete Nimrod code and wraps that @@ -249,6 +253,14 @@ proc expectLen*(n: PNimrodNode, len: int) {.compileTime.} = ## compilation aborts with an error message. This is useful for writing ## macros that check its number of arguments. if n.len != len: error("macro expects a node with " & $len & " children") + +proc newCall*(theProc: PNimrodNode, + args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = + ## produces a new call node. `theProc` is the proc that is called with + ## the arguments ``args[0..]``. + result = newNimNode(nnkCall) + result.add(theProc) + result.add(args) proc newCall*(theProc: TNimrodIdent, args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = |