add nodeId proc to macros (#11456)
* add nodeId proc to macros * add doc comment. * fix typo
This commit is contained in:
parent
f8000d4ba1
commit
188ce5f3ee
6 changed files with 18 additions and 2 deletions
|
|
@ -666,7 +666,8 @@ type
|
||||||
mInstantiationInfo, mGetTypeInfo,
|
mInstantiationInfo, mGetTypeInfo,
|
||||||
mNimvm, mIntDefine, mStrDefine, mBoolDefine, mRunnableExamples,
|
mNimvm, mIntDefine, mStrDefine, mBoolDefine, mRunnableExamples,
|
||||||
mException, mBuiltinType, mSymOwner, mUncheckedArray, mGetImplTransf,
|
mException, mBuiltinType, mSymOwner, mUncheckedArray, mGetImplTransf,
|
||||||
mSymIsInstantiationOf
|
mSymIsInstantiationOf, mNodeId
|
||||||
|
|
||||||
|
|
||||||
# things that we can evaluate safely at compile time, even if not asked for it:
|
# things that we can evaluate safely at compile time, even if not asked for it:
|
||||||
const
|
const
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ proc initDefines*(symbols: StringTableRef) =
|
||||||
defineSymbol("nimHasDefault")
|
defineSymbol("nimHasDefault")
|
||||||
defineSymbol("nimMacrosSizealignof")
|
defineSymbol("nimMacrosSizealignof")
|
||||||
defineSymbol("nimNoZeroExtendMagic")
|
defineSymbol("nimNoZeroExtendMagic")
|
||||||
|
defineSymbol("nimMacrosGetNodeId")
|
||||||
for f in low(Feature)..high(Feature):
|
for f in low(Feature)..high(Feature):
|
||||||
defineSymbol("nimHas" & $f)
|
defineSymbol("nimHas" & $f)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1472,6 +1472,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
regs[ra].node = copyNode(a)
|
regs[ra].node = copyNode(a)
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, errFieldXNotFound & "ident")
|
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:
|
of opcNGetType:
|
||||||
let rb = instr.regB
|
let rb = instr.regB
|
||||||
let rc = instr.regC
|
let rc = instr.regC
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ type
|
||||||
opcNNewNimNode, opcNCopyNimNode, opcNCopyNimTree, opcNDel, opcGenSym,
|
opcNNewNimNode, opcNCopyNimNode, opcNCopyNimTree, opcNDel, opcGenSym,
|
||||||
|
|
||||||
opcNccValue, opcNccInc, opcNcsAdd, opcNcsIncl, opcNcsLen, opcNcsAt,
|
opcNccValue, opcNccInc, opcNcsAdd, opcNcsIncl, opcNcsLen, opcNcsAt,
|
||||||
opcNctPut, opcNctLen, opcNctGet, opcNctHasNext, opcNctNext,
|
opcNctPut, opcNctLen, opcNctGet, opcNctHasNext, opcNctNext, opcNodeId,
|
||||||
|
|
||||||
opcSlurp,
|
opcSlurp,
|
||||||
opcGorge,
|
opcGorge,
|
||||||
|
|
|
||||||
|
|
@ -1324,6 +1324,8 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
c.gABx(n, opcNodeToReg, a, a)
|
c.gABx(n, opcNodeToReg, a, a)
|
||||||
c.genAsgnPatch(arg, a)
|
c.genAsgnPatch(arg, a)
|
||||||
c.freeTemp(a)
|
c.freeTemp(a)
|
||||||
|
of mNodeId:
|
||||||
|
c.genUnaryABC(n, dest, opcNodeId)
|
||||||
else:
|
else:
|
||||||
# mGCref, mGCunref,
|
# mGCref, mGCunref,
|
||||||
globalError(c.config, n.info, "cannot generate code for: " & $m)
|
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
|
if n.kind == nnkIntLit: n.intVal != 0
|
||||||
else: n == bindSym"true" # hacky solution for now
|
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 =
|
macro expandMacros*(body: typed): untyped =
|
||||||
## Expands one level of macro - useful for debugging.
|
## Expands one level of macro - useful for debugging.
|
||||||
## Can be used to inspect what happens when a macro call is expanded,
|
## Can be used to inspect what happens when a macro call is expanded,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue