micropython

Change of rsvp.py

244:2f452a4c2230
rsvp.py
     1.1 --- a/rsvp.py	Sun Jun 14 01:18:05 2009 +0200
     1.2 +++ b/rsvp.py	Sun Jun 14 23:17:22 2009 +0200
     1.3 @@ -754,7 +754,7 @@
     1.4  
     1.5      # Native function implementations.
     1.6  
     1.7 -    def builtins_int_add(self):
     1.8 +    def builtins_int_arithmetic_op(self, op):
     1.9          frame = self.local_sp_stack[-1]
    1.10  
    1.11          # Get operands addresses.
    1.12 @@ -781,13 +781,19 @@
    1.13          # Store the result.
    1.14          # NOTE: The data is considered ready to use.
    1.15  
    1.16 -        self.save(addr + 1, self.load(left_data) + self.load(right_data))
    1.17 +        self.save(addr + 1, op(self.load(left_data), self.load(right_data)))
    1.18  
    1.19          # Return the new object.
    1.20          # Introduce object as context for the new object.
    1.21  
    1.22          self.result = addr, addr
    1.23  
    1.24 +    def builtins_int_add(self):
    1.25 +        return self.builtins_int_arithmetic_op(operator.add)
    1.26 +
    1.27 +    def builtins_int_sub(self):
    1.28 +        return self.builtins_int_arithmetic_op(operator.sub)
    1.29 +
    1.30      def builtins_int_bool(self):
    1.31          frame = self.local_sp_stack[-1]
    1.32  
    1.33 @@ -950,6 +956,7 @@
    1.34  
    1.35          "__builtins__.int.__add__" : builtins_int_add,
    1.36          "__builtins__.int.__radd__" : builtins_int_add,               # NOTE: To be made distinct.
    1.37 +        "__builtins__.int.__sub__" : builtins_int_sub,
    1.38          "__builtins__.int.__iadd__" : builtins_int_add,
    1.39          "__builtins__.int.__bool__" : builtins_int_bool,
    1.40          "__builtins__.int.__neg__" : builtins_int_neg,