Skip to content

Commit

Permalink
added kind proc to NimSym
Browse files Browse the repository at this point in the history
  • Loading branch information
krux02 committed Apr 3, 2018
1 parent f108e89 commit 955f6f3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ proc initDefines*() =
defineSymbol("nimHasRunnableExamples")
defineSymbol("nimNewDot")
defineSymbol("nimHasNilChecks")
defineSymbol("nimSymKind")
4 changes: 4 additions & 0 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions compiler/vmdef.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type
opcNAdd,
opcNAddMultiple,
opcNKind,
opcNSymKind,
opcNIntVal,
opcNFloatVal,
opcNSymbol,
Expand Down
1 change: 1 addition & 0 deletions compiler/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/macros/tgensym.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ macro async2(prc: untyped): untyped =
# -> iterator nameIter(): FutureBase {.closure.} = <proc_body>
# 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)

Expand All @@ -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

Expand Down

0 comments on commit 955f6f3

Please sign in to comment.