diff options
author | cooldome <cdome@bk.ru> | 2018-11-21 20:30:03 +0000 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-11-21 21:30:03 +0100 |
commit | 086676782a6053158cc6da14bc65961205c4b014 (patch) | |
tree | 4f599c3f2dd615bc4065f61df8ece68ca21a4afe /compiler | |
parent | 1cc8b7814d3a744a384d42b0f9f5a3bc65e39fe9 (diff) | |
download | Nim-086676782a6053158cc6da14bc65961205c4b014.tar.gz |
Add isInstanceOf for generic procs to the macros module (#9730)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 3 | ||||
-rw-r--r-- | compiler/condsyms.nim | 2 | ||||
-rw-r--r-- | compiler/vm.nim | 11 | ||||
-rw-r--r-- | compiler/vmdef.nim | 3 | ||||
-rw-r--r-- | compiler/vmgen.nim | 1 |
5 files changed, 17 insertions, 3 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index bb0f95acd..6a73df3c7 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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 diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index ab89481b8..9a4c1701c 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -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) diff --git a/compiler/vm.nim b/compiler/vm.nim index 5b5b807bb..7e7ec8903 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -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: diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 25ace3cdd..493078f74 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -147,7 +147,8 @@ type opcTypeTrait, opcMarshalLoad, opcMarshalStore, opcToNarrowInt, - opcSymOwner + opcSymOwner, + opcSymIsInstantiationOf TBlock* = object label*: PSym diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index c37ec7c6b..e52f460d2 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -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) |