diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-06-05 14:55:47 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-06-05 14:55:47 +0200 |
commit | efbf43d4a9b9ffdee5db95749d0d992bc16bb350 (patch) | |
tree | 31843b75327e73eb41df0e09343757246282f53b | |
parent | 92308625347493b37951cb25e944c650a909565a (diff) | |
download | Nim-efbf43d4a9b9ffdee5db95749d0d992bc16bb350.tar.gz |
intVal works now on enum field symbols (#11403)
* intVal works now on enum field symbols * disable flakey titerators test
-rw-r--r-- | compiler/vm.nim | 11 | ||||
-rw-r--r-- | lib/core/macros.nim | 2 | ||||
-rw-r--r-- | tests/coroutines/titerators.nim | 3 | ||||
-rw-r--r-- | tests/macros/tmacro1.nim | 11 |
4 files changed, 24 insertions, 3 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 8b36b461b..4e8a34471 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1418,9 +1418,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of opcNIntVal: decodeB(rkInt) let a = regs[rb].node - case a.kind - of nkCharLit..nkUInt64Lit: regs[ra].intVal = a.intVal - else: stackTrace(c, tos, pc, errFieldXNotFound & "intVal") + if a.kind in {nkCharLit..nkUInt64Lit}: + regs[ra].intVal = a.intVal + elif a.kind == nkSym and a.sym.kind == skEnumField: + regs[ra].intVal = a.sym.position + else: + stackTrace(c, tos, pc, errFieldXNotFound & "intVal") of opcNFloatVal: decodeB(rkFloat) let a = regs[rb].node @@ -1692,6 +1695,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = if dest.kind in {nkCharLit..nkUInt64Lit} and regs[rb].kind in {rkInt}: dest.intVal = regs[rb].intVal + elif dest.kind == nkSym and dest.sym.kind == skEnumField: + stackTrace(c, tos, pc, "`intVal` cannot be changed for an enum symbol.") else: stackTrace(c, tos, pc, errFieldXNotFound & "intVal") of opcNSetFloatVal: diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 77e707464..87e9e4b94 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -226,8 +226,10 @@ proc kind*(n: NimNode): NimNodeKind {.magic: "NKind", noSideEffect.} ## returns the `kind` of the node `n`. proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.} + ## Returns an integer value from any integer literal or enum field symbol. proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.} + ## Returns a float from any floating point literal. {.push warnings: off.} diff --git a/tests/coroutines/titerators.nim b/tests/coroutines/titerators.nim index abcfbde43..d12a5debe 100644 --- a/tests/coroutines/titerators.nim +++ b/tests/coroutines/titerators.nim @@ -1,7 +1,10 @@ discard """ target: "c" +disabled: true """ +# Timers are always flakey on the testing servers. + import coro include system/timers diff --git a/tests/macros/tmacro1.nim b/tests/macros/tmacro1.nim index 5388e861c..844738c82 100644 --- a/tests/macros/tmacro1.nim +++ b/tests/macros/tmacro1.nim @@ -93,3 +93,14 @@ static: quit("may not be evaluated") assert( (myLit or bottom()) == myLit ) + +type + Fruit = enum + apple + banana + orange + +macro foo(x: typed) = + doAssert Fruit(x.intVal) == banana + +foo(banana) |