Skip to content

Commit

Permalink
Allow SomeSignedInt and SomeUnsignedInt as literal operand
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jun 12, 2024
1 parent 9d2b382 commit d689650
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions stint/literals_stint.nim
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -21,10 +21,16 @@ 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"),
newIdentNode("lit")
)
let
intLit = nnkCurlyExpr.newTree(
newIdentNode("SomeSignedInt"),
newIdentNode("lit")
)

uintLit = nnkCurlyExpr.newTree(
newIdentNode("SomeUnsignedInt"),
newIdentNode("lit")
)

if sign != IntOnly:
let ResultTy = if not isInputType: ResultTy
Expand All @@ -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:
Expand Down

0 comments on commit d689650

Please sign in to comment.