1.1 --- a/micropython/ast.py Sat Aug 07 02:06:15 2010 +0200
1.2 +++ b/micropython/ast.py Mon Aug 09 01:23:05 2010 +0200
1.3 @@ -287,7 +287,7 @@
1.4
1.5 for op in node.ops:
1.6 op_name, next_node = op
1.7 - methods = comparison_methods[op_name]
1.8 + operator_fn = operator_functions.get(op_name)
1.9
1.10 # Propagate the arguments as we traverse the construct.
1.11
1.12 @@ -298,13 +298,15 @@
1.13 # Use the appropriate mechanism, setting the boolean status for the
1.14 # comparison.
1.15
1.16 - if methods is not None:
1.17 - left_method, right_method = methods
1.18 + if operator_fn is not None:
1.19 +
1.20 + # Generate function call using evaluated argument and next node.
1.21
1.22 - # Generate method call using evaluated argument and next node.
1.23 + temp_fn = self._generateOperatorFunction(op_name)
1.24 + self._generateInvocation(temp_fn, (temp1, temp2))
1.25 + self.discard_temp(temp_fn)
1.26
1.27 - temp_result = self._generateBinary(node, temp1, temp2, left_method, right_method)
1.28 - self.new_op(temp_result)
1.29 + temp_result = self.optimiser.optimise_temp_storage()
1.30 self._generateTestBoolean(node, temp_result)
1.31 self.discard_temp(temp_result)
1.32
1.33 @@ -330,14 +332,7 @@
1.34 # Add arguments.
1.35 # NOTE: No support for defaults.
1.36
1.37 - self._startCallFunc()
1.38 - self.new_op(temp2)
1.39 - self.new_op(StoreFrame(0))
1.40 - self.new_op(temp1)
1.41 - self.new_op(StoreFrame(1))
1.42 - self._endCallFuncArgs(2)
1.43 - self._doCallFunc(temp_method)
1.44 - self._endCallFunc(temp_method)
1.45 + self._generateInvocation(temp_method, (temp2, temp1))
1.46
1.47 temp_result = self.get_temp()
1.48 self._generateTestBoolean(node, temp_result)
1.49 @@ -519,34 +514,15 @@
1.50 visitAssTuple = visitAssList
1.51
1.52 def visitAugAssign(self, node):
1.53 - use_binary_block = self.new_block()
1.54 - end_block = self.new_block()
1.55
1.56 - # Evaluate the expression.
1.57 -
1.58 - self.dispatch(node.expr)
1.59 - temp2 = self.optimiser.optimise_temp_storage()
1.60 -
1.61 - # Evaluate the target.
1.62 + # Find the augmented assignment function and attempt to use it.
1.63
1.64 - self.dispatch(node.node)
1.65 - temp1 = self.optimiser.optimise_temp_storage()
1.66 -
1.67 - # Find the augmented assignment method and attempt to use it.
1.68 -
1.69 - aug_method, (left_method, right_method) = augassign_methods[node.op]
1.70 - temp_out = self._generateOpMethod(node, temp1, temp2, aug_method, use_binary_block, use_binary_block, end_block)
1.71 - self.discard_temp(temp_out) # NOTE: Will re-use the same storage.
1.72 -
1.73 - # Where no such method exists, use the binary operator methods.
1.74 -
1.75 - self.set_block(use_binary_block)
1.76 - temp_out = self._generateBinary(node, temp1, temp2, left_method, right_method)
1.77 + temp_fn = self._getOperatorAugAssignFunction(node)
1.78 + self._visitBinaryCall(node, temp_fn, node.node, node.expr)
1.79 + self.discard_temp(temp_fn)
1.80
1.81 # Assign the result to the name.
1.82
1.83 - self.set_block(end_block)
1.84 - self.new_op(temp_out)
1.85 self.record_value(1)
1.86
1.87 if isinstance(node.node, compiler.ast.Name):
1.88 @@ -558,11 +534,6 @@
1.89
1.90 self.discard_value()
1.91
1.92 - # Compilation duties...
1.93 -
1.94 - self.discard_temp(temp1)
1.95 - self.discard_temp(temp2)
1.96 -
1.97 def visitClass(self, node):
1.98 if not used_by_unit(node):
1.99 return
1.100 @@ -840,12 +811,7 @@
1.101 self.dispatch(node.expr2)
1.102 temp_arg = self.optimiser.optimise_temp_storage()
1.103
1.104 - self._startCallFunc()
1.105 - self.new_op(temp_arg)
1.106 - self.new_op(StoreFrame(0))
1.107 - self._endCallFuncArgs(1)
1.108 - self._doCallFunc(temp)
1.109 - self._endCallFunc(temp)
1.110 + self._generateInvocation(temp, (temp_arg,))
1.111
1.112 self.discard_temp(temp_arg)
1.113