mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
intVal works now on enum field symbols (#11403)
* intVal works now on enum field symbols * disable flakey titerators test
This commit is contained in:
committed by
Andreas Rumpf
parent
9230862534
commit
efbf43d4a9
@@ -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:
|
||||
|
||||
@@ -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.}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
discard """
|
||||
target: "c"
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
# Timers are always flakey on the testing servers.
|
||||
|
||||
import coro
|
||||
include system/timers
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user