# HG changeset patch # User paulb@localhost.localdomain # Date 1164929526 -3600 # Node ID 7185f75492b3f36bd8770fbc8b25de7f62256542 # Parent 8a7125282e77c8c7e7dda11a33562bfbedf6fb08 Noted operator coverage, adding unary operator viewing and support for floor division. Added a border around pop-up annotation elements. diff -r 8a7125282e77 -r 7185f75492b3 lib/builtins.py --- a/lib/builtins.py Tue Nov 28 00:37:12 2006 +0100 +++ b/lib/builtins.py Fri Dec 01 00:32:06 2006 +0100 @@ -98,6 +98,18 @@ else: raise TypeError + def __floordiv__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + + def __rfloordiv__(self, other): + if isinstance(other, int): + return int() + else: + raise TypeError + def __pow__(self, other): if isinstance(other, int): return int() @@ -362,6 +374,26 @@ else: raise TypeError + def __floordiv__(self, other): + if isinstance(other, int): + return float() + elif isinstance(other, long): + return float() + elif isinstance(other, float): + return float() + else: + raise TypeError + + def __rfloordiv__(self, other): + if isinstance(other, int): + return float() + elif isinstance(other, long): + return float() + elif isinstance(other, float): + return float() + else: + raise TypeError + def __pow__(self, other): if isinstance(other, int): return float() diff -r 8a7125282e77 -r 7185f75492b3 simplify.py --- a/simplify.py Tue Nov 28 00:37:12 2006 +0100 +++ b/simplify.py Fri Dec 01 00:32:06 2006 +0100 @@ -49,15 +49,14 @@ Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard, - For, From, Function, Getattr, Global, If, Import, Invert, Keyword, - Lambda, List, Module, Name, Not, Or, Pass, Raise, Return, Slice, - Stmt, Subscript, TryExcept, TryFinally, Tuple, While, UnaryAdd, - UnarySub. + Div, FloorDiv, For, From, Function, Getattr, Global, If, Import, + Invert, Keyword, Lambda, List, Module, Mul, Name, Not, Or, Pass, + Raise, Return, Slice, Stmt, Sub, Subscript, TryExcept, TryFinally, + Tuple, While, UnaryAdd, UnarySub. - Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div, - Ellipsis, Exec, FloorDiv, LeftShift, ListComp, ListCompFor, - ListCompIf, Mod, Mul, Power, Print, Printnl, RightShift, Sliceobj, - Sub, Yield. + Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis, + Exec, LeftShift, ListComp, ListCompFor, ListCompIf, + Power, Print, Printnl, RightShift, Sliceobj, Yield. """ def __init__(self, builtins=0): @@ -716,6 +715,9 @@ ) ] + self.current_subprograms.pop() + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + result = InvokeBlock(produces_result=1) result.expr = LoadRef(ref=subprogram) return result @@ -726,6 +728,9 @@ def visitDiv(self, div): return self._visitBinary(div, "__div__", "__rdiv__") + def visitFloorDiv(self, floordiv): + return self._visitBinary(floordiv, "__floordiv__", "__rfloordiv__") + def visitMul(self, mul): return self._visitBinary(mul, "__mul__", "__rmul__") diff -r 8a7125282e77 -r 7185f75492b3 tests/operators.py --- a/tests/operators.py Tue Nov 28 00:37:12 2006 +0100 +++ b/tests/operators.py Fri Dec 01 00:32:06 2006 +0100 @@ -1,2 +1,5 @@ a = 1 + 1.1 - 1 b = a + 2 / 2 +c = -a +d = +b +e = a // b diff -r 8a7125282e77 -r 7185f75492b3 viewer.py --- a/viewer.py Tue Nov 28 00:37:12 2006 +0100 +++ b/viewer.py Fri Dec 01 00:32:06 2006 +0100 @@ -121,6 +121,7 @@ display: none; z-index: 2; position: absolute; top: 1em; left: 0.5em; padding: 0.2em; background-color: #000000; + border: 2px solid #dddddd; } .invocations { @@ -188,14 +189,14 @@ Covered: Add, And, AssAttr, AssList, AssName, AssTuple, Assign, AugAssign, Break, CallFunc, Class, Compare, Const, Continue, Dict, Discard, - For, Function, Getattr, If, Keyword, Lambda, List, Module, Name, - Not, Or, Pass, Raise, Return, Slice, Stmt, Subscript, TryExcept, - TryFinally, Tuple, While. + Div, FloorDiv, For, Function, Getattr, If, Keyword, Lambda, List, + Module, Mul, Name, Not, Or, Pass, Raise, Return, Slice, Stmt, Sub, + Subscript, TryExcept, TryFinally, Tuple, UnaryAdd, UnarySub, While. - Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Div, - Ellipsis, Exec, FloorDiv, From, Global, Import, Invert, LeftShift, - ListComp, ListCompFor, ListCompIf, Mod, Mul, Not, Or, Power, Print, - Printnl, RightShift, Sliceobj, Sub, UnaryAdd, UnarySub, Yield. + Missing: Assert, Backquote, Bitand, Bitor, Bitxor, Decorators, Ellipsis, + Exec, From, Global, Import, Invert, LeftShift, ListComp, + ListCompFor, ListCompIf, Mod, Power, Print, Printnl, RightShift, + Sliceobj, Yield. """ def __init__(self, stream): @@ -493,7 +494,7 @@ self.stream.write("\n") self.stream.write("\n") - # Expressions. + # Expression-related helper methods. def _visitBinary(self, node, name, symbol): self.stream.write("\n" % name) @@ -510,6 +511,21 @@ self.dispatch(node.right) self.stream.write("") + def _visitUnary(self, node, name, symbol): + self.stream.write("\n" % name) + self.stream.write("\n") + self.stream.write(symbol) + self._popup_start() + self.stream.write("
\n") + self._invocations_list(node._node) # NOTE: See _visitUnary in simplify. + self.stream.write("
\n") + self._popup_end() + self.stream.write("
\n") + self.dispatch(node.expr) + self.stream.write("
") + + # Expressions. + def visitAdd(self, node): self._visitBinary(node, "add", "+") @@ -606,6 +622,9 @@ def visitDiv(self, node): self._visitBinary(node, "div", "/") + def visitFloorDiv(self, node): + self._visitBinary(node, "floordiv", "//") + def visitGetattr(self, node): self.stream.write("\n") self.dispatch(node.expr) @@ -701,6 +720,12 @@ visitTuple = visitAssTuple + def visitUnaryAdd(self, node): + self._visitUnary(node, "add", "+") + + def visitUnarySub(self, node): + self._visitUnary(node, "sub", "-") + # Output preparation methods. def _text(self, text):