Skip to content

Commit

Permalink
feat: empty constructor for BigUInt() defaults to zero
Browse files Browse the repository at this point in the history
chore: address minor TODO regarding source locations
  • Loading branch information
achidlow committed Mar 22, 2024
1 parent 6f79b8a commit c02079b
Show file tree
Hide file tree
Showing 24 changed files with 250 additions and 233 deletions.
2 changes: 1 addition & 1 deletion examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
state_proxies/StateProxy 87 83 4 83 0
state_totals 46 34 12 34 0
string_ops 157 152 5 152 0
stubs/BigUInt 172 112 60 112 0
stubs/BigUInt 179 112 67 112 0
stubs/Bytes 1769 253 1516 253 0
stubs/String 777 141 636 141 0
stubs/Uint64 378 8 370 8 0
Expand Down
13 changes: 7 additions & 6 deletions src/puya/awst_build/eb/biguint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
BigUIntBinaryOperation,
BigUIntBinaryOperator,
BigUIntConstant,
Expression,
Literal,
NumericComparison,
NumericComparisonExpression,
Expand Down Expand Up @@ -52,15 +53,15 @@ def call(
location: SourceLocation,
) -> ExpressionBuilder:
match args:
case []:
value: Expression = BigUIntConstant(value=0, source_location=location)
case [Literal(value=int(int_value))]:
value = BigUIntConstant(value=int_value, source_location=location)
case [ExpressionBuilder() as eb]:
itob_call = uint64_to_biguint(eb, location)
return var_expression(itob_call)
case [Literal(value=int(int_value), source_location=loc)]:
# TODO: replace with loc with location
const = BigUIntConstant(value=int_value, source_location=loc)
return var_expression(const)
value = uint64_to_biguint(eb, location)
case _:
raise CodeError("Invalid/unhandled arguments", location)
return var_expression(value)


class BigUIntExpressionBuilder(ValueExpressionBuilder):
Expand Down
2 changes: 1 addition & 1 deletion src/puyapy-stubs/_primitives.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class BigUInt(BytesBacked):
# TODO: consider how to handle cases where sizes exceeds 512, which can happen on + or *,
# but the result is no longer usable with any further ops.
# ~~~ https://docs.python.org/3/reference/datamodel.html#basic-customization ~~~
def __init__(self, value: UInt64 | int, /) -> None:
def __init__(self, value: UInt64 | int = 0, /) -> None:
"""A BigUInt can be initialized with a UInt64, a Python int literal, or an int variable
declared at the module level"""
# TODO: mypy suggests due to Liskov below should be other: object
Expand Down
72 changes: 36 additions & 36 deletions test_cases/arc4_numeric_comparisons/out/UIntNOrdering.approval.mir

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions test_cases/biguint_binary_ops/out/BiguintBinaryOps.approval.mir

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions test_cases/contains/out/MyContract.approval.mir
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ main_block@0:
// virtual: store tmp%1#0 to l-stack (no copy) tmp%1#0 not two_false contains/contract.py:22
// virtual: load tmp%1#0 from l-stack (no copy) tmp%1#0 assert not two_false, "Should be false" contains/contract.py:22
assert // Should be false // assert not two_false, "Should be false" contains/contract.py:22
byte 0x1d65e22bcbbf // 0x1d65e22bcbbf 32323423423423 contains/contract.py:25
byte 0x1d65e22bcbbf // 0x1d65e22bcbbf,0x1d65e22bcbbf 32323423423423 contains/contract.py:25
byte 0x07acf5cae41e // 0x1d65e22bcbbf,0x1d65e22bcbbf,0x07acf5cae41e 8439439483934 contains/contract.py:25
byte 0x1d65e22bcbbf // 0x1d65e22bcbbf BigUInt(32323423423423) contains/contract.py:25
byte 0x1d65e22bcbbf // 0x1d65e22bcbbf,0x1d65e22bcbbf BigUInt(32323423423423) contains/contract.py:25
byte 0x07acf5cae41e // 0x1d65e22bcbbf,0x1d65e22bcbbf,0x07acf5cae41e BigUInt(8439439483934) contains/contract.py:25
callsub is_in_tuple_3 // {is_in_tuple_3} self.is_in_tuple_3(\nBigUInt(32323423423423), (BigUInt(32323423423423), BigUInt(8439439483934))\n) contains/contract.py:24-26
// virtual: store three_true#0 to l-stack (no copy) three_true#0 three_true = self.is_in_tuple_3(\nBigUInt(32323423423423), (BigUInt(32323423423423), BigUInt(8439... contains/contract.py:24-26
byte 0x3acbc457977e // three_true#0,0x3acbc457977e BigUInt(32323423423423) + BigUInt(32323423423423) contains/contract.py:28
byte 0x1d65e22bcbbf // three_true#0,0x3acbc457977e,0x1d65e22bcbbf 32323423423423 contains/contract.py:29
byte 0x07acf5cae41e // three_true#0,0x3acbc457977e,0x1d65e22bcbbf,0x07acf5cae41e 8439439483934 contains/contract.py:29
byte 0x1d65e22bcbbf // three_true#0,0x3acbc457977e,0x1d65e22bcbbf BigUInt(32323423423423) contains/contract.py:29
byte 0x07acf5cae41e // three_true#0,0x3acbc457977e,0x1d65e22bcbbf,0x07acf5cae41e BigUInt(8439439483934) contains/contract.py:29
callsub is_in_tuple_3 // three_true#0,{is_in_tuple_3} self.is_in_tuple_3(\nBigUInt(32323423423423) + BigUInt(32323423423423),\n(BigUInt(32323423423423)... contains/contract.py:27-30
// virtual: store three_false#0 to l-stack (no copy) three_true#0,three_false#0 three_false = self.is_in_tuple_3(\nBigUInt(32323423423423) + BigUInt(32323423423423),\n(BigUInt(3... contains/contract.py:27-30
swap // load three_true#0 from l-stack (no copy) three_false#0,three_true#0 assert three_true, "Should be true" contains/contract.py:31
Expand Down
Loading

0 comments on commit c02079b

Please sign in to comment.