diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-03-26 04:36:26 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-03-26 04:36:26 +0300 |
commit | 6216046bc6b2794d15705f5d2621f602bda636c4 (patch) | |
tree | 8a70def0c70dc634ee92d1144c4b12e661042343 /compiler/idgen.nim | |
parent | bc2eb0ea9b8a806ddafdb7726c94363fbd2c2f20 (diff) | |
download | Nim-6216046bc6b2794d15705f5d2621f602bda636c4.tar.gz |
genSym support for hygienic macros and templates.
example: template hygienic(val: expr) = var `*x` = val echo `*x` *x was chosen as mnemonic for "opposite of public" and thus private
Diffstat (limited to 'compiler/idgen.nim')
-rw-r--r-- | compiler/idgen.nim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/idgen.nim b/compiler/idgen.nim index 6dc19474d..d2e322796 100644 --- a/compiler/idgen.nim +++ b/compiler/idgen.nim @@ -11,7 +11,7 @@ import idents, strutils, os, options -var gFrontEndId, gBackendId*: int +var gFrontEndId, gBackendId*, genSymBaseId*: int const debugIds* = false @@ -25,7 +25,7 @@ proc registerID*(id: PIdObj) = when debugIDs: if id.id == -1 or ContainsOrIncl(usedIds, id.id): InternalError("ID already used: " & $id.id) - + proc getID*(): int {.inline.} = result = gFrontEndId inc(gFrontEndId) @@ -34,6 +34,9 @@ proc backendId*(): int {.inline.} = result = gBackendId inc(gBackendId) +proc genSym*(basename: string): PIdent = + result = getIdent(basename & $genSymBaseId) + proc setId*(id: int) {.inline.} = gFrontEndId = max(gFrontEndId, id + 1) |