# HG changeset patch # User Paul Boddie # Date 1245014242 -7200 # Node ID 2f452a4c223043198f404f388f16cbe8f3f02825 # Parent 6cf226d3df537400b071431a10f6976b031de5cc Added missing inspection code for AugAssign nodes. Added an RSVP implementation of integer subtraction using a generic arithmetic operator handler method. Expanded test coverage. diff -r 6cf226d3df53 -r 2f452a4c2230 micropython/inspect.py --- a/micropython/inspect.py Sun Jun 14 01:18:05 2009 +0200 +++ b/micropython/inspect.py Sun Jun 14 23:17:22 2009 +0200 @@ -477,7 +477,22 @@ self.importer.use_name(aug_method) self.importer.use_name(left_method) self.importer.use_name(right_method) - return self.OP(node) + + # Process the assignment. + + self.expr = self.dispatch(node.expr) + + # NOTE: Similar to micropython.ast handler code. + # NOTE: Slices and subscripts not supported. + + if isinstance(node.node, compiler.ast.Name): + self.visitAssName(node.node) + elif isinstance(node.node, compiler.ast.Getattr): + self.visitAssAttr(node.node) + else: + raise InspectError(self.full_name(), node, "AugAssign(Slice or Subscript)") + + return None visitBackquote = OP diff -r 6cf226d3df53 -r 2f452a4c2230 rsvp.py --- a/rsvp.py Sun Jun 14 01:18:05 2009 +0200 +++ b/rsvp.py Sun Jun 14 23:17:22 2009 +0200 @@ -754,7 +754,7 @@ # Native function implementations. - def builtins_int_add(self): + def builtins_int_arithmetic_op(self, op): frame = self.local_sp_stack[-1] # Get operands addresses. @@ -781,13 +781,19 @@ # Store the result. # NOTE: The data is considered ready to use. - self.save(addr + 1, self.load(left_data) + self.load(right_data)) + self.save(addr + 1, op(self.load(left_data), self.load(right_data))) # Return the new object. # Introduce object as context for the new object. self.result = addr, addr + def builtins_int_add(self): + return self.builtins_int_arithmetic_op(operator.add) + + def builtins_int_sub(self): + return self.builtins_int_arithmetic_op(operator.sub) + def builtins_int_bool(self): frame = self.local_sp_stack[-1] @@ -950,6 +956,7 @@ "__builtins__.int.__add__" : builtins_int_add, "__builtins__.int.__radd__" : builtins_int_add, # NOTE: To be made distinct. + "__builtins__.int.__sub__" : builtins_int_sub, "__builtins__.int.__iadd__" : builtins_int_add, "__builtins__.int.__bool__" : builtins_int_bool, "__builtins__.int.__neg__" : builtins_int_neg, diff -r 6cf226d3df53 -r 2f452a4c2230 tests/logical2.py --- a/tests/logical2.py Sun Jun 14 01:18:05 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#!/usr/bin/env python - -a = 1 -b = 0 -e = a and b or not a and not b - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 6cf226d3df53 -r 2f452a4c2230 tests/logical_results.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/logical_results.py Sun Jun 14 23:17:22 2009 +0200 @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +a = 1 +b = 0 +e = a and b or not a and not b + +if e is False: + f = 0 +else: + f = 1 + +e = a and b or a and not b + +if e is False: + g = 0 +else: + g = 1 + +result_0 = f +result_1 = g + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 6cf226d3df53 -r 2f452a4c2230 tests/loop_while.py --- a/tests/loop_while.py Sun Jun 14 01:18:05 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#!/usr/bin/env python - -class C: - value = "hello" - x = 10 - while x > 0: - subvalue = "world" - x = x - 1 - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 6cf226d3df53 -r 2f452a4c2230 tests/loop_while_in_class.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/loop_while_in_class.py Sun Jun 14 23:17:22 2009 +0200 @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +class C: + value = "hello" + x = 10 + y = 0 + while x > 0: + y += 1 + x = x - 1 + +result_0 = C.x +result_10 = C.y + +# vim: tabstop=4 expandtab shiftwidth=4