diff --git a/examples/match/contract.py b/examples/match/contract.py index e09fd855b8..23113fa1b2 100644 --- a/examples/match/contract.py +++ b/examples/match/contract.py @@ -3,10 +3,14 @@ class MyContract(puyapy.Contract): def approval_program(self) -> bool: + self.case_one = puyapy.UInt64(1) + self.case_two = puyapy.UInt64(2) self.match_uint64() self.match_biguint() self.match_bytes() self.match_address() + self.match_attributes() + self.match_bools() return True @puyapy.subroutine @@ -53,5 +57,30 @@ def match_address(self) -> None: hello = puyapy.Bytes(b"Hello There address") puyapy.log(hello) + @puyapy.subroutine + def match_attributes(self) -> None: + n = puyapy.Transaction.num_app_args() + match n: + case self.case_one: + hello = puyapy.Bytes(b"Hello one") + puyapy.log(hello) + case self.case_two: + hello = puyapy.Bytes(b"Hello two") + puyapy.log(hello) + case _: + hello = puyapy.Bytes(b"Hello default") + puyapy.log(hello) + + @puyapy.subroutine + def match_bools(self) -> None: + n = puyapy.Transaction.num_app_args() > 0 + match n: + case True: + hello = puyapy.Bytes(b"Hello True") + puyapy.log(hello) + case False: + hello = puyapy.Bytes(b"Hello False") + puyapy.log(hello) + def clear_state_program(self) -> bool: return True diff --git a/examples/match/out/contract.approval.debug.teal b/examples/match/out/contract.approval.debug.teal index 1b79d9f361..080bb5557f 100644 --- a/examples/match/out/contract.approval.debug.teal +++ b/examples/match/out/contract.approval.debug.teal @@ -1,120 +1,190 @@ -// Op // Op Description Stack (out) Source code Source line +// Op // Op Description Stack (out) Source code Source line #pragma version 8 // examples.match.contract.MyContract.approval_program() -> uint64: main_block@0: - callsub match_uint64 // self.match_uint64() File "match/contract.py", line 6 - callsub match_biguint // self.match_biguint() File "match/contract.py", line 7 - callsub match_bytes // self.match_bytes() File "match/contract.py", line 8 - callsub match_address // self.match_address() File "match/contract.py", line 9 - int 1 // 1 True File "match/contract.py", line 10 - return // return True File "match/contract.py", line 10 + byte "case_one" // "case_one" self.case_one File "match/contract.py", line 6 + int 1 // "case_one",1 1 File "match/contract.py", line 6 + app_global_put // self.case_one = puyapy.UInt64(1) File "match/contract.py", line 6 + byte "case_two" // "case_two" self.case_two File "match/contract.py", line 7 + int 2 // "case_two",2 2 File "match/contract.py", line 7 + app_global_put // self.case_two = puyapy.UInt64(2) File "match/contract.py", line 7 + callsub match_uint64 // self.match_uint64() File "match/contract.py", line 8 + callsub match_biguint // self.match_biguint() File "match/contract.py", line 9 + callsub match_bytes // self.match_bytes() File "match/contract.py", line 10 + callsub match_address // self.match_address() File "match/contract.py", line 11 + callsub match_attributes // self.match_attributes() File "match/contract.py", line 12 + callsub match_bools // self.match_bools() File "match/contract.py", line 13 + int 1 // 1 True File "match/contract.py", line 14 + return // return True File "match/contract.py", line 14 // examples.match.contract.MyContract.match_uint64() -> void: match_uint64: - proto 0 0 // def match_uint64(self) -> None: File "match/contract.py", line 13 + proto 0 0 // def match_uint64(self) -> None: File "match/contract.py", line 17 match_uint64_block@0: - txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 14 - int 0 // n#0,0 0 File "match/contract.py", line 16 - int 10 // n#0,0,10 10 File "match/contract.py", line 19 - uncover 2 // load n#0 from l-stack (no copy) 0,10,n#0 n File "match/contract.py", line 14 - match match_uint64_switch_case_0@1 match_uint64_switch_case_1@2 // match n: File "match/contract.py", line 15 - b match_uint64_switch_case_next@4 // match n: File "match/contract.py", line 15 + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 18 + int 0 // n#0,0 0 File "match/contract.py", line 20 + int 10 // n#0,0,10 10 File "match/contract.py", line 23 + uncover 2 // load n#0 from l-stack (no copy) 0,10,n#0 n File "match/contract.py", line 18 + match match_uint64_switch_case_0@1 match_uint64_switch_case_1@2 // match n: File "match/contract.py", line 19 + b match_uint64_switch_case_next@4 // match n: File "match/contract.py", line 19 match_uint64_switch_case_0@1: - byte "Hello" // "Hello" b"Hello" File "match/contract.py", line 17 - log // puyapy.log(hello) File "match/contract.py", line 18 - b match_uint64_switch_case_next@4 // + byte "Hello" // "Hello" b"Hello" File "match/contract.py", line 21 + log // puyapy.log(hello) File "match/contract.py", line 22 + b match_uint64_switch_case_next@4 // match_uint64_switch_case_1@2: - byte "Hello There" // "Hello There" b"Hello There" File "match/contract.py", line 20 - log // puyapy.log(hello) File "match/contract.py", line 21 - // Implicit fall through to match_uint64_switch_case_next@4 // + byte "Hello There" // "Hello There" b"Hello There" File "match/contract.py", line 24 + log // puyapy.log(hello) File "match/contract.py", line 25 + // Implicit fall through to match_uint64_switch_case_next@4 // match_uint64_switch_case_next@4: - retsub // + retsub // // examples.match.contract.MyContract.match_biguint() -> void: match_biguint: - proto 0 0 // def match_biguint(self) -> None: File "match/contract.py", line 35 + proto 0 0 // def match_biguint(self) -> None: File "match/contract.py", line 39 match_biguint_block@0: - txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 36 - itob // {itob} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 36 - byte 0x0a // tmp%1#0,0x0a 10 File "match/contract.py", line 36 - b* // {b*} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 36 - byte 0x // n#0,0x 0 File "match/contract.py", line 38 - byte 0x0a // n#0,0x,0x0a 10 File "match/contract.py", line 41 - uncover 2 // load n#0 from l-stack (no copy) 0x,0x0a,n#0 n File "match/contract.py", line 36 - match match_biguint_switch_case_0@1 match_biguint_switch_case_1@2 // match n: File "match/contract.py", line 37 - b match_biguint_switch_case_next@4 // match n: File "match/contract.py", line 37 + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 40 + itob // {itob} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 40 + byte 0x0a // tmp%1#0,0x0a 10 File "match/contract.py", line 40 + b* // {b*} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 40 + byte 0x // n#0,0x 0 File "match/contract.py", line 42 + byte 0x0a // n#0,0x,0x0a 10 File "match/contract.py", line 45 + uncover 2 // load n#0 from l-stack (no copy) 0x,0x0a,n#0 n File "match/contract.py", line 40 + match match_biguint_switch_case_0@1 match_biguint_switch_case_1@2 // match n: File "match/contract.py", line 41 + b match_biguint_switch_case_next@4 // match n: File "match/contract.py", line 41 match_biguint_switch_case_0@1: - byte "Hello biguint" // "Hello biguint" b"Hello biguint" File "match/contract.py", line 39 - log // puyapy.log(hello) File "match/contract.py", line 40 - b match_biguint_switch_case_next@4 // + byte "Hello biguint" // "Hello biguint" b"Hello biguint" File "match/contract.py", line 43 + log // puyapy.log(hello) File "match/contract.py", line 44 + b match_biguint_switch_case_next@4 // match_biguint_switch_case_1@2: - byte "Hello There biguint" // "Hello There biguint" b"Hello There biguint" File "match/contract.py", line 42 - log // puyapy.log(hello) File "match/contract.py", line 43 - // Implicit fall through to match_biguint_switch_case_next@4 // + byte "Hello There biguint" // "Hello There biguint" b"Hello There biguint" File "match/contract.py", line 46 + log // puyapy.log(hello) File "match/contract.py", line 47 + // Implicit fall through to match_biguint_switch_case_next@4 // match_biguint_switch_case_next@4: - retsub // + retsub // // examples.match.contract.MyContract.match_bytes() -> void: match_bytes: - proto 0 0 // def match_bytes(self) -> None: File "match/contract.py", line 24 + proto 0 0 // def match_bytes(self) -> None: File "match/contract.py", line 28 match_bytes_block@0: - txna ApplicationArgs 0 // {txna} puyapy.Transaction.application_args(0) File "match/contract.py", line 25 - byte "" // n#0,"" b"" File "match/contract.py", line 27 - byte "10" // n#0,"","10" b"10" File "match/contract.py", line 30 - uncover 2 // load n#0 from l-stack (no copy) "","10",n#0 n File "match/contract.py", line 25 - match match_bytes_switch_case_0@1 match_bytes_switch_case_1@2 // match n: File "match/contract.py", line 26 - b match_bytes_switch_case_next@4 // match n: File "match/contract.py", line 26 + txna ApplicationArgs 0 // {txna} puyapy.Transaction.application_args(0) File "match/contract.py", line 29 + byte "" // n#0,"" b"" File "match/contract.py", line 31 + byte "10" // n#0,"","10" b"10" File "match/contract.py", line 34 + uncover 2 // load n#0 from l-stack (no copy) "","10",n#0 n File "match/contract.py", line 29 + match match_bytes_switch_case_0@1 match_bytes_switch_case_1@2 // match n: File "match/contract.py", line 30 + b match_bytes_switch_case_next@4 // match n: File "match/contract.py", line 30 match_bytes_switch_case_0@1: - byte "Hello bytes" // "Hello bytes" b"Hello bytes" File "match/contract.py", line 28 - log // puyapy.log(hello) File "match/contract.py", line 29 - b match_bytes_switch_case_next@4 // + byte "Hello bytes" // "Hello bytes" b"Hello bytes" File "match/contract.py", line 32 + log // puyapy.log(hello) File "match/contract.py", line 33 + b match_bytes_switch_case_next@4 // match_bytes_switch_case_1@2: - byte "Hello There bytes" // "Hello There bytes" b"Hello There bytes" File "match/contract.py", line 31 - log // puyapy.log(hello) File "match/contract.py", line 32 - // Implicit fall through to match_bytes_switch_case_next@4 // + byte "Hello There bytes" // "Hello There bytes" b"Hello There bytes" File "match/contract.py", line 35 + log // puyapy.log(hello) File "match/contract.py", line 36 + // Implicit fall through to match_bytes_switch_case_next@4 // match_bytes_switch_case_next@4: - retsub // + retsub // // examples.match.contract.MyContract.match_address() -> void: match_address: - proto 0 0 // def match_address(self) -> None: File "match/contract.py", line 46 + proto 0 0 // def match_address(self) -> None: File "match/contract.py", line 50 match_address_block@0: - txn Sender // {txn} puyapy.Transaction.sender() File "match/contract.py", line 47 - addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" File "match/contract.py", line 49 - addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA" File "match/contract.py", line 52 - uncover 2 // load n#0 from l-stack (no copy) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA,n#0 n File "match/contract.py", line 47 - match match_address_switch_case_0@1 match_address_switch_case_1@2 // match n: File "match/contract.py", line 48 - b match_address_switch_case_next@4 // match n: File "match/contract.py", line 48 + txn Sender // {txn} puyapy.Transaction.sender() File "match/contract.py", line 51 + addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" File "match/contract.py", line 53 + addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA" File "match/contract.py", line 56 + uncover 2 // load n#0 from l-stack (no copy) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA,n#0 n File "match/contract.py", line 51 + match match_address_switch_case_0@1 match_address_switch_case_1@2 // match n: File "match/contract.py", line 52 + b match_address_switch_case_next@4 // match n: File "match/contract.py", line 52 match_address_switch_case_0@1: - byte "Hello address" // "Hello address" b"Hello address" File "match/contract.py", line 50 - log // puyapy.log(hello) File "match/contract.py", line 51 - b match_address_switch_case_next@4 // + byte "Hello address" // "Hello address" b"Hello address" File "match/contract.py", line 54 + log // puyapy.log(hello) File "match/contract.py", line 55 + b match_address_switch_case_next@4 // match_address_switch_case_1@2: - byte "Hello There address" // "Hello There address" b"Hello There address" File "match/contract.py", line 53 - log // puyapy.log(hello) File "match/contract.py", line 54 - // Implicit fall through to match_address_switch_case_next@4 // + byte "Hello There address" // "Hello There address" b"Hello There address" File "match/contract.py", line 57 + log // puyapy.log(hello) File "match/contract.py", line 58 + // Implicit fall through to match_address_switch_case_next@4 // match_address_switch_case_next@4: - retsub // + retsub // + + +// examples.match.contract.MyContract.match_attributes() -> void: +match_attributes: + proto 0 0 // def match_attributes(self) -> None: File "match/contract.py", line 61 + +match_attributes_block@0: + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 62 + int 0 // n#0,0 self.case_one File "match/contract.py", line 64 + byte "case_one" // n#0,0,"case_one" self.case_one File "match/contract.py", line 64 + app_global_get_ex // n#0,{app_global_get_ex}.0,{app_global_get_ex}.1 self.case_one File "match/contract.py", line 64 + assert // check value exists // n#0,app_global_get_ex_value%0#0 self.case_one File "match/contract.py", line 64 + int 0 // n#0,app_global_get_ex_value%0#0,0 self.case_two File "match/contract.py", line 67 + byte "case_two" // n#0,app_global_get_ex_value%0#0,0,"case_two" self.case_two File "match/contract.py", line 67 + app_global_get_ex // n#0,app_global_get_ex_value%0#0,{app_global_get_ex}.0,{app_global_get_ex}.1 self.case_two File "match/contract.py", line 67 + assert // check value exists // n#0,app_global_get_ex_value%0#0,app_global_get_ex_value%2#0 self.case_two File "match/contract.py", line 67 + uncover 2 // load n#0 from l-stack (no copy) app_global_get_ex_value%0#0,app_global_get_ex_value%2#0,n#0 n File "match/contract.py", line 62 + match match_attributes_switch_case_0@1 match_attributes_switch_case_1@2 // match n: File "match/contract.py", line 63 + b match_attributes_switch_case_default@3 // match n: File "match/contract.py", line 63 + +match_attributes_switch_case_0@1: + byte "Hello one" // "Hello one" b"Hello one" File "match/contract.py", line 65 + log // puyapy.log(hello) File "match/contract.py", line 66 + b match_attributes_switch_case_next@4 // + +match_attributes_switch_case_1@2: + byte "Hello two" // "Hello two" b"Hello two" File "match/contract.py", line 68 + log // puyapy.log(hello) File "match/contract.py", line 69 + b match_attributes_switch_case_next@4 // + +match_attributes_switch_case_default@3: + byte "Hello default" // "Hello default" b"Hello default" File "match/contract.py", line 71 + log // puyapy.log(hello) File "match/contract.py", line 72 + // Implicit fall through to match_attributes_switch_case_next@4 // + +match_attributes_switch_case_next@4: + retsub // + + +// examples.match.contract.MyContract.match_bools() -> void: +match_bools: + proto 0 0 // def match_bools(self) -> None: File "match/contract.py", line 75 + +match_bools_block@0: + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 76 + int 0 // tmp%0#0,0 0 File "match/contract.py", line 76 + > // {>} puyapy.Transaction.num_app_args() > 0 File "match/contract.py", line 76 + switch match_bools_switch_case_1@2 match_bools_switch_case_0@1 // match n: File "match/contract.py", line 77 + b match_bools_switch_case_next@4 // match n: File "match/contract.py", line 77 + +match_bools_switch_case_0@1: + byte "Hello True" // "Hello True" b"Hello True" File "match/contract.py", line 79 + log // puyapy.log(hello) File "match/contract.py", line 80 + b match_bools_switch_case_next@4 // + +match_bools_switch_case_1@2: + byte "Hello False" // "Hello False" b"Hello False" File "match/contract.py", line 82 + log // puyapy.log(hello) File "match/contract.py", line 83 + // Implicit fall through to match_bools_switch_case_next@4 // + +match_bools_switch_case_next@4: + retsub // diff --git a/examples/match/out/contract.approval.teal b/examples/match/out/contract.approval.teal index 2f33f913cb..1813110d2c 100644 --- a/examples/match/out/contract.approval.teal +++ b/examples/match/out/contract.approval.teal @@ -2,10 +2,18 @@ // examples.match.contract.MyContract.approval_program() -> uint64: main_block@0: + byte "case_one" + int 1 + app_global_put + byte "case_two" + int 2 + app_global_put callsub match_uint64 callsub match_biguint callsub match_bytes callsub match_address + callsub match_attributes + callsub match_bools int 1 return @@ -112,3 +120,63 @@ match_address_switch_case_1@2: match_address_switch_case_next@4: retsub + +// examples.match.contract.MyContract.match_attributes() -> void: +match_attributes: + proto 0 0 + +match_attributes_block@0: + txn NumAppArgs + int 0 + byte "case_one" + app_global_get_ex + assert // check value exists + int 0 + byte "case_two" + app_global_get_ex + assert // check value exists + uncover 2 + match match_attributes_switch_case_0@1 match_attributes_switch_case_1@2 + b match_attributes_switch_case_default@3 + +match_attributes_switch_case_0@1: + byte "Hello one" + log + b match_attributes_switch_case_next@4 + +match_attributes_switch_case_1@2: + byte "Hello two" + log + b match_attributes_switch_case_next@4 + +match_attributes_switch_case_default@3: + byte "Hello default" + log + +match_attributes_switch_case_next@4: + retsub + + +// examples.match.contract.MyContract.match_bools() -> void: +match_bools: + proto 0 0 + +match_bools_block@0: + txn NumAppArgs + int 0 + > + switch match_bools_switch_case_1@2 match_bools_switch_case_0@1 + b match_bools_switch_case_next@4 + +match_bools_switch_case_0@1: + byte "Hello True" + log + b match_bools_switch_case_next@4 + +match_bools_switch_case_1@2: + byte "Hello False" + log + +match_bools_switch_case_next@4: + retsub + diff --git a/examples/match/out/contract.approval_unoptimized.debug.teal b/examples/match/out/contract.approval_unoptimized.debug.teal index cdaec14959..bac705dc9e 100644 --- a/examples/match/out/contract.approval_unoptimized.debug.teal +++ b/examples/match/out/contract.approval_unoptimized.debug.teal @@ -1,132 +1,208 @@ -// Op // Op Description Stack (out) Source code Source line +// Op // Op Description Stack (out) Source code Source line #pragma version 8 // examples.match.contract.MyContract.approval_program() -> uint64: main_block@0: - callsub match_uint64 // self.match_uint64() File "match/contract.py", line 6 - callsub match_biguint // self.match_biguint() File "match/contract.py", line 7 - callsub match_bytes // self.match_bytes() File "match/contract.py", line 8 - callsub match_address // self.match_address() File "match/contract.py", line 9 - int 1 // 1 True File "match/contract.py", line 10 - return // return True File "match/contract.py", line 10 + byte "case_one" // "case_one" self.case_one File "match/contract.py", line 6 + int 1 // "case_one",1 1 File "match/contract.py", line 6 + app_global_put // self.case_one = puyapy.UInt64(1) File "match/contract.py", line 6 + byte "case_two" // "case_two" self.case_two File "match/contract.py", line 7 + int 2 // "case_two",2 2 File "match/contract.py", line 7 + app_global_put // self.case_two = puyapy.UInt64(2) File "match/contract.py", line 7 + callsub match_uint64 // self.match_uint64() File "match/contract.py", line 8 + callsub match_biguint // self.match_biguint() File "match/contract.py", line 9 + callsub match_bytes // self.match_bytes() File "match/contract.py", line 10 + callsub match_address // self.match_address() File "match/contract.py", line 11 + callsub match_attributes // self.match_attributes() File "match/contract.py", line 12 + callsub match_bools // self.match_bools() File "match/contract.py", line 13 + int 1 // 1 True File "match/contract.py", line 14 + return // return True File "match/contract.py", line 14 // examples.match.contract.MyContract.match_uint64() -> void: match_uint64: - proto 0 0 // def match_uint64(self) -> None: File "match/contract.py", line 13 + proto 0 0 // def match_uint64(self) -> None: File "match/contract.py", line 17 match_uint64_block@0: - txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 14 - int 0 // n#0,0 0 File "match/contract.py", line 16 - int 10 // n#0,0,10 10 File "match/contract.py", line 19 - uncover 2 // load n#0 from l-stack (no copy) 0,10,n#0 n File "match/contract.py", line 14 - match match_uint64_switch_case_0@1 match_uint64_switch_case_1@2 // match n: File "match/contract.py", line 15 - b match_uint64_switch_case_default@3 // match n: File "match/contract.py", line 15 + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 18 + int 0 // n#0,0 0 File "match/contract.py", line 20 + int 10 // n#0,0,10 10 File "match/contract.py", line 23 + uncover 2 // load n#0 from l-stack (no copy) 0,10,n#0 n File "match/contract.py", line 18 + match match_uint64_switch_case_0@1 match_uint64_switch_case_1@2 // match n: File "match/contract.py", line 19 + b match_uint64_switch_case_default@3 // match n: File "match/contract.py", line 19 match_uint64_switch_case_0@1: - byte "Hello" // "Hello" b"Hello" File "match/contract.py", line 17 - log // puyapy.log(hello) File "match/contract.py", line 18 - b match_uint64_switch_case_next@4 // + byte "Hello" // "Hello" b"Hello" File "match/contract.py", line 21 + log // puyapy.log(hello) File "match/contract.py", line 22 + b match_uint64_switch_case_next@4 // match_uint64_switch_case_1@2: - byte "Hello There" // "Hello There" b"Hello There" File "match/contract.py", line 20 - log // puyapy.log(hello) File "match/contract.py", line 21 - b match_uint64_switch_case_next@4 // + byte "Hello There" // "Hello There" b"Hello There" File "match/contract.py", line 24 + log // puyapy.log(hello) File "match/contract.py", line 25 + b match_uint64_switch_case_next@4 // match_uint64_switch_case_default@3: - // Implicit fall through to match_uint64_switch_case_next@4 // + // Implicit fall through to match_uint64_switch_case_next@4 // match_uint64_switch_case_next@4: - retsub // + retsub // // examples.match.contract.MyContract.match_biguint() -> void: match_biguint: - proto 0 0 // def match_biguint(self) -> None: File "match/contract.py", line 35 + proto 0 0 // def match_biguint(self) -> None: File "match/contract.py", line 39 match_biguint_block@0: - txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 36 - itob // {itob} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 36 - byte 0x0a // tmp%1#0,0x0a 10 File "match/contract.py", line 36 - b* // {b*} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 36 - byte 0x // n#0,0x 0 File "match/contract.py", line 38 - byte 0x0a // n#0,0x,0x0a 10 File "match/contract.py", line 41 - uncover 2 // load n#0 from l-stack (no copy) 0x,0x0a,n#0 n File "match/contract.py", line 36 - match match_biguint_switch_case_0@1 match_biguint_switch_case_1@2 // match n: File "match/contract.py", line 37 - b match_biguint_switch_case_default@3 // match n: File "match/contract.py", line 37 + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 40 + itob // {itob} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 40 + byte 0x0a // tmp%1#0,0x0a 10 File "match/contract.py", line 40 + b* // {b*} puyapy.Transaction.num_app_args() * puyapy.BigUInt(10) File "match/contract.py", line 40 + byte 0x // n#0,0x 0 File "match/contract.py", line 42 + byte 0x0a // n#0,0x,0x0a 10 File "match/contract.py", line 45 + uncover 2 // load n#0 from l-stack (no copy) 0x,0x0a,n#0 n File "match/contract.py", line 40 + match match_biguint_switch_case_0@1 match_biguint_switch_case_1@2 // match n: File "match/contract.py", line 41 + b match_biguint_switch_case_default@3 // match n: File "match/contract.py", line 41 match_biguint_switch_case_0@1: - byte "Hello biguint" // "Hello biguint" b"Hello biguint" File "match/contract.py", line 39 - log // puyapy.log(hello) File "match/contract.py", line 40 - b match_biguint_switch_case_next@4 // + byte "Hello biguint" // "Hello biguint" b"Hello biguint" File "match/contract.py", line 43 + log // puyapy.log(hello) File "match/contract.py", line 44 + b match_biguint_switch_case_next@4 // match_biguint_switch_case_1@2: - byte "Hello There biguint" // "Hello There biguint" b"Hello There biguint" File "match/contract.py", line 42 - log // puyapy.log(hello) File "match/contract.py", line 43 - b match_biguint_switch_case_next@4 // + byte "Hello There biguint" // "Hello There biguint" b"Hello There biguint" File "match/contract.py", line 46 + log // puyapy.log(hello) File "match/contract.py", line 47 + b match_biguint_switch_case_next@4 // match_biguint_switch_case_default@3: - // Implicit fall through to match_biguint_switch_case_next@4 // + // Implicit fall through to match_biguint_switch_case_next@4 // match_biguint_switch_case_next@4: - retsub // + retsub // // examples.match.contract.MyContract.match_bytes() -> void: match_bytes: - proto 0 0 // def match_bytes(self) -> None: File "match/contract.py", line 24 + proto 0 0 // def match_bytes(self) -> None: File "match/contract.py", line 28 match_bytes_block@0: - txna ApplicationArgs 0 // {txna} puyapy.Transaction.application_args(0) File "match/contract.py", line 25 - byte "" // n#0,"" b"" File "match/contract.py", line 27 - byte "10" // n#0,"","10" b"10" File "match/contract.py", line 30 - uncover 2 // load n#0 from l-stack (no copy) "","10",n#0 n File "match/contract.py", line 25 - match match_bytes_switch_case_0@1 match_bytes_switch_case_1@2 // match n: File "match/contract.py", line 26 - b match_bytes_switch_case_default@3 // match n: File "match/contract.py", line 26 + txna ApplicationArgs 0 // {txna} puyapy.Transaction.application_args(0) File "match/contract.py", line 29 + byte "" // n#0,"" b"" File "match/contract.py", line 31 + byte "10" // n#0,"","10" b"10" File "match/contract.py", line 34 + uncover 2 // load n#0 from l-stack (no copy) "","10",n#0 n File "match/contract.py", line 29 + match match_bytes_switch_case_0@1 match_bytes_switch_case_1@2 // match n: File "match/contract.py", line 30 + b match_bytes_switch_case_default@3 // match n: File "match/contract.py", line 30 match_bytes_switch_case_0@1: - byte "Hello bytes" // "Hello bytes" b"Hello bytes" File "match/contract.py", line 28 - log // puyapy.log(hello) File "match/contract.py", line 29 - b match_bytes_switch_case_next@4 // + byte "Hello bytes" // "Hello bytes" b"Hello bytes" File "match/contract.py", line 32 + log // puyapy.log(hello) File "match/contract.py", line 33 + b match_bytes_switch_case_next@4 // match_bytes_switch_case_1@2: - byte "Hello There bytes" // "Hello There bytes" b"Hello There bytes" File "match/contract.py", line 31 - log // puyapy.log(hello) File "match/contract.py", line 32 - b match_bytes_switch_case_next@4 // + byte "Hello There bytes" // "Hello There bytes" b"Hello There bytes" File "match/contract.py", line 35 + log // puyapy.log(hello) File "match/contract.py", line 36 + b match_bytes_switch_case_next@4 // match_bytes_switch_case_default@3: - // Implicit fall through to match_bytes_switch_case_next@4 // + // Implicit fall through to match_bytes_switch_case_next@4 // match_bytes_switch_case_next@4: - retsub // + retsub // // examples.match.contract.MyContract.match_address() -> void: match_address: - proto 0 0 // def match_address(self) -> None: File "match/contract.py", line 46 + proto 0 0 // def match_address(self) -> None: File "match/contract.py", line 50 match_address_block@0: - txn Sender // {txn} puyapy.Transaction.sender() File "match/contract.py", line 47 - addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" File "match/contract.py", line 49 - addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA" File "match/contract.py", line 52 - uncover 2 // load n#0 from l-stack (no copy) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA,n#0 n File "match/contract.py", line 47 - match match_address_switch_case_0@1 match_address_switch_case_1@2 // match n: File "match/contract.py", line 48 - b match_address_switch_case_default@3 // match n: File "match/contract.py", line 48 + txn Sender // {txn} puyapy.Transaction.sender() File "match/contract.py", line 51 + addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ" File "match/contract.py", line 53 + addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA // n#0,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA" File "match/contract.py", line 56 + uncover 2 // load n#0 from l-stack (no copy) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ,VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA,n#0 n File "match/contract.py", line 51 + match match_address_switch_case_0@1 match_address_switch_case_1@2 // match n: File "match/contract.py", line 52 + b match_address_switch_case_default@3 // match n: File "match/contract.py", line 52 match_address_switch_case_0@1: - byte "Hello address" // "Hello address" b"Hello address" File "match/contract.py", line 50 - log // puyapy.log(hello) File "match/contract.py", line 51 - b match_address_switch_case_next@4 // + byte "Hello address" // "Hello address" b"Hello address" File "match/contract.py", line 54 + log // puyapy.log(hello) File "match/contract.py", line 55 + b match_address_switch_case_next@4 // match_address_switch_case_1@2: - byte "Hello There address" // "Hello There address" b"Hello There address" File "match/contract.py", line 53 - log // puyapy.log(hello) File "match/contract.py", line 54 - b match_address_switch_case_next@4 // + byte "Hello There address" // "Hello There address" b"Hello There address" File "match/contract.py", line 57 + log // puyapy.log(hello) File "match/contract.py", line 58 + b match_address_switch_case_next@4 // match_address_switch_case_default@3: - // Implicit fall through to match_address_switch_case_next@4 // + // Implicit fall through to match_address_switch_case_next@4 // match_address_switch_case_next@4: - retsub // + retsub // + + +// examples.match.contract.MyContract.match_attributes() -> void: +match_attributes: + proto 0 0 // def match_attributes(self) -> None: File "match/contract.py", line 61 + +match_attributes_block@0: + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 62 + int 0 // n#0,0 self.case_one File "match/contract.py", line 64 + byte "case_one" // n#0,0,"case_one" self.case_one File "match/contract.py", line 64 + app_global_get_ex // n#0,{app_global_get_ex}.0,{app_global_get_ex}.1 self.case_one File "match/contract.py", line 64 + assert // check value exists // n#0,app_global_get_ex_value%0#0 self.case_one File "match/contract.py", line 64 + int 0 // n#0,app_global_get_ex_value%0#0,0 self.case_two File "match/contract.py", line 67 + byte "case_two" // n#0,app_global_get_ex_value%0#0,0,"case_two" self.case_two File "match/contract.py", line 67 + app_global_get_ex // n#0,app_global_get_ex_value%0#0,{app_global_get_ex}.0,{app_global_get_ex}.1 self.case_two File "match/contract.py", line 67 + assert // check value exists // n#0,app_global_get_ex_value%0#0,app_global_get_ex_value%2#0 self.case_two File "match/contract.py", line 67 + uncover 2 // load n#0 from l-stack (no copy) app_global_get_ex_value%0#0,app_global_get_ex_value%2#0,n#0 n File "match/contract.py", line 62 + match match_attributes_switch_case_0@1 match_attributes_switch_case_1@2 // match n: File "match/contract.py", line 63 + b match_attributes_switch_case_default@3 // match n: File "match/contract.py", line 63 + +match_attributes_switch_case_0@1: + byte "Hello one" // "Hello one" b"Hello one" File "match/contract.py", line 65 + log // puyapy.log(hello) File "match/contract.py", line 66 + b match_attributes_switch_case_next@4 // + +match_attributes_switch_case_1@2: + byte "Hello two" // "Hello two" b"Hello two" File "match/contract.py", line 68 + log // puyapy.log(hello) File "match/contract.py", line 69 + b match_attributes_switch_case_next@4 // + +match_attributes_switch_case_default@3: + byte "Hello default" // "Hello default" b"Hello default" File "match/contract.py", line 71 + log // puyapy.log(hello) File "match/contract.py", line 72 + // Implicit fall through to match_attributes_switch_case_next@4 // + +match_attributes_switch_case_next@4: + retsub // + + +// examples.match.contract.MyContract.match_bools() -> void: +match_bools: + proto 0 0 // def match_bools(self) -> None: File "match/contract.py", line 75 + +match_bools_block@0: + txn NumAppArgs // {txn} puyapy.Transaction.num_app_args() File "match/contract.py", line 76 + int 0 // tmp%0#0,0 0 File "match/contract.py", line 76 + > // {>} puyapy.Transaction.num_app_args() > 0 File "match/contract.py", line 76 + int 1 // n#0,1 True File "match/contract.py", line 78 + int 0 // n#0,1,0 False File "match/contract.py", line 81 + uncover 2 // load n#0 from l-stack (no copy) 1,0,n#0 n File "match/contract.py", line 76 + match match_bools_switch_case_0@1 match_bools_switch_case_1@2 // match n: File "match/contract.py", line 77 + b match_bools_switch_case_default@3 // match n: File "match/contract.py", line 77 + +match_bools_switch_case_0@1: + byte "Hello True" // "Hello True" b"Hello True" File "match/contract.py", line 79 + log // puyapy.log(hello) File "match/contract.py", line 80 + b match_bools_switch_case_next@4 // + +match_bools_switch_case_1@2: + byte "Hello False" // "Hello False" b"Hello False" File "match/contract.py", line 82 + log // puyapy.log(hello) File "match/contract.py", line 83 + b match_bools_switch_case_next@4 // + +match_bools_switch_case_default@3: + // Implicit fall through to match_bools_switch_case_next@4 // + +match_bools_switch_case_next@4: + retsub // diff --git a/examples/match/out/contract.approval_unoptimized.teal b/examples/match/out/contract.approval_unoptimized.teal index f61d4f4a61..3640ab7d4f 100644 --- a/examples/match/out/contract.approval_unoptimized.teal +++ b/examples/match/out/contract.approval_unoptimized.teal @@ -2,10 +2,18 @@ // examples.match.contract.MyContract.approval_program() -> uint64: main_block@0: + byte "case_one" + int 1 + app_global_put + byte "case_two" + int 2 + app_global_put callsub match_uint64 callsub match_biguint callsub match_bytes callsub match_address + callsub match_attributes + callsub match_bools int 1 return @@ -124,3 +132,69 @@ match_address_switch_case_default@3: match_address_switch_case_next@4: retsub + +// examples.match.contract.MyContract.match_attributes() -> void: +match_attributes: + proto 0 0 + +match_attributes_block@0: + txn NumAppArgs + int 0 + byte "case_one" + app_global_get_ex + assert // check value exists + int 0 + byte "case_two" + app_global_get_ex + assert // check value exists + uncover 2 + match match_attributes_switch_case_0@1 match_attributes_switch_case_1@2 + b match_attributes_switch_case_default@3 + +match_attributes_switch_case_0@1: + byte "Hello one" + log + b match_attributes_switch_case_next@4 + +match_attributes_switch_case_1@2: + byte "Hello two" + log + b match_attributes_switch_case_next@4 + +match_attributes_switch_case_default@3: + byte "Hello default" + log + +match_attributes_switch_case_next@4: + retsub + + +// examples.match.contract.MyContract.match_bools() -> void: +match_bools: + proto 0 0 + +match_bools_block@0: + txn NumAppArgs + int 0 + > + int 1 + int 0 + uncover 2 + match match_bools_switch_case_0@1 match_bools_switch_case_1@2 + b match_bools_switch_case_default@3 + +match_bools_switch_case_0@1: + byte "Hello True" + log + b match_bools_switch_case_next@4 + +match_bools_switch_case_1@2: + byte "Hello False" + log + b match_bools_switch_case_next@4 + +match_bools_switch_case_default@3: + +match_bools_switch_case_next@4: + retsub + diff --git a/examples/match/out/contract.awst b/examples/match/out/contract.awst index e4a676e826..cbf0a0fb8e 100644 --- a/examples/match/out/contract.awst +++ b/examples/match/out/contract.awst @@ -1,11 +1,20 @@ contract MyContract { + globals { + ['case_one']: puyapy.UInt64 + ['case_two']: puyapy.UInt64 + } + approval_program(): bool { + this.globals['case_one']: puyapy.UInt64 = 1u + this.globals['case_two']: puyapy.UInt64 = 2u this::match_uint64() this::match_biguint() this::match_bytes() this::match_address() + this::match_attributes() + this::match_bools() return true } @@ -73,4 +82,38 @@ contract MyContract } } } + + subroutine match_attributes(): None + { + n: puyapy.UInt64 = txn() + switch (n) { + case this.globals['case_one']: { + hello: puyapy.Bytes = 'Hello one' + log(hello) + } + case this.globals['case_two']: { + hello: puyapy.Bytes = 'Hello two' + log(hello) + } + case _: { + hello: puyapy.Bytes = 'Hello default' + log(hello) + } + } + } + + subroutine match_bools(): None + { + n: bool = txn() > 0u + switch (n) { + case true: { + hello: puyapy.Bytes = 'Hello True' + log(hello) + } + case false: { + hello: puyapy.Bytes = 'Hello False' + log(hello) + } + } + } } \ No newline at end of file diff --git a/examples/match/out/contract.clear.debug.teal b/examples/match/out/contract.clear.debug.teal index 397cee3fe4..adc3f3b42e 100644 --- a/examples/match/out/contract.clear.debug.teal +++ b/examples/match/out/contract.clear.debug.teal @@ -4,6 +4,6 @@ // examples.match.contract.MyContract.clear_state_program() -> uint64: main_block@0: - int 1 // 1 True File "match/contract.py", line 57 - return // return True File "match/contract.py", line 57 + int 1 // 1 True File "match/contract.py", line 86 + return // return True File "match/contract.py", line 86 diff --git a/examples/match/out/contract.clear_unoptimized.debug.teal b/examples/match/out/contract.clear_unoptimized.debug.teal index 397cee3fe4..adc3f3b42e 100644 --- a/examples/match/out/contract.clear_unoptimized.debug.teal +++ b/examples/match/out/contract.clear_unoptimized.debug.teal @@ -4,6 +4,6 @@ // examples.match.contract.MyContract.clear_state_program() -> uint64: main_block@0: - int 1 // 1 True File "match/contract.py", line 57 - return // return True File "match/contract.py", line 57 + int 1 // 1 True File "match/contract.py", line 86 + return // return True File "match/contract.py", line 86 diff --git a/examples/match/out/contract_MyContract.cssa.ir b/examples/match/out/contract_MyContract.cssa.ir index cac46472d7..7702cda3ac 100644 --- a/examples/match/out/contract_MyContract.cssa.ir +++ b/examples/match/out/contract_MyContract.cssa.ir @@ -2,67 +2,105 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@4} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 (log "Hello") goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 (log "Hello There") goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@4} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 (log "Hello biguint") goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 (log "Hello There biguint") goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@4} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 (log "Hello bytes") goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 (log "Hello There bytes") goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@4} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 (log "Hello address") goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 (log "Hello There address") goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + (log "Hello one") + goto block@4 + block@2: // switch_case_1_L68 + (log "Hello two") + goto block@4 + block@3: // switch_case_default_L63 + (log "Hello default") + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + goto [block@2, block@1, ...block@4][n#0] + block@1: // switch_case_0_L79 + (log "Hello True") + goto block@4 + block@2: // switch_case_1_L82 + (log "Hello False") + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/out/contract_MyContract.final.ir b/examples/match/out/contract_MyContract.final.ir index cac46472d7..7702cda3ac 100644 --- a/examples/match/out/contract_MyContract.final.ir +++ b/examples/match/out/contract_MyContract.final.ir @@ -2,67 +2,105 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@4} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 (log "Hello") goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 (log "Hello There") goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@4} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 (log "Hello biguint") goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 (log "Hello There biguint") goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@4} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 (log "Hello bytes") goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 (log "Hello There bytes") goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@4} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 (log "Hello address") goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 (log "Hello There address") goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + (log "Hello one") + goto block@4 + block@2: // switch_case_1_L68 + (log "Hello two") + goto block@4 + block@3: // switch_case_default_L63 + (log "Hello default") + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + goto [block@2, block@1, ...block@4][n#0] + block@1: // switch_case_0_L79 + (log "Hello True") + goto block@4 + block@2: // switch_case_1_L82 + (log "Hello False") + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/out/contract_MyContract.final_unoptimized.ir b/examples/match/out/contract_MyContract.final_unoptimized.ir index c7abae88b5..5147a6dc14 100644 --- a/examples/match/out/contract_MyContract.final_unoptimized.ir +++ b/examples/match/out/contract_MyContract.final_unoptimized.ir @@ -2,83 +2,128 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@3} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 let hello#0: bytes = "Hello" (log hello#0) goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 let hello#0: bytes = "Hello There" (log hello#0) goto block@4 - block@3: // switch_case_default_L15 + block@3: // switch_case_default_L19 goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@3} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 let hello#0: bytes = "Hello biguint" (log hello#0) goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 let hello#0: bytes = "Hello There biguint" (log hello#0) goto block@4 - block@3: // switch_case_default_L37 + block@3: // switch_case_default_L41 goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@3} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 let hello#0: bytes = "Hello bytes" (log hello#0) goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 let hello#0: bytes = "Hello There bytes" (log hello#0) goto block@4 - block@3: // switch_case_default_L26 + block@3: // switch_case_default_L30 goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@3} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 let hello#0: bytes = "Hello address" (log hello#0) goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 let hello#0: bytes = "Hello There address" (log hello#0) goto block@4 - block@3: // switch_case_default_L48 + block@3: // switch_case_default_L52 goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + let hello#0: bytes = "Hello one" + (log hello#0) + goto block@4 + block@2: // switch_case_1_L68 + let hello#0: bytes = "Hello two" + (log hello#0) + goto block@4 + block@3: // switch_case_default_L63 + let hello#0: bytes = "Hello default" + (log hello#0) + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + switch n#0 {1u => block@1, 0u => block@2, * => block@3} + block@1: // switch_case_0_L79 + let hello#0: bytes = "Hello True" + (log hello#0) + goto block@4 + block@2: // switch_case_1_L82 + let hello#0: bytes = "Hello False" + (log hello#0) + goto block@4 + block@3: // switch_case_default_L77 + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/out/contract_MyContract.parallel_copies.ir b/examples/match/out/contract_MyContract.parallel_copies.ir index cac46472d7..7702cda3ac 100644 --- a/examples/match/out/contract_MyContract.parallel_copies.ir +++ b/examples/match/out/contract_MyContract.parallel_copies.ir @@ -2,67 +2,105 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@4} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 (log "Hello") goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 (log "Hello There") goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@4} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 (log "Hello biguint") goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 (log "Hello There biguint") goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@4} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 (log "Hello bytes") goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 (log "Hello There bytes") goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@4} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 (log "Hello address") goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 (log "Hello There address") goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + (log "Hello one") + goto block@4 + block@2: // switch_case_1_L68 + (log "Hello two") + goto block@4 + block@3: // switch_case_default_L63 + (log "Hello default") + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + goto [block@2, block@1, ...block@4][n#0] + block@1: // switch_case_0_L79 + (log "Hello True") + goto block@4 + block@2: // switch_case_1_L82 + (log "Hello False") + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/out/contract_MyContract.post_ssa.ir b/examples/match/out/contract_MyContract.post_ssa.ir index cac46472d7..7702cda3ac 100644 --- a/examples/match/out/contract_MyContract.post_ssa.ir +++ b/examples/match/out/contract_MyContract.post_ssa.ir @@ -2,67 +2,105 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@4} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 (log "Hello") goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 (log "Hello There") goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@4} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 (log "Hello biguint") goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 (log "Hello There biguint") goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@4} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 (log "Hello bytes") goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 (log "Hello There bytes") goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@4} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 (log "Hello address") goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 (log "Hello There address") goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + (log "Hello one") + goto block@4 + block@2: // switch_case_1_L68 + (log "Hello two") + goto block@4 + block@3: // switch_case_default_L63 + (log "Hello default") + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + goto [block@2, block@1, ...block@4][n#0] + block@1: // switch_case_0_L79 + (log "Hello True") + goto block@4 + block@2: // switch_case_1_L82 + (log "Hello False") + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/out/contract_MyContract.ssa.ir b/examples/match/out/contract_MyContract.ssa.ir index 2d2c56d801..e4a1972907 100644 --- a/examples/match/out/contract_MyContract.ssa.ir +++ b/examples/match/out/contract_MyContract.ssa.ir @@ -2,83 +2,128 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@3} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 let hello#0: bytes = "Hello" (log hello#0) goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 let hello#1: bytes = "Hello There" (log hello#1) goto block@4 - block@3: // switch_case_default_L15 + block@3: // switch_case_default_L19 goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@3} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 let hello#0: bytes = "Hello biguint" (log hello#0) goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 let hello#1: bytes = "Hello There biguint" (log hello#1) goto block@4 - block@3: // switch_case_default_L37 + block@3: // switch_case_default_L41 goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@3} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 let hello#0: bytes = "Hello bytes" (log hello#0) goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 let hello#1: bytes = "Hello There bytes" (log hello#1) goto block@4 - block@3: // switch_case_default_L26 + block@3: // switch_case_default_L30 goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@3} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 let hello#0: bytes = "Hello address" (log hello#0) goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 let hello#1: bytes = "Hello There address" (log hello#1) goto block@4 - block@3: // switch_case_default_L48 + block@3: // switch_case_default_L52 goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + let hello#0: bytes = "Hello one" + (log hello#0) + goto block@4 + block@2: // switch_case_1_L68 + let hello#1: bytes = "Hello two" + (log hello#1) + goto block@4 + block@3: // switch_case_default_L63 + let hello#2: bytes = "Hello default" + (log hello#2) + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + switch n#0 {1u => block@1, 0u => block@2, * => block@3} + block@1: // switch_case_0_L79 + let hello#0: bytes = "Hello True" + (log hello#0) + goto block@4 + block@2: // switch_case_1_L82 + let hello#1: bytes = "Hello False" + (log hello#1) + goto block@4 + block@3: // switch_case_default_L77 + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/out/contract_MyContract.ssa.opt_pass_1.ir b/examples/match/out/contract_MyContract.ssa.opt_pass_1.ir index cac46472d7..7702cda3ac 100644 --- a/examples/match/out/contract_MyContract.ssa.opt_pass_1.ir +++ b/examples/match/out/contract_MyContract.ssa.opt_pass_1.ir @@ -2,67 +2,105 @@ contract examples.match.contract.MyContract: program approval: subroutine examples.match.contract.MyContract.approval_program() -> uint64: block@0: // L5 + (app_global_put "case_one" 1u) + (app_global_put "case_two" 2u) examples.match.contract.MyContract.match_uint64() examples.match.contract.MyContract.match_biguint() examples.match.contract.MyContract.match_bytes() examples.match.contract.MyContract.match_address() + examples.match.contract.MyContract.match_attributes() + examples.match.contract.MyContract.match_bools() return 1u subroutine examples.match.contract.MyContract.match_uint64() -> void: - block@0: // L13 + block@0: // L17 let n#0: uint64 = (txn NumAppArgs) switch n#0 {0u => block@1, 10u => block@2, * => block@4} - block@1: // switch_case_0_L17 + block@1: // switch_case_0_L21 (log "Hello") goto block@4 - block@2: // switch_case_1_L20 + block@2: // switch_case_1_L24 (log "Hello There") goto block@4 - block@4: // switch_case_next_L15 + block@4: // switch_case_next_L19 return subroutine examples.match.contract.MyContract.match_biguint() -> void: - block@0: // L35 + block@0: // L39 let tmp%0#0: uint64 = (txn NumAppArgs) let tmp%1#0: bytes = (itob tmp%0#0) let n#0: bytes = (b* tmp%1#0 10b) switch n#0 {0b => block@1, 10b => block@2, * => block@4} - block@1: // switch_case_0_L39 + block@1: // switch_case_0_L43 (log "Hello biguint") goto block@4 - block@2: // switch_case_1_L42 + block@2: // switch_case_1_L46 (log "Hello There biguint") goto block@4 - block@4: // switch_case_next_L37 + block@4: // switch_case_next_L41 return subroutine examples.match.contract.MyContract.match_bytes() -> void: - block@0: // L24 + block@0: // L28 let n#0: bytes = (txna ApplicationArgs 0) switch n#0 {"" => block@1, "10" => block@2, * => block@4} - block@1: // switch_case_0_L28 + block@1: // switch_case_0_L32 (log "Hello bytes") goto block@4 - block@2: // switch_case_1_L31 + block@2: // switch_case_1_L35 (log "Hello There bytes") goto block@4 - block@4: // switch_case_next_L26 + block@4: // switch_case_next_L30 return subroutine examples.match.contract.MyContract.match_address() -> void: - block@0: // L46 + block@0: // L50 let n#0: bytes = (txn Sender) switch n#0 {addr AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ => block@1, addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA => block@2, * => block@4} - block@1: // switch_case_0_L50 + block@1: // switch_case_0_L54 (log "Hello address") goto block@4 - block@2: // switch_case_1_L53 + block@2: // switch_case_1_L57 (log "Hello There address") goto block@4 - block@4: // switch_case_next_L48 + block@4: // switch_case_next_L52 + return + + subroutine examples.match.contract.MyContract.match_attributes() -> void: + block@0: // L61 + let n#0: uint64 = (txn NumAppArgs) + let (app_global_get_ex_value%0#0: uint64, app_global_get_ex_did_exist%1#0: uint64) = (app_global_get_ex 0u "case_one") + (assert app_global_get_ex_did_exist%1#0) // check value exists + let (app_global_get_ex_value%2#0: uint64, app_global_get_ex_did_exist%3#0: uint64) = (app_global_get_ex 0u "case_two") + (assert app_global_get_ex_did_exist%3#0) // check value exists + switch n#0 {app_global_get_ex_value%0#0 => block@1, app_global_get_ex_value%2#0 => block@2, * => block@3} + block@1: // switch_case_0_L65 + (log "Hello one") + goto block@4 + block@2: // switch_case_1_L68 + (log "Hello two") + goto block@4 + block@3: // switch_case_default_L63 + (log "Hello default") + goto block@4 + block@4: // switch_case_next_L63 + return + + subroutine examples.match.contract.MyContract.match_bools() -> void: + block@0: // L75 + let tmp%0#0: uint64 = (txn NumAppArgs) + let n#0: uint64 = (> tmp%0#0 0u) + goto [block@2, block@1, ...block@4][n#0] + block@1: // switch_case_0_L79 + (log "Hello True") + goto block@4 + block@2: // switch_case_1_L82 + (log "Hello False") + goto block@4 + block@4: // switch_case_next_L77 return program clear-state: subroutine examples.match.contract.MyContract.clear_state_program() -> uint64: - block@0: // L56 + block@0: // L85 return 1u \ No newline at end of file diff --git a/examples/match/puya.log b/examples/match/puya.log index 19bc0eb55a..fe6dbbb627 100644 --- a/examples/match/puya.log +++ b/examples/match/puya.log @@ -3,50 +3,70 @@ debug: Building AWST for __init__.py debug: Building AWST for match debug: Building AWST for embedded puyapy lib at /puyapy.py debug: Building AWST for match/contract.py -debug: Sealing block@0: // L13 -debug: Terminated block@0: // L13 -debug: Sealing block@None: // switch_case_default_L15 -debug: Sealing block@None: // switch_case_0_L17 -debug: Sealing block@None: // switch_case_1_L20 -debug: Terminated block@1: // switch_case_0_L17 -debug: Terminated block@2: // switch_case_1_L20 -debug: Terminated block@3: // switch_case_default_L15 -debug: Sealing block@4: // switch_case_next_L15 -debug: Terminated block@4: // switch_case_next_L15 -debug: Sealing block@0: // L35 -debug: Terminated block@0: // L35 -debug: Sealing block@None: // switch_case_default_L37 -debug: Sealing block@None: // switch_case_0_L39 -debug: Sealing block@None: // switch_case_1_L42 -debug: Terminated block@1: // switch_case_0_L39 -debug: Terminated block@2: // switch_case_1_L42 -debug: Terminated block@3: // switch_case_default_L37 -debug: Sealing block@4: // switch_case_next_L37 -debug: Terminated block@4: // switch_case_next_L37 -debug: Sealing block@0: // L24 -debug: Terminated block@0: // L24 -debug: Sealing block@None: // switch_case_default_L26 -debug: Sealing block@None: // switch_case_0_L28 -debug: Sealing block@None: // switch_case_1_L31 -debug: Terminated block@1: // switch_case_0_L28 -debug: Terminated block@2: // switch_case_1_L31 -debug: Terminated block@3: // switch_case_default_L26 -debug: Sealing block@4: // switch_case_next_L26 -debug: Terminated block@4: // switch_case_next_L26 -debug: Sealing block@0: // L46 -debug: Terminated block@0: // L46 -debug: Sealing block@None: // switch_case_default_L48 -debug: Sealing block@None: // switch_case_0_L50 -debug: Sealing block@None: // switch_case_1_L53 -debug: Terminated block@1: // switch_case_0_L50 -debug: Terminated block@2: // switch_case_1_L53 -debug: Terminated block@3: // switch_case_default_L48 -debug: Sealing block@4: // switch_case_next_L48 -debug: Terminated block@4: // switch_case_next_L48 +debug: Sealing block@0: // L17 +debug: Terminated block@0: // L17 +debug: Sealing block@None: // switch_case_default_L19 +debug: Sealing block@None: // switch_case_0_L21 +debug: Sealing block@None: // switch_case_1_L24 +debug: Terminated block@1: // switch_case_0_L21 +debug: Terminated block@2: // switch_case_1_L24 +debug: Terminated block@3: // switch_case_default_L19 +debug: Sealing block@4: // switch_case_next_L19 +debug: Terminated block@4: // switch_case_next_L19 +debug: Sealing block@0: // L39 +debug: Terminated block@0: // L39 +debug: Sealing block@None: // switch_case_default_L41 +debug: Sealing block@None: // switch_case_0_L43 +debug: Sealing block@None: // switch_case_1_L46 +debug: Terminated block@1: // switch_case_0_L43 +debug: Terminated block@2: // switch_case_1_L46 +debug: Terminated block@3: // switch_case_default_L41 +debug: Sealing block@4: // switch_case_next_L41 +debug: Terminated block@4: // switch_case_next_L41 +debug: Sealing block@0: // L28 +debug: Terminated block@0: // L28 +debug: Sealing block@None: // switch_case_default_L30 +debug: Sealing block@None: // switch_case_0_L32 +debug: Sealing block@None: // switch_case_1_L35 +debug: Terminated block@1: // switch_case_0_L32 +debug: Terminated block@2: // switch_case_1_L35 +debug: Terminated block@3: // switch_case_default_L30 +debug: Sealing block@4: // switch_case_next_L30 +debug: Terminated block@4: // switch_case_next_L30 +debug: Sealing block@0: // L50 +debug: Terminated block@0: // L50 +debug: Sealing block@None: // switch_case_default_L52 +debug: Sealing block@None: // switch_case_0_L54 +debug: Sealing block@None: // switch_case_1_L57 +debug: Terminated block@1: // switch_case_0_L54 +debug: Terminated block@2: // switch_case_1_L57 +debug: Terminated block@3: // switch_case_default_L52 +debug: Sealing block@4: // switch_case_next_L52 +debug: Terminated block@4: // switch_case_next_L52 +debug: Sealing block@0: // L61 +debug: Terminated block@0: // L61 +debug: Sealing block@None: // switch_case_default_L63 +debug: Sealing block@None: // switch_case_0_L65 +debug: Sealing block@None: // switch_case_1_L68 +debug: Terminated block@1: // switch_case_0_L65 +debug: Terminated block@2: // switch_case_1_L68 +debug: Terminated block@3: // switch_case_default_L63 +debug: Sealing block@4: // switch_case_next_L63 +debug: Terminated block@4: // switch_case_next_L63 +debug: Sealing block@0: // L75 +debug: Terminated block@0: // L75 +debug: Sealing block@None: // switch_case_default_L77 +debug: Sealing block@None: // switch_case_0_L79 +debug: Sealing block@None: // switch_case_1_L82 +debug: Terminated block@1: // switch_case_0_L79 +debug: Terminated block@2: // switch_case_1_L82 +debug: Terminated block@3: // switch_case_default_L77 +debug: Sealing block@4: // switch_case_next_L77 +debug: Terminated block@4: // switch_case_next_L77 debug: Sealing block@0: // L5 debug: Terminated block@0: // L5 -debug: Sealing block@0: // L56 -debug: Terminated block@0: // L56 +debug: Sealing block@0: // L85 +debug: Terminated block@0: // L85 debug: Output IR to /examples/match/out/contract_MyContract.ssa.ir info: Optimizing examples.match.contract.MyContract at level 1 debug: Begin optimization pass 1/100 @@ -73,7 +93,7 @@ debug: Removing unused variable hello#1 debug: Optimizer: Simplify Conditional Branches debug: Optimizer: Remove Linear Jump debug: Optimizer: Remove Empty Blocks -debug: Removed empty block: block@3: // switch_case_default_L15 +debug: Removed empty block: block@3: // switch_case_default_L19 debug: Optimizer: Remove Unreachable Blocks debug: Optimizing subroutine examples.match.contract.MyContract.match_biguint debug: Splitting parallel copies prior to optimization @@ -87,7 +107,7 @@ debug: Removing unused variable hello#1 debug: Optimizer: Simplify Conditional Branches debug: Optimizer: Remove Linear Jump debug: Optimizer: Remove Empty Blocks -debug: Removed empty block: block@3: // switch_case_default_L37 +debug: Removed empty block: block@3: // switch_case_default_L41 debug: Optimizer: Remove Unreachable Blocks debug: Optimizing subroutine examples.match.contract.MyContract.match_bytes debug: Splitting parallel copies prior to optimization @@ -101,7 +121,7 @@ debug: Removing unused variable hello#1 debug: Optimizer: Simplify Conditional Branches debug: Optimizer: Remove Linear Jump debug: Optimizer: Remove Empty Blocks -debug: Removed empty block: block@3: // switch_case_default_L26 +debug: Removed empty block: block@3: // switch_case_default_L30 debug: Optimizer: Remove Unreachable Blocks debug: Optimizing subroutine examples.match.contract.MyContract.match_address debug: Splitting parallel copies prior to optimization @@ -115,7 +135,36 @@ debug: Removing unused variable hello#1 debug: Optimizer: Simplify Conditional Branches debug: Optimizer: Remove Linear Jump debug: Optimizer: Remove Empty Blocks -debug: Removed empty block: block@3: // switch_case_default_L48 +debug: Removed empty block: block@3: // switch_case_default_L52 +debug: Optimizer: Remove Unreachable Blocks +debug: Optimizing subroutine examples.match.contract.MyContract.match_attributes +debug: Splitting parallel copies prior to optimization +debug: Optimizer: Arithmetic Simplification +debug: Optimizer: Constant Replacer +debug: Optimizer: Copy Propagation +debug: Optimizer: Intrinsic Simplifier +debug: Optimizer: Remove Unused Variables +debug: Removing unused variable hello#0 +debug: Removing unused variable hello#1 +debug: Removing unused variable hello#2 +debug: Optimizer: Simplify Conditional Branches +debug: Optimizer: Remove Linear Jump +debug: Optimizer: Remove Empty Blocks +debug: Optimizer: Remove Unreachable Blocks +debug: Optimizing subroutine examples.match.contract.MyContract.match_bools +debug: Splitting parallel copies prior to optimization +debug: Optimizer: Arithmetic Simplification +debug: Optimizer: Constant Replacer +debug: Optimizer: Copy Propagation +debug: Optimizer: Intrinsic Simplifier +debug: Optimizer: Remove Unused Variables +debug: Removing unused variable hello#0 +debug: Removing unused variable hello#1 +debug: Optimizer: Simplify Conditional Branches +debug: Switch switch n#0 {1u => block@1, 0u => block@2, * => block@3} simplified to goto [block@2, block@1, ...block@3][n#0] +debug: Optimizer: Remove Linear Jump +debug: Optimizer: Remove Empty Blocks +debug: Removed empty block: block@3: // switch_case_default_L77 debug: Optimizer: Remove Unreachable Blocks debug: Optimizing subroutine examples.match.contract.MyContract.clear_state_program debug: Splitting parallel copies prior to optimization @@ -180,6 +229,26 @@ debug: Optimizer: Simplify Conditional Branches debug: Optimizer: Remove Linear Jump debug: Optimizer: Remove Empty Blocks debug: Optimizer: Remove Unreachable Blocks +debug: Optimizing subroutine examples.match.contract.MyContract.match_attributes +debug: Optimizer: Arithmetic Simplification +debug: Optimizer: Constant Replacer +debug: Optimizer: Copy Propagation +debug: Optimizer: Intrinsic Simplifier +debug: Optimizer: Remove Unused Variables +debug: Optimizer: Simplify Conditional Branches +debug: Optimizer: Remove Linear Jump +debug: Optimizer: Remove Empty Blocks +debug: Optimizer: Remove Unreachable Blocks +debug: Optimizing subroutine examples.match.contract.MyContract.match_bools +debug: Optimizer: Arithmetic Simplification +debug: Optimizer: Constant Replacer +debug: Optimizer: Copy Propagation +debug: Optimizer: Intrinsic Simplifier +debug: Optimizer: Remove Unused Variables +debug: Optimizer: Simplify Conditional Branches +debug: Optimizer: Remove Linear Jump +debug: Optimizer: Remove Empty Blocks +debug: Optimizer: Remove Unreachable Blocks debug: Optimizing subroutine examples.match.contract.MyContract.clear_state_program debug: Optimizer: Arithmetic Simplification debug: Optimizer: Constant Replacer @@ -197,6 +266,8 @@ debug: Removing Phis from examples.match.contract.MyContract.match_uint64 debug: Removing Phis from examples.match.contract.MyContract.match_biguint debug: Removing Phis from examples.match.contract.MyContract.match_bytes debug: Removing Phis from examples.match.contract.MyContract.match_address +debug: Removing Phis from examples.match.contract.MyContract.match_attributes +debug: Removing Phis from examples.match.contract.MyContract.match_bools debug: Removing Phis from examples.match.contract.MyContract.clear_state_program debug: Output IR to /examples/match/out/contract_MyContract.post_ssa.ir debug: Sequentializing parallel copies in examples.match.contract.MyContract.approval_program @@ -204,6 +275,8 @@ debug: Sequentializing parallel copies in examples.match.contract.MyContract.mat debug: Sequentializing parallel copies in examples.match.contract.MyContract.match_biguint debug: Sequentializing parallel copies in examples.match.contract.MyContract.match_bytes debug: Sequentializing parallel copies in examples.match.contract.MyContract.match_address +debug: Sequentializing parallel copies in examples.match.contract.MyContract.match_attributes +debug: Sequentializing parallel copies in examples.match.contract.MyContract.match_bools debug: Sequentializing parallel copies in examples.match.contract.MyContract.clear_state_program debug: Output IR to /examples/match/out/contract_MyContract.parallel_copies.ir debug: Coalescing local variables in examples.match.contract.MyContract.approval_program using strategy RootOperandGrouping @@ -216,6 +289,10 @@ debug: Coalescing local variables in examples.match.contract.MyContract.match_by debug: Coalescing resulted in 0 replacement/s debug: Coalescing local variables in examples.match.contract.MyContract.match_address using strategy RootOperandGrouping debug: Coalescing resulted in 0 replacement/s +debug: Coalescing local variables in examples.match.contract.MyContract.match_attributes using strategy RootOperandGrouping +debug: Coalescing resulted in 0 replacement/s +debug: Coalescing local variables in examples.match.contract.MyContract.match_bools using strategy RootOperandGrouping +debug: Coalescing resulted in 0 replacement/s debug: Coalescing local variables in examples.match.contract.MyContract.clear_state_program using strategy RootOperandGrouping debug: Coalescing resulted in 0 replacement/s debug: Output IR to /examples/match/out/contract_MyContract.final.ir @@ -235,6 +312,22 @@ debug: Found 1 edge set/s for examples.match.contract.MyContract.match_bytes debug: Inserted match_address_block@0.ops[1]: 'store n#0 to l-stack (copy)' debug: Replaced match_address_block@0.ops[5]: 'load n#0' with 'load n#0 from l-stack (no copy)' debug: Found 1 edge set/s for examples.match.contract.MyContract.match_address +debug: Inserted match_attributes_block@0.ops[5]: 'store app_global_get_ex_did_exist%1#0 to l-stack (copy)' +debug: Replaced match_attributes_block@0.ops[8]: 'load app_global_get_ex_did_exist%1#0' with 'load app_global_get_ex_did_exist%1#0 from l-stack (no copy)' +debug: Inserted match_attributes_block@0.ops[13]: 'store app_global_get_ex_did_exist%3#0 to l-stack (copy)' +debug: Replaced match_attributes_block@0.ops[16]: 'load app_global_get_ex_did_exist%3#0' with 'load app_global_get_ex_did_exist%3#0 from l-stack (no copy)' +debug: Inserted match_attributes_block@0.ops[15]: 'store app_global_get_ex_value%2#0 to l-stack (copy)' +debug: Replaced match_attributes_block@0.ops[20]: 'load app_global_get_ex_value%2#0' with 'load app_global_get_ex_value%2#0 from l-stack (no copy)' +debug: Inserted match_attributes_block@0.ops[7]: 'store app_global_get_ex_value%0#0 to l-stack (copy)' +debug: Replaced match_attributes_block@0.ops[20]: 'load app_global_get_ex_value%0#0' with 'load app_global_get_ex_value%0#0 from l-stack (no copy)' +debug: Inserted match_attributes_block@0.ops[1]: 'store n#0 to l-stack (copy)' +debug: Replaced match_attributes_block@0.ops[23]: 'load n#0' with 'load n#0 from l-stack (no copy)' +debug: Found 2 edge set/s for examples.match.contract.MyContract.match_attributes +debug: Inserted match_bools_block@0.ops[1]: 'store tmp%0#0 to l-stack (copy)' +debug: Replaced match_bools_block@0.ops[3]: 'load tmp%0#0' with 'load tmp%0#0 from l-stack (no copy)' +debug: Inserted match_bools_block@0.ops[6]: 'store n#0 to l-stack (copy)' +debug: Replaced match_bools_block@0.ops[8]: 'load n#0' with 'load n#0 from l-stack (no copy)' +debug: Found 1 edge set/s for examples.match.contract.MyContract.match_bools info: Writing match/out/contract.approval.teal info: Writing match/out/contract.approval.debug.teal info: Writing match/out/contract.clear.teal diff --git a/examples/sizes.txt b/examples/sizes.txt index d32e7063ba..fb68783ca6 100644 --- a/examples/sizes.txt +++ b/examples/sizes.txt @@ -32,7 +32,7 @@ koopman 12 5 less_simple 93 87 local_storage/local_storage_contract 317 314 local_storage/local_storage_with_offsets 330 328 -match 328 316 +match 486 467 nested_loops 228 203 simple 51 4 simplish 739 725 diff --git a/src/puya/awst_build/subroutine.py b/src/puya/awst_build/subroutine.py index 508d833d8a..60d2176990 100644 --- a/src/puya/awst_build/subroutine.py +++ b/src/puya/awst_build/subroutine.py @@ -457,7 +457,13 @@ def visit_match_stmt(self, stmt: mypy.nodes.MatchStmt) -> Switch | None: match pattern, guard: case mypy.patterns.ValuePattern(expr=case_expr), None: case_value_builder_or_literal = case_expr.accept(self) - case_value = expect_operand_wtype(case_value_builder_or_literal, subject.wtype) + case_value = require_expression_builder(case_value_builder_or_literal).rvalue() + case_block = self.visit_block(block) + case_block_map[case_value] = case_block + case mypy.patterns.SingletonPattern(value=bool() as bool_literal), None: + case_value = BoolConstant( + value=bool_literal, source_location=self._location(pattern) + ) case_block = self.visit_block(block) case_block_map[case_value] = case_block case mypy.patterns.ClassPattern( @@ -486,8 +492,8 @@ def visit_match_stmt(self, stmt: mypy.nodes.MatchStmt) -> Switch | None: ) self._error( f"match statements only support class patterns for {supported_types}" - " or value patterns", - stmt, + ", value patterns or bool literals", + pattern, ) break else: diff --git a/src/puya/lib_embedded/_puyapy_.py b/src/puya/lib_embedded/_puyapy_.py index 2b9643691d..5c831be7db 100644 --- a/src/puya/lib_embedded/_puyapy_.py +++ b/src/puya/lib_embedded/_puyapy_.py @@ -25,9 +25,9 @@ def ensure_budget(required_budget: UInt64, fee_source: UInt64) -> None: CreateInnerTransaction.set_approval_program(Bytes.from_hex("068101")) CreateInnerTransaction.set_clear_state_program(Bytes.from_hex("068101")) match fee_source: - case 0: + case UInt64(0): CreateInnerTransaction.set_fee(0) - case 1: + case UInt64(1): CreateInnerTransaction.set_fee(Global.min_txn_fee()) CreateInnerTransaction.submit()