A new fix for newLit
Upstream fix submitted here: https://github.com/nim-lang/Nim/pull/12542
This commit is contained in:
parent
2c9ca5dabb
commit
1c4293b3e7
|
@ -168,81 +168,101 @@ macro inspectType*(T: typed): untyped =
|
||||||
# FIXED NewLit
|
# FIXED NewLit
|
||||||
|
|
||||||
proc newLitFixed*(c: char): NimNode {.compileTime.} =
|
proc newLitFixed*(c: char): NimNode {.compileTime.} =
|
||||||
## produces a new character literal node.
|
## Produces a new character literal node.
|
||||||
result = newNimNode(nnkCharLit)
|
result = newNimNode(nnkCharLit)
|
||||||
result.intVal = ord(c)
|
result.intVal = ord(c)
|
||||||
|
|
||||||
proc newLitFixed*(i: int): NimNode {.compileTime.} =
|
proc newLitFixed*(i: int): NimNode {.compileTime.} =
|
||||||
## produces a new integer literal node.
|
## Produces a new integer literal node.
|
||||||
result = newNimNode(nnkIntLit)
|
result = newNimNode(nnkIntLit)
|
||||||
result.intVal = i
|
result.intVal = i
|
||||||
|
|
||||||
proc newLitFixed*(i: int8): NimNode {.compileTime.} =
|
proc newLitFixed*(i: int8): NimNode {.compileTime.} =
|
||||||
## produces a new integer literal node.
|
## Produces a new integer literal node.
|
||||||
result = newNimNode(nnkInt8Lit)
|
result = newNimNode(nnkInt8Lit)
|
||||||
result.intVal = i
|
result.intVal = i
|
||||||
|
|
||||||
proc newLitFixed*(i: int16): NimNode {.compileTime.} =
|
proc newLitFixed*(i: int16): NimNode {.compileTime.} =
|
||||||
## produces a new integer literal node.
|
## Produces a new integer literal node.
|
||||||
result = newNimNode(nnkInt16Lit)
|
result = newNimNode(nnkInt16Lit)
|
||||||
result.intVal = i
|
result.intVal = i
|
||||||
|
|
||||||
proc newLitFixed*(i: int32): NimNode {.compileTime.} =
|
proc newLitFixed*(i: int32): NimNode {.compileTime.} =
|
||||||
## produces a new integer literal node.
|
## Produces a new integer literal node.
|
||||||
result = newNimNode(nnkInt32Lit)
|
result = newNimNode(nnkInt32Lit)
|
||||||
result.intVal = i
|
result.intVal = i
|
||||||
|
|
||||||
proc newLitFixed*(i: int64): NimNode {.compileTime.} =
|
proc newLitFixed*(i: int64): NimNode {.compileTime.} =
|
||||||
## produces a new integer literal node.
|
## Produces a new integer literal node.
|
||||||
result = newNimNode(nnkInt64Lit)
|
result = newNimNode(nnkInt64Lit)
|
||||||
result.intVal = i
|
result.intVal = i
|
||||||
|
|
||||||
proc newLitFixed*(i: uint): NimNode {.compileTime.} =
|
proc newLitFixed*(i: uint): NimNode {.compileTime.} =
|
||||||
## produces a new unsigned integer literal node.
|
## Produces a new unsigned integer literal node.
|
||||||
result = newNimNode(nnkUIntLit)
|
result = newNimNode(nnkUIntLit)
|
||||||
result.intVal = BiggestInt(i)
|
result.intVal = BiggestInt(i)
|
||||||
|
|
||||||
proc newLitFixed*(i: uint8): NimNode {.compileTime.} =
|
proc newLitFixed*(i: uint8): NimNode {.compileTime.} =
|
||||||
## produces a new unsigned integer literal node.
|
## Produces a new unsigned integer literal node.
|
||||||
result = newNimNode(nnkUInt8Lit)
|
result = newNimNode(nnkUInt8Lit)
|
||||||
result.intVal = BiggestInt(i)
|
result.intVal = BiggestInt(i)
|
||||||
|
|
||||||
proc newLitFixed*(i: uint16): NimNode {.compileTime.} =
|
proc newLitFixed*(i: uint16): NimNode {.compileTime.} =
|
||||||
## produces a new unsigned integer literal node.
|
## Produces a new unsigned integer literal node.
|
||||||
result = newNimNode(nnkUInt16Lit)
|
result = newNimNode(nnkUInt16Lit)
|
||||||
result.intVal = BiggestInt(i)
|
result.intVal = BiggestInt(i)
|
||||||
|
|
||||||
proc newLitFixed*(i: uint32): NimNode {.compileTime.} =
|
proc newLitFixed*(i: uint32): NimNode {.compileTime.} =
|
||||||
## produces a new unsigned integer literal node.
|
## Produces a new unsigned integer literal node.
|
||||||
result = newNimNode(nnkUInt32Lit)
|
result = newNimNode(nnkUInt32Lit)
|
||||||
result.intVal = BiggestInt(i)
|
result.intVal = BiggestInt(i)
|
||||||
|
|
||||||
proc newLitFixed*(i: uint64): NimNode {.compileTime.} =
|
proc newLitFixed*(i: uint64): NimNode {.compileTime.} =
|
||||||
## produces a new unsigned integer literal node.
|
## Produces a new unsigned integer literal node.
|
||||||
result = newNimNode(nnkUInt64Lit)
|
result = newNimNode(nnkUInt64Lit)
|
||||||
result.intVal = BiggestInt(i)
|
result.intVal = BiggestInt(i)
|
||||||
|
|
||||||
proc newLitFixed*(b: bool): NimNode {.compileTime.} =
|
proc newLitFixed*(b: bool): NimNode {.compileTime.} =
|
||||||
## produces a new boolean literal node.
|
## Produces a new boolean literal node.
|
||||||
result = if b: bindSym"true" else: bindSym"false"
|
result = if b: bindSym"true" else: bindSym"false"
|
||||||
|
|
||||||
|
proc newLitFixed*(s: string): NimNode {.compileTime.} =
|
||||||
|
## Produces a new string literal node.
|
||||||
|
result = newNimNode(nnkStrLit)
|
||||||
|
result.strVal = s
|
||||||
|
|
||||||
|
when false:
|
||||||
|
# the float type is not really a distinct type as described in https://github.com/nim-lang/Nim/issues/5875
|
||||||
|
proc newLitFixed*(f: float): NimNode {.compileTime.} =
|
||||||
|
## Produces a new float literal node.
|
||||||
|
result = newNimNode(nnkFloatLit)
|
||||||
|
result.floatVal = f
|
||||||
|
|
||||||
proc newLitFixed*(f: float32): NimNode {.compileTime.} =
|
proc newLitFixed*(f: float32): NimNode {.compileTime.} =
|
||||||
## produces a new float literal node.
|
## Produces a new float literal node.
|
||||||
result = newNimNode(nnkFloat32Lit)
|
result = newNimNode(nnkFloat32Lit)
|
||||||
result.floatVal = f
|
result.floatVal = f
|
||||||
|
|
||||||
proc newLitFixed*(f: float64): NimNode {.compileTime.} =
|
proc newLitFixed*(f: float64): NimNode {.compileTime.} =
|
||||||
## produces a new float literal node.
|
## Produces a new float literal node.
|
||||||
result = newNimNode(nnkFloat64Lit)
|
result = newNimNode(nnkFloat64Lit)
|
||||||
result.floatVal = f
|
result.floatVal = f
|
||||||
|
|
||||||
proc newLitFixed*(s: string): NimNode {.compileTime.} =
|
when declared(float128):
|
||||||
## produces a new string literal node.
|
proc newLitFixed*(f: float128): NimNode {.compileTime.} =
|
||||||
result = newNimNode(nnkStrLit)
|
## Produces a new float literal node.
|
||||||
result.strVal = s
|
result = newNimNode(nnkFloat128Lit)
|
||||||
|
result.floatVal = f
|
||||||
|
|
||||||
|
proc newLitFixed*(arg: enum): NimNode {.compileTime.} =
|
||||||
|
result = newCall(
|
||||||
|
arg.type.getTypeInst[1],
|
||||||
|
newLitFixed(int(arg))
|
||||||
|
)
|
||||||
|
|
||||||
proc newLitFixed*[N,T](arg: array[N,T]): NimNode {.compileTime.}
|
proc newLitFixed*[N,T](arg: array[N,T]): NimNode {.compileTime.}
|
||||||
proc newLitFixed*[T](arg: seq[T]): NimNode {.compileTime.}
|
proc newLitFixed*[T](arg: seq[T]): NimNode {.compileTime.}
|
||||||
|
proc newLitFixed*[T](s: set[T]): NimNode {.compileTime.}
|
||||||
proc newLitFixed*(arg: tuple): NimNode {.compileTime.}
|
proc newLitFixed*(arg: tuple): NimNode {.compileTime.}
|
||||||
|
|
||||||
proc newLitFixed*(arg: object): NimNode {.compileTime.} =
|
proc newLitFixed*(arg: object): NimNode {.compileTime.} =
|
||||||
|
@ -250,23 +270,34 @@ proc newLitFixed*(arg: object): NimNode {.compileTime.} =
|
||||||
for a, b in arg.fieldPairs:
|
for a, b in arg.fieldPairs:
|
||||||
result.add nnkExprColonExpr.newTree( newIdentNode(a), newLitFixed(b) )
|
result.add nnkExprColonExpr.newTree( newIdentNode(a), newLitFixed(b) )
|
||||||
|
|
||||||
|
proc newLitFixed*(arg: ref object): NimNode {.compileTime.} =
|
||||||
|
## produces a new ref type literal node.
|
||||||
|
result = nnkObjConstr.newTree(arg.type.getTypeInst[1])
|
||||||
|
for a, b in fieldPairs(arg[]):
|
||||||
|
result.add nnkExprColonExpr.newTree(newIdentNode(a), newLitFixed(b))
|
||||||
|
|
||||||
proc newLitFixed*[N,T](arg: array[N,T]): NimNode {.compileTime.} =
|
proc newLitFixed*[N,T](arg: array[N,T]): NimNode {.compileTime.} =
|
||||||
result = nnkBracket.newTree
|
result = nnkBracket.newTree
|
||||||
for x in arg:
|
for x in arg:
|
||||||
result.add newLitFixed(x)
|
result.add newLitFixed(x)
|
||||||
|
|
||||||
proc newLitFixed*[T](arg: seq[T]): NimNode {.compileTime.} =
|
proc newLitFixed*[T](arg: seq[T]): NimNode {.compileTime.} =
|
||||||
var bracket = nnkBracket.newTree
|
let bracket = nnkBracket.newTree
|
||||||
for x in arg:
|
for x in arg:
|
||||||
bracket.add newLitFixed(x)
|
bracket.add newLitFixed(x)
|
||||||
|
result = nnkPrefix.newTree(
|
||||||
result = nnkCall.newTree(
|
bindSym"@",
|
||||||
nnkBracketExpr.newTree(
|
|
||||||
nnkAccQuoted.newTree( bindSym"@" ),
|
|
||||||
getTypeInst( bindSym"T" )
|
|
||||||
),
|
|
||||||
bracket
|
bracket
|
||||||
)
|
)
|
||||||
|
if arg.len == 0:
|
||||||
|
# add type cast for empty seq
|
||||||
|
var typ = getTypeInst(typeof(arg))[1]
|
||||||
|
result = newCall(typ,result)
|
||||||
|
|
||||||
|
proc newLitFixed*[T](s: set[T]): NimNode {.compileTime.} =
|
||||||
|
result = nnkCurly.newTree
|
||||||
|
for x in s:
|
||||||
|
result.add newLitFixed(x)
|
||||||
|
|
||||||
proc newLitFixed*(arg: tuple): NimNode {.compileTime.} =
|
proc newLitFixed*(arg: tuple): NimNode {.compileTime.} =
|
||||||
result = nnkPar.newTree
|
result = nnkPar.newTree
|
||||||
|
|
Loading…
Reference in New Issue