Skip to content

Commit

Permalink
Ite -> If
Browse files Browse the repository at this point in the history
  • Loading branch information
Shumo Chu committed Feb 5, 2020
1 parent 7e7fb86 commit 7c99fba
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
8 changes: 6 additions & 2 deletions docs/control_structures.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Control Structures
==================
.. _conditionals:

Conditionals
============


7 changes: 4 additions & 3 deletions examples/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
Txn.receiver() == Global.zero_address(),
Txn.first_valid() == tmpl_timeout)

split = split_core.And(Ite(Global.group_size() == Int(2),
split_transfer,
split_close))
split = And(split_core,
If(Global.group_size() == Int(2),
split_transfer,
split_close))

print(split.teal())
10 changes: 5 additions & 5 deletions pyteal/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def type_of(self):
return type_of_field[self.field]


class Ite(NaryExpr):
class If(NaryExpr):

#default constructor
def __init__(self, arg0:Expr, arg1:Expr, arg2:Expr):
Expand All @@ -740,7 +740,7 @@ def __teal__(self):
return ret

def __str__(self):
return "(Ite {} {} {})".format(self.args[0], self.args[1], self.args[2])
return "(If {} {} {})".format(self.args[0], self.args[1], self.args[2])

def type_of(self):
return self.args[1].type_of()
Expand Down Expand Up @@ -984,13 +984,13 @@ def __init__(self, *argv):
self.args = argv

def __teal__(self):
# converting cond to ite first
def make_ite(conds):
# converting cond to if first
def make_if(conds):
if len(conds) == 0:
return Err()
else:
e = conds[0]
return Ite(e[0], e[1], make_ite(conds[1:]))
return If(e[0], e[1], make_if(conds[1:]))

desugared = make_ite(self.args)
return desugared.__teal__()
Expand Down
6 changes: 3 additions & 3 deletions tests/compile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def test_split():
Txn.first_valid() > tmpl_timeout)

split = And(split_core,
Ite(Global.group_size() == Int(2),
split_transfer,
split_close))
If(Global.group_size() == Int(2),
split_transfer,
split_close))

target = """txn TypeEnum
int 1
Expand Down
8 changes: 4 additions & 4 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ def test_gtxn():
Gtxn.tx_id(1)


def test_ite():
Ite(Int(0), Txn.sender(), Txn.receiver())
def test_if():
If(Int(0), Txn.sender(), Txn.receiver())

with pytest.raises(TealTypeError):
Ite(Int(0), Txn.amount(), Txn.sender())
If(Int(0), Txn.amount(), Txn.sender())

with pytest.raises(TealTypeError):
Ite(Txn.sender(), Int(1), Int(0))
If(Txn.sender(), Int(1), Int(0))


def test_itob():
Expand Down

0 comments on commit 7c99fba

Please sign in to comment.