mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 13:30:33 +00:00
add nodeId proc to macros (#11456)
* add nodeId proc to macros * add doc comment. * fix typo
This commit is contained in:
committed by
Andreas Rumpf
parent
f8000d4ba1
commit
188ce5f3ee
@@ -666,7 +666,8 @@ type
|
||||
mInstantiationInfo, mGetTypeInfo,
|
||||
mNimvm, mIntDefine, mStrDefine, mBoolDefine, mRunnableExamples,
|
||||
mException, mBuiltinType, mSymOwner, mUncheckedArray, mGetImplTransf,
|
||||
mSymIsInstantiationOf
|
||||
mSymIsInstantiationOf, mNodeId
|
||||
|
||||
|
||||
# things that we can evaluate safely at compile time, even if not asked for it:
|
||||
const
|
||||
|
||||
@@ -87,6 +87,7 @@ proc initDefines*(symbols: StringTableRef) =
|
||||
defineSymbol("nimHasDefault")
|
||||
defineSymbol("nimMacrosSizealignof")
|
||||
defineSymbol("nimNoZeroExtendMagic")
|
||||
defineSymbol("nimMacrosGetNodeId")
|
||||
for f in low(Feature)..high(Feature):
|
||||
defineSymbol("nimHas" & $f)
|
||||
|
||||
|
||||
@@ -1472,6 +1472,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
regs[ra].node = copyNode(a)
|
||||
else:
|
||||
stackTrace(c, tos, pc, errFieldXNotFound & "ident")
|
||||
of opcNodeId:
|
||||
decodeB(rkInt)
|
||||
when defined(useNodeIds):
|
||||
regs[ra].intVal = regs[rb].node.id
|
||||
else:
|
||||
regs[ra].intVal = -1
|
||||
of opcNGetType:
|
||||
let rb = instr.regB
|
||||
let rc = instr.regC
|
||||
|
||||
@@ -99,7 +99,7 @@ type
|
||||
opcNNewNimNode, opcNCopyNimNode, opcNCopyNimTree, opcNDel, opcGenSym,
|
||||
|
||||
opcNccValue, opcNccInc, opcNcsAdd, opcNcsIncl, opcNcsLen, opcNcsAt,
|
||||
opcNctPut, opcNctLen, opcNctGet, opcNctHasNext, opcNctNext,
|
||||
opcNctPut, opcNctLen, opcNctGet, opcNctHasNext, opcNctNext, opcNodeId,
|
||||
|
||||
opcSlurp,
|
||||
opcGorge,
|
||||
|
||||
@@ -1324,6 +1324,8 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||
c.gABx(n, opcNodeToReg, a, a)
|
||||
c.genAsgnPatch(arg, a)
|
||||
c.freeTemp(a)
|
||||
of mNodeId:
|
||||
c.genUnaryABC(n, dest, opcNodeId)
|
||||
else:
|
||||
# mGCref, mGCunref,
|
||||
globalError(c.config, n.info, "cannot generate code for: " & $m)
|
||||
|
||||
@@ -1426,6 +1426,12 @@ proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} =
|
||||
if n.kind == nnkIntLit: n.intVal != 0
|
||||
else: n == bindSym"true" # hacky solution for now
|
||||
|
||||
when defined(nimMacrosGetNodeId):
|
||||
proc nodeID*(n: NimNode): int {.magic: NodeId.}
|
||||
## Returns the id of ``n``, when the compiler has been compiled
|
||||
## with the flag ``-d:useNodeids``, otherwise returns ``-1``. This
|
||||
## proc is for the purpose to debug the compiler only.
|
||||
|
||||
macro expandMacros*(body: typed): untyped =
|
||||
## Expands one level of macro - useful for debugging.
|
||||
## Can be used to inspect what happens when a macro call is expanded,
|
||||
|
||||
Reference in New Issue
Block a user