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
This commit is contained in:
parent
bc2eb0ea9b
commit
6216046bc6
6 changed files with 34 additions and 70 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue