intVal works now on enum field symbols (#11403)
* intVal works now on enum field symbols * disable flakey titerators test
This commit is contained in:
parent
9230862534
commit
efbf43d4a9
4 changed files with 24 additions and 3 deletions
|
|
@ -1418,9 +1418,12 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
of opcNIntVal:
|
of opcNIntVal:
|
||||||
decodeB(rkInt)
|
decodeB(rkInt)
|
||||||
let a = regs[rb].node
|
let a = regs[rb].node
|
||||||
case a.kind
|
if a.kind in {nkCharLit..nkUInt64Lit}:
|
||||||
of nkCharLit..nkUInt64Lit: regs[ra].intVal = a.intVal
|
regs[ra].intVal = a.intVal
|
||||||
else: stackTrace(c, tos, pc, errFieldXNotFound & "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:
|
of opcNFloatVal:
|
||||||
decodeB(rkFloat)
|
decodeB(rkFloat)
|
||||||
let a = regs[rb].node
|
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
|
if dest.kind in {nkCharLit..nkUInt64Lit} and
|
||||||
regs[rb].kind in {rkInt}:
|
regs[rb].kind in {rkInt}:
|
||||||
dest.intVal = regs[rb].intVal
|
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:
|
else:
|
||||||
stackTrace(c, tos, pc, errFieldXNotFound & "intVal")
|
stackTrace(c, tos, pc, errFieldXNotFound & "intVal")
|
||||||
of opcNSetFloatVal:
|
of opcNSetFloatVal:
|
||||||
|
|
|
||||||
|
|
@ -226,8 +226,10 @@ proc kind*(n: NimNode): NimNodeKind {.magic: "NKind", noSideEffect.}
|
||||||
## returns the `kind` of the node `n`.
|
## returns the `kind` of the node `n`.
|
||||||
|
|
||||||
proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.}
|
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.}
|
proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.}
|
||||||
|
## Returns a float from any floating point literal.
|
||||||
|
|
||||||
{.push warnings: off.}
|
{.push warnings: off.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
target: "c"
|
target: "c"
|
||||||
|
disabled: true
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Timers are always flakey on the testing servers.
|
||||||
|
|
||||||
import coro
|
import coro
|
||||||
include system/timers
|
include system/timers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,3 +93,14 @@ static:
|
||||||
quit("may not be evaluated")
|
quit("may not be evaluated")
|
||||||
|
|
||||||
assert( (myLit or bottom()) == myLit )
|
assert( (myLit or bottom()) == myLit )
|
||||||
|
|
||||||
|
type
|
||||||
|
Fruit = enum
|
||||||
|
apple
|
||||||
|
banana
|
||||||
|
orange
|
||||||
|
|
||||||
|
macro foo(x: typed) =
|
||||||
|
doAssert Fruit(x.intVal) == banana
|
||||||
|
|
||||||
|
foo(banana)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue