Add isInstanceOf for generic procs to the macros module (#9730)

This commit is contained in:
cooldome 2018-11-21 20:30:03 +00:00 • committed by Andreas Rumpf
commit 086676782a
8 changed files with 46 additions and 3 deletions

View file

@ -656,7 +656,8 @@ type
mNHint, mNWarning, mNError,
mInstantiationInfo, mGetTypeInfo,
mNimvm, mIntDefine, mStrDefine, mRunnableExamples,
mException, mBuiltinType, mSymOwner, mUncheckedArray, mGetImplTransf
mException, mBuiltinType, mSymOwner, mUncheckedArray, mGetImplTransf,
mSymIsInstantiationOf
# things that we can evaluate safely at compile time, even if not asked for it:
const

View file

@ -86,7 +86,7 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimUncheckedArrayTyp")
defineSymbol("nimHasTypeof")
defineSymbol("nimErrorProcCanHaveBody")
defineSymbol("nimHasInstantiationOfInMacro")
defineSymbol("nimHasNilSeqs")
for f in low(Feature)..high(Feature):
defineSymbol("nimHas" & $f)

View file

@ -960,6 +960,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
regs[ra].node.flags.incl nfIsRef
else:
stackTrace(c, tos, pc, "node is not a symbol")
of opcSymIsInstantiationOf:
decodeBC(rkInt)
let a = regs[rb].node
let b = regs[rc].node
if a.kind == nkSym and a.sym.kind in skProcKinds and
b.kind == nkSym and b.sym.kind in skProcKinds:
regs[ra].intVal =
if sfFromGeneric in a.sym.flags and a.sym.owner == b.sym: 1
else: 0
else:
stackTrace(c, tos, pc, "node is not a proc symbol")
of opcEcho:
let rb = instr.regB
if rb == 1:

View file

@ -147,7 +147,8 @@ type
opcTypeTrait,
opcMarshalLoad, opcMarshalStore,
opcToNarrowInt,
opcSymOwner
opcSymOwner,
opcSymIsInstantiationOf
TBlock* = object
label*: PSym

View file

@ -1148,6 +1148,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of mGetImpl: genUnaryABC(c, n, dest, opcGetImpl)
of mGetImplTransf: genUnaryABC(c, n, dest, opcGetImplTransf)
of mSymOwner: genUnaryABC(c, n, dest, opcSymOwner)
of mSymIsInstantiationOf: genBinaryABC(c, n, dest, opcSymIsInstantiationOf)
of mNChild: genBinaryABC(c, n, dest, opcNChild)
of mNSetChild: genVoidABC(c, n, dest, opcNSetChild)
of mNDel: genVoidABC(c, n, dest, opcNDel)