1.1 --- a/lib/builtins.py Tue Nov 28 00:37:12 2006 +0100
1.2 +++ b/lib/builtins.py Fri Dec 01 00:32:06 2006 +0100
1.3 @@ -98,6 +98,18 @@
1.4 else:
1.5 raise TypeError
1.6
1.7 + def __floordiv__(self, other):
1.8 + if isinstance(other, int):
1.9 + return int()
1.10 + else:
1.11 + raise TypeError
1.12 +
1.13 + def __rfloordiv__(self, other):
1.14 + if isinstance(other, int):
1.15 + return int()
1.16 + else:
1.17 + raise TypeError
1.18 +
1.19 def __pow__(self, other):
1.20 if isinstance(other, int):
1.21 return int()
1.22 @@ -362,6 +374,26 @@
1.23 else:
1.24 raise TypeError
1.25
1.26 + def __floordiv__(self, other):
1.27 + if isinstance(other, int):
1.28 + return float()
1.29 + elif isinstance(other, long):
1.30 + return float()
1.31 + elif isinstance(other, float):
1.32 + return float()
1.33 + else:
1.34 + raise TypeError
1.35 +
1.36 + def __rfloordiv__(self, other):
1.37 + if isinstance(other, int):
1.38 + return float()
1.39 + elif isinstance(other, long):
1.40 + return float()
1.41 + elif isinstance(other, float):
1.42 + return float()
1.43 + else:
1.44 + raise TypeError
1.45 +
1.46 def __pow__(self, other):
1.47 if isinstance(other, int):
1.48 return float()
2.1 --- a/simplify.py Tue Nov 28 00:37:12 2006 +0100
2.2 +++ b/simplify.py Fri Dec 01 00:32:06 2006 +0100
2.3 @@ -49,15 +49,14 @@
2.4
2.5 Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign,
2.6 Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard,
2.7 - For, From, Function, Getattr, Global, If, Import, Invert, Keyword,
2.8 - Lambda, List, Module, Name, Not, Or, Pass, Raise, Return, Slice,
2.9 - Stmt, Subscript, TryExcept, TryFinally, Tuple, While, UnaryAdd,
2.10 - UnarySub.
2.11 + Div, FloorDiv, For, From, Function, Getattr, Global, If, Import,
2.12 + Invert, Keyword, Lambda, List, Module, Mul, Name, Not, Or, Pass,
2.13 + Raise, Return, Slice, Stmt, Sub, Subscript, TryExcept, TryFinally,
2.14 + Tuple, While, UnaryAdd, UnarySub.
2.15
2.16 - Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div,
2.17 - Ellipsis, Exec, FloorDiv, LeftShift, ListComp, ListCompFor,
2.18 - ListCompIf, Mod, Mul, Power, Print, Printnl, RightShift, Sliceobj,
2.19 - Sub, Yield.
2.20 + Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis,
2.21 + Exec, LeftShift, ListComp, ListCompFor, ListCompIf,
2.22 + Power, Print, Printnl, RightShift, Sliceobj, Yield.
2.23 """
2.24
2.25 def __init__(self, builtins=0):
2.26 @@ -716,6 +715,9 @@
2.27 )
2.28 ]
2.29
2.30 + self.current_subprograms.pop()
2.31 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
2.32 +
2.33 result = InvokeBlock(produces_result=1)
2.34 result.expr = LoadRef(ref=subprogram)
2.35 return result
2.36 @@ -726,6 +728,9 @@
2.37 def visitDiv(self, div):
2.38 return self._visitBinary(div, "__div__", "__rdiv__")
2.39
2.40 + def visitFloorDiv(self, floordiv):
2.41 + return self._visitBinary(floordiv, "__floordiv__", "__rfloordiv__")
2.42 +
2.43 def visitMul(self, mul):
2.44 return self._visitBinary(mul, "__mul__", "__rmul__")
2.45
3.1 --- a/tests/operators.py Tue Nov 28 00:37:12 2006 +0100
3.2 +++ b/tests/operators.py Fri Dec 01 00:32:06 2006 +0100
3.3 @@ -1,2 +1,5 @@
3.4 a = 1 + 1.1 - 1
3.5 b = a + 2 / 2
3.6 +c = -a
3.7 +d = +b
3.8 +e = a // b
4.1 --- a/viewer.py Tue Nov 28 00:37:12 2006 +0100
4.2 +++ b/viewer.py Fri Dec 01 00:32:06 2006 +0100
4.3 @@ -121,6 +121,7 @@
4.4 display: none; z-index: 2;
4.5 position: absolute; top: 1em; left: 0.5em;
4.6 padding: 0.2em; background-color: #000000;
4.7 + border: 2px solid #dddddd;
4.8 }
4.9
4.10 .invocations {
4.11 @@ -188,14 +189,14 @@
4.12
4.13 Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign,
4.14 Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard,
4.15 - For, Function, Getattr, If, Keyword, Lambda, List, Module, Name,
4.16 - Not, Or, Pass, Raise, Return, Slice, Stmt, Subscript, TryExcept,
4.17 - TryFinally, Tuple, While.
4.18 + Div, FloorDiv, For, Function, Getattr, If, Keyword, Lambda, List,
4.19 + Module, Mul, Name, Not, Or, Pass, Raise, Return, Slice, Stmt, Sub,
4.20 + Subscript, TryExcept, TryFinally, Tuple, UnaryAdd, UnarySub, While.
4.21
4.22 - Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div,
4.23 - Ellipsis, Exec, FloorDiv, From, Global, Import, Invert, LeftShift,
4.24 - ListComp, ListCompFor, ListCompIf, Mod, Mul, Not, Or, Power, Print,
4.25 - Printnl, RightShift, Sliceobj, Sub, UnaryAdd, UnarySub, Yield.
4.26 + Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis,
4.27 + Exec, From, Global, Import, Invert, LeftShift, ListComp,
4.28 + ListCompFor, ListCompIf, Mod, Power, Print, Printnl, RightShift,
4.29 + Sliceobj, Yield.
4.30 """
4.31
4.32 def __init__(self, stream):
4.33 @@ -493,7 +494,7 @@
4.34 self.stream.write("</div>\n")
4.35 self.stream.write("</div>\n")
4.36
4.37 - # Expressions.
4.38 + # Expression-related helper methods.
4.39
4.40 def _visitBinary(self, node, name, symbol):
4.41 self.stream.write("<span class='%s'>\n" % name)
4.42 @@ -510,6 +511,21 @@
4.43 self.dispatch(node.right)
4.44 self.stream.write("</span>")
4.45
4.46 + def _visitUnary(self, node, name, symbol):
4.47 + self.stream.write("<span class='%s'>\n" % name)
4.48 + self.stream.write("<span class='operator'>\n")
4.49 + self.stream.write(symbol)
4.50 + self._popup_start()
4.51 + self.stream.write("<div class='invocations'>\n")
4.52 + self._invocations_list(node._node) # NOTE: See _visitUnary in simplify.
4.53 + self.stream.write("</div>\n")
4.54 + self._popup_end()
4.55 + self.stream.write("</span>\n")
4.56 + self.dispatch(node.expr)
4.57 + self.stream.write("</span>")
4.58 +
4.59 + # Expressions.
4.60 +
4.61 def visitAdd(self, node):
4.62 self._visitBinary(node, "add", "+")
4.63
4.64 @@ -606,6 +622,9 @@
4.65 def visitDiv(self, node):
4.66 self._visitBinary(node, "div", "/")
4.67
4.68 + def visitFloorDiv(self, node):
4.69 + self._visitBinary(node, "floordiv", "//")
4.70 +
4.71 def visitGetattr(self, node):
4.72 self.stream.write("<span class='getattr'>\n")
4.73 self.dispatch(node.expr)
4.74 @@ -701,6 +720,12 @@
4.75
4.76 visitTuple = visitAssTuple
4.77
4.78 + def visitUnaryAdd(self, node):
4.79 + self._visitUnary(node, "add", "+")
4.80 +
4.81 + def visitUnarySub(self, node):
4.82 + self._visitUnary(node, "sub", "-")
4.83 +
4.84 # Output preparation methods.
4.85
4.86 def _text(self, text):