Allow SomeSignedInt and SomeUnsignedInt as literal operand
This commit is contained in:
parent
9d2b382c5d
commit
d689650c3f
|
@ -1,5 +1,5 @@
|
||||||
# Stint
|
# Stint
|
||||||
# Copyright 2018 Status Research & Development GmbH
|
# Copyright 2018-2024 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
#
|
#
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
@ -21,8 +21,14 @@ macro make_mixed_types_ops(op: untyped, ResultTy: untyped, sign: static[Signedne
|
||||||
result = newStmtList()
|
result = newStmtList()
|
||||||
|
|
||||||
# Workaround for int{lit} in quote do block
|
# Workaround for int{lit} in quote do block
|
||||||
let intLit = nnkCurlyExpr.newTree(
|
let
|
||||||
newIdentNode("int"),
|
intLit = nnkCurlyExpr.newTree(
|
||||||
|
newIdentNode("SomeSignedInt"),
|
||||||
|
newIdentNode("lit")
|
||||||
|
)
|
||||||
|
|
||||||
|
uintLit = nnkCurlyExpr.newTree(
|
||||||
|
newIdentNode("SomeUnsignedInt"),
|
||||||
newIdentNode("lit")
|
newIdentNode("lit")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,12 +40,12 @@ macro make_mixed_types_ops(op: untyped, ResultTy: untyped, sign: static[Signedne
|
||||||
)
|
)
|
||||||
|
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
proc `op`*[bits: static[int]](a: StUint[bits], b: `intLit`): `ResultTy` {.inline.}=
|
proc `op`*[bits: static[int]](a: StUint[bits], b: `uintLit`): `ResultTy` {.inline.}=
|
||||||
`op`(a, b.stuint(bits))
|
`op`(a, b.stuint(bits))
|
||||||
|
|
||||||
if switchInputs:
|
if switchInputs:
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
proc `op`*[bits: static[int]](a: `intLit`, b: StUint[bits]): `ResultTy` {.inline.}=
|
proc `op`*[bits: static[int]](a: `uintLit`, b: StUint[bits]): `ResultTy` {.inline.}=
|
||||||
`op`(a.stuint(bits), b)
|
`op`(a.stuint(bits), b)
|
||||||
|
|
||||||
if sign != UintOnly:
|
if sign != UintOnly:
|
||||||
|
|
Loading…
Reference in New Issue