Allow SomeSignedInt and SomeUnsignedInt as literal operand

This commit is contained in:
jangko 2024-06-12 08:49:42 +07:00
parent 9d2b382c5d
commit d689650c3f
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,5 @@
# Stint
# Copyright 2018 Status Research & Development GmbH
# Copyright 2018-2024 Status Research & Development GmbH
# Licensed under either of
#
# * 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()
# Workaround for int{lit} in quote do block
let intLit = nnkCurlyExpr.newTree(
newIdentNode("int"),
let
intLit = nnkCurlyExpr.newTree(
newIdentNode("SomeSignedInt"),
newIdentNode("lit")
)
uintLit = nnkCurlyExpr.newTree(
newIdentNode("SomeUnsignedInt"),
newIdentNode("lit")
)
@ -34,12 +40,12 @@ macro make_mixed_types_ops(op: untyped, ResultTy: untyped, sign: static[Signedne
)
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))
if switchInputs:
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)
if sign != UintOnly: