diff options
author | Adam Strzelecki <ono@java.pl> | 2015-06-02 21:29:28 +0200 |
---|---|---|
committer | Adam Strzelecki <ono@java.pl> | 2015-06-02 21:38:53 +0200 |
commit | 13b57dbc2f686ba9beb410ad9fef848926de38c5 (patch) | |
tree | 4f876def309e15da3baf0ad9f141e5f34b587995 /compiler/semstmts.nim | |
parent | 79c92603f505c388d370c5ef0dd8890e4e17e4e0 (diff) | |
download | Nim-13b57dbc2f686ba9beb410ad9fef848926de38c5.tar.gz |
Introduce {.noRewrite.} expr pragma disabling TR
Term rewriting macros/templates are currently greedy and they will rewrite as long as there is a match. So there was no way to ensure some rewrite happens only once, eg. when rewriting term to same term plus extra content. With new macro we can actually prevent further rewriting on marked expr or stmts, eg. with given example echo(...) will be rewritten just once: template pwnEcho{echo(x)}(x: expr) = {.noRewrite.}: echo("pwned!") echo "ab"
Diffstat (limited to 'compiler/semstmts.nim')
-rw-r--r-- | compiler/semstmts.nim | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index c355a5bf1..43cdca866 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1268,6 +1268,8 @@ proc semPragmaBlock(c: PContext, n: PNode): PNode = of wLocks: result = n result.typ = n.sons[1].typ + of wNoRewrite: + incl(result.flags, nfNoRewrite) else: discard proc semStaticStmt(c: PContext, n: PNode): PNode = |