Get symbol kind (#7491)
This commit is contained in:
parent
1ee5f1e36a
commit
6baca58693
13 changed files with 319 additions and 272 deletions
|
|
@ -632,10 +632,11 @@ 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,
|
||||
mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent,
|
||||
mNBindSym, mLocals, mNCallSite,
|
||||
mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl,
|
||||
mNHint, mNWarning, mNError,
|
||||
|
|
|
|||
|
|
@ -113,3 +113,4 @@ proc initDefines*() =
|
|||
defineSymbol("nimHasRunnableExamples")
|
||||
defineSymbol("nimNewDot")
|
||||
defineSymbol("nimHasNilChecks")
|
||||
defineSymbol("nimSymKind")
|
||||
|
|
|
|||
|
|
@ -768,8 +768,10 @@ macro `=~`(x: PNode, pat: untyped): bool =
|
|||
|
||||
var conds = newTree(nnkBracket)
|
||||
m(x, pat, conds)
|
||||
when declared(macros.toNimIdent):
|
||||
result = nestList(toNimIdent"and", conds)
|
||||
when compiles(nestList(ident"and", conds)):
|
||||
result = nestList(ident"and", conds)
|
||||
#elif declared(macros.toNimIdent):
|
||||
# result = nestList(toNimIdent"and", conds)
|
||||
else:
|
||||
result = nestList(!"and", conds)
|
||||
|
||||
|
|
|
|||
|
|
@ -892,7 +892,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
|||
regs[ra].node = if a.sym.ast.isNil: newNode(nkNilLit)
|
||||
else: copyTree(a.sym.ast)
|
||||
else:
|
||||
stackTrace(c, tos, pc, errFieldXNotFound, "symbol")
|
||||
stackTrace(c, tos, pc, errGenerated, "node is not a symbol")
|
||||
of opcEcho:
|
||||
let rb = instr.regB
|
||||
if rb == 1:
|
||||
|
|
@ -1233,6 +1233,14 @@ 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)
|
||||
let a = regs[rb].node
|
||||
if a.kind == nkSym:
|
||||
regs[ra].intVal = ord(a.sym.kind)
|
||||
else:
|
||||
stackTrace(c, tos, pc, errGenerated, "node is not a symbol")
|
||||
c.comesFromHeuristic = regs[rb].node.info
|
||||
of opcNIntVal:
|
||||
decodeB(rkInt)
|
||||
let a = regs[rb].node
|
||||
|
|
@ -1295,9 +1303,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
|||
decodeB(rkNode)
|
||||
createStr regs[ra]
|
||||
let a = regs[rb].node
|
||||
if a.kind in {nkStrLit..nkTripleStrLit}: regs[ra].node.strVal = a.strVal
|
||||
elif a.kind == nkCommentStmt: regs[ra].node.strVal = a.comment
|
||||
else: stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
|
||||
case a.kind
|
||||
of {nkStrLit..nkTripleStrLit}:
|
||||
regs[ra].node.strVal = a.strVal
|
||||
of nkCommentStmt:
|
||||
regs[ra].node.strVal = a.comment
|
||||
of nkIdent:
|
||||
regs[ra].node.strVal = a.ident.s
|
||||
of nkSym:
|
||||
regs[ra].node.strVal = a.sym.name.s
|
||||
else:
|
||||
stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
|
||||
of opcSlurp:
|
||||
decodeB(rkNode)
|
||||
createStr regs[ra]
|
||||
|
|
@ -1387,17 +1403,6 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
|||
else:
|
||||
regs[ra].node = newNodeI(nkIdent, c.debug[pc])
|
||||
regs[ra].node.ident = getIdent(regs[rb].node.strVal)
|
||||
of opcIdentToStr:
|
||||
decodeB(rkNode)
|
||||
let a = regs[rb].node
|
||||
createStr regs[ra]
|
||||
regs[ra].node.info = c.debug[pc]
|
||||
if a.kind == nkSym:
|
||||
regs[ra].node.strVal = a.sym.name.s
|
||||
elif a.kind == nkIdent:
|
||||
regs[ra].node.strVal = a.ident.s
|
||||
else:
|
||||
stackTrace(c, tos, pc, errFieldXNotFound, "ident")
|
||||
of opcSetType:
|
||||
if regs[ra].kind != rkNode:
|
||||
internalError(c.debug[pc], "cannot set type")
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ type
|
|||
opcNAdd,
|
||||
opcNAddMultiple,
|
||||
opcNKind,
|
||||
opcNSymKind,
|
||||
opcNIntVal,
|
||||
opcNFloatVal,
|
||||
opcNSymbol,
|
||||
|
|
@ -101,7 +102,6 @@ type
|
|||
opcNGetLine, opcNGetColumn, opcNGetFile,
|
||||
opcEqIdent,
|
||||
opcStrToIdent,
|
||||
opcIdentToStr,
|
||||
opcGetImpl,
|
||||
|
||||
opcEcho,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -1125,7 +1126,6 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
|||
else:
|
||||
localError(n.info, "invalid bindSym usage")
|
||||
of mStrToIdent: genUnaryABC(c, n, dest, opcStrToIdent)
|
||||
of mIdentToStr: genUnaryABC(c, n, dest, opcIdentToStr)
|
||||
of mEqIdent: genBinaryABC(c, n, dest, opcEqIdent)
|
||||
of mEqNimrodNode: genBinaryABC(c, n, dest, opcEqNimrodNode)
|
||||
of mSameNodeType: genBinaryABC(c, n, dest, opcSameNodeType)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue