From 955f6f3e3983de4bef09ba6deeba77fa2ff735b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Wed, 4 Apr 2018 01:22:22 +0200 Subject: [PATCH] added kind proc to NimSym --- compiler/ast.nim | 2 +- compiler/condsyms.nim | 1 + compiler/vm.nim | 4 ++++ compiler/vmdef.nim | 1 + compiler/vmgen.nim | 1 + lib/core/macros.nim | 3 +++ tests/macros/tgensym.nim | 2 ++ 7 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index a28a7e7e33811..2ad6936573425 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -632,7 +632,7 @@ type mCpuEndian, mHostOS, mHostCPU, mBuildOS, mBuildCPU, mAppType, mNaN, mInf, mNegInf, mCompileOption, mCompileOptionArg, - mNLen, mNChild, mNSetChild, mNAdd, mNAddMultiple, mNDel, mNKind, + mNLen, mNChild, mNSetChild, mNAdd, mNAddMultiple, mNDel, mNKind, mNSymKind, mNIntVal, mNFloatVal, mNSymbol, mNIdent, mNGetType, mNStrVal, mNSetIntVal, mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo, mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr, diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 0be2899be0cd1..85ebdd7bf3fab 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -113,3 +113,4 @@ proc initDefines*() = defineSymbol("nimHasRunnableExamples") defineSymbol("nimNewDot") defineSymbol("nimHasNilChecks") + defineSymbol("nimSymKind") diff --git a/compiler/vm.nim b/compiler/vm.nim index 6ea6f14924905..686bf9392501b 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1233,6 +1233,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = decodeB(rkInt) regs[ra].intVal = ord(regs[rb].node.kind) c.comesFromHeuristic = regs[rb].node.info + of opcNSymKind: + decodeB(rkInt) + regs[ra].intVal = ord(regs[rb].node.sym.kind) + c.comesFromHeuristic = regs[rb].node.info of opcNIntVal: decodeB(rkInt) let a = regs[rb].node diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index dd4bc5060e630..ccb8ed6f07b39 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -79,6 +79,7 @@ type opcNAdd, opcNAddMultiple, opcNKind, + opcNSymKind, opcNIntVal, opcNFloatVal, opcNSymbol, diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index bcfaeef230ca0..b9f7bc3d68705 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1080,6 +1080,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mNAdd: genBinaryABC(c, n, dest, opcNAdd) of mNAddMultiple: genBinaryABC(c, n, dest, opcNAddMultiple) of mNKind: genUnaryABC(c, n, dest, opcNKind) + of mNSymKind: genUnaryABC(c, n, dest, opcNSymKind) of mNIntVal: genUnaryABC(c, n, dest, opcNIntVal) of mNFloatVal: genUnaryABC(c, n, dest, opcNFloatVal) of mNSymbol: genUnaryABC(c, n, dest, opcNSymbol) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index d09f5f93387c4..ff16f44edc951 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -198,6 +198,9 @@ proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.} proc symbol*(n: NimNode): NimSym {.magic: "NSymbol", noSideEffect.} proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect.} +when defined(nimSymKind): + proc kind*(s: NimSym): NimSymKind {.magic: "NSymKind", noSideEffect.} + proc getType*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.} ## with 'getType' you can access the node's `type`:idx:. A Nim type is ## mapped to a Nim AST too, so it's slightly confusing but it means the same diff --git a/tests/macros/tgensym.nim b/tests/macros/tgensym.nim index 9551689392e0f..f96b76681dcad 100644 --- a/tests/macros/tgensym.nim +++ b/tests/macros/tgensym.nim @@ -28,6 +28,7 @@ macro async2(prc: untyped): untyped = # -> iterator nameIter(): FutureBase {.closure.} = # Changing this line to: newIdentNode($prc[0].ident & "Iter") # will make it work. var iteratorNameSym = genSym(nskIterator, $prc[0].ident & "Iter") + assert iteratorNamSym.symbol.kind == nskIterator #var iteratorNameSym = newIdentNode($prc[0].ident & "Iter") var procBody = prc[6].convertReturns(retFutureSym) @@ -42,6 +43,7 @@ macro async2(prc: untyped): untyped = var varNameIter = newVarStmt(varNameIterSym, iteratorNameSym) outerProcBody.add varNameIter var varFirstSym = genSym(nskVar, "first") + assert iteratorNamSym.symbol.kind == nskVar var varFirst = newVarStmt(varFirstSym, newCall(varNameIterSym)) outerProcBody.add varFirst