1.1 --- a/lib/builtins.py Fri Sep 04 00:26:30 2009 +0200
1.2 +++ b/lib/builtins.py Thu Sep 24 21:29:29 2009 +0200
1.3 @@ -148,9 +148,18 @@
1.4 def __add__(self, other): pass
1.5 def __iadd__(self, other): pass
1.6 def __str__(self): pass
1.7 - def __iter__(self): pass
1.8 def __bool__(self): pass
1.9
1.10 + def __iter__(self):
1.11 +
1.12 + "Return an iterator."
1.13 +
1.14 + return listiterator(self)
1.15 +
1.16 +class listiterator(object):
1.17 + def __init__(self, l): pass
1.18 + def next(self): pass
1.19 +
1.20 class long(object):
1.21 def __init__(self, number_or_string=None): pass
1.22 def __iadd__(self, other): pass
2.1 --- a/micropython/ast.py Fri Sep 04 00:26:30 2009 +0200
2.2 +++ b/micropython/ast.py Thu Sep 24 21:29:29 2009 +0200
2.3 @@ -201,9 +201,9 @@
2.4 # Binary operators.
2.5
2.6 visitAdd = Helper._visitBinary
2.7 - visitBitand = Helper._visitBinary
2.8 - visitBitor = Helper._visitBinary
2.9 - visitBitxor = Helper._visitBinary
2.10 + visitBitand = Helper._visitBinaryBit
2.11 + visitBitor = Helper._visitBinaryBit
2.12 + visitBitxor = Helper._visitBinaryBit
2.13 visitDiv = Helper._visitBinary
2.14 visitFloorDiv = Helper._visitBinary
2.15 visitLeftShift = Helper._visitBinary
3.1 --- a/micropython/trans.py Fri Sep 04 00:26:30 2009 +0200
3.2 +++ b/micropython/trans.py Thu Sep 24 21:29:29 2009 +0200
3.3 @@ -1065,6 +1065,21 @@
3.4 self.discard_temp(temp)
3.5 self.discard_temp(temp_out)
3.6
3.7 + def _visitBinaryBit(self, node):
3.8 +
3.9 + """
3.10 + Need to impose binary rules over a sequence of nodes. The
3.11 + short-circuiting of the similar logical operators is not imposed by the
3.12 + bitwise operators.
3.13 + """
3.14 +
3.15 + left = None
3.16 +
3.17 + for right in node.nodes:
3.18 + if left is not None:
3.19 + self._visitBinaryMethods(node, left, right)
3.20 + left = right
3.21 +
3.22 def _visitBinary(self, node):
3.23
3.24 """
3.25 @@ -1083,16 +1098,20 @@
3.26 raise TypeError
3.27 """
3.28
3.29 + self._visitBinaryMethods(node, node.left, node.right)
3.30 +
3.31 + def _visitBinaryMethods(self, node, left, right):
3.32 +
3.33 left_method, right_method = binary_methods[node.__class__.__name__]
3.34
3.35 # Evaluate and store the left operand in temporary storage.
3.36
3.37 - self.dispatch(node.left)
3.38 + self.dispatch(left)
3.39 temp1 = self.optimiser.optimise_temp_storage()
3.40
3.41 # Evaluate and store the right operand in temporary storage.
3.42
3.43 - self.dispatch(node.right)
3.44 + self.dispatch(right)
3.45 temp2 = self.optimiser.optimise_temp_storage()
3.46
3.47 temp_out = self._generateBinary(node, temp1, temp2, left_method, right_method)
4.1 --- a/rsvp.py Fri Sep 04 00:26:30 2009 +0200
4.2 +++ b/rsvp.py Thu Sep 24 21:29:29 2009 +0200
4.3 @@ -858,12 +858,6 @@
4.4
4.5 self.machine.result = addr, addr
4.6
4.7 - def builtins_int_add(self):
4.8 - return self.builtins_int_arithmetic_op(operator.add)
4.9 -
4.10 - def builtins_int_sub(self):
4.11 - return self.builtins_int_arithmetic_op(operator.sub)
4.12 -
4.13 def builtins_int_bool(self):
4.14 frame = self.local_sp_stack[-1]
4.15
4.16 @@ -952,6 +946,12 @@
4.17 else:
4.18 self.machine.result = self.false_constant, self.false_constant
4.19
4.20 + def builtins_int_add(self):
4.21 + return self.builtins_int_arithmetic_op(operator.add)
4.22 +
4.23 + def builtins_int_sub(self):
4.24 + return self.builtins_int_arithmetic_op(operator.sub)
4.25 +
4.26 def builtins_int_lt(self):
4.27 return self.builtins_int_op(operator.lt, 0)
4.28
4.29 @@ -970,6 +970,12 @@
4.30 def builtins_int_ne(self):
4.31 return self.builtins_int_op(operator.ne, 1)
4.32
4.33 + def builtins_int_and(self):
4.34 + return self.builtins_int_arithmetic_op(operator.and_)
4.35 +
4.36 + def builtins_int_or(self):
4.37 + return self.builtins_int_arithmetic_op(operator.or_)
4.38 +
4.39 def builtins_bool_bool(self):
4.40 frame = self.local_sp_stack[-1]
4.41
4.42 @@ -1204,6 +1210,10 @@
4.43 "__builtins__.int.__ge__" : builtins_int_ge,
4.44 "__builtins__.int.__eq__" : builtins_int_eq,
4.45 "__builtins__.int.__ne__" : builtins_int_ne,
4.46 + "__builtins__.int.__and__" : builtins_int_and,
4.47 + "__builtins__.int.__rand__" : builtins_int_and,
4.48 + "__builtins__.int.__or__" : builtins_int_or,
4.49 + "__builtins__.int.__ror__" : builtins_int_or,
4.50 "__builtins__.bool.__bool__" : builtins_bool_bool,
4.51 "__builtins__.list.__getitem__" : builtins_list_getitem,
4.52 "__builtins__.list.__len__" : builtins_list_len,
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/bitwise.py Thu Sep 24 21:29:29 2009 +0200
5.3 @@ -0,0 +1,12 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +a = 1
5.7 +b = 2
5.8 +c = 3
5.9 +
5.10 +result_0 = a & b
5.11 +result_1 = a | a & b
5.12 +result_2 = b & c
5.13 +result_3 = a | b
5.14 +
5.15 +# vim: tabstop=4 expandtab shiftwidth=4