1.1 --- a/micropython/ast.py Wed Aug 24 01:01:24 2011 +0200
1.2 +++ b/micropython/ast.py Wed Aug 24 01:05:46 2011 +0200
1.3 @@ -159,7 +159,7 @@
1.4
1.5 # Store the object as the result.
1.6
1.7 - self.new_op(LoadTemp(0, target="result")) # load the context from the locals
1.8 + self.new_op(LoadTemp(0)) # load the context from the locals
1.9 self.new_op(Return())
1.10
1.11 self.unit.blocks = self.blocks
1.12 @@ -222,6 +222,7 @@
1.13 self.dispatch(node.expr)
1.14
1.15 temp = self.optimiser.optimise_temp_storage()
1.16 + self.new_op(temp)
1.17 self._generateTestBoolean(node.expr, temp)
1.18 self.discard_temp(temp)
1.19
1.20 @@ -775,6 +776,7 @@
1.21 self.dispatch(test)
1.22
1.23 temp = self.optimiser.optimise_temp_storage()
1.24 + self.new_op(temp)
1.25 self._generateTestBoolean(node, temp)
1.26
1.27 next_block = self.new_block()
1.28 @@ -814,7 +816,7 @@
1.29
1.30 self.discard_temp(temp_arg)
1.31
1.32 - self.set_target("exception")
1.33 + self.new_op(Transfer(source="working", target="exception"))
1.34
1.35 self.new_op(RaiseException())
1.36
1.37 @@ -824,8 +826,6 @@
1.38 else:
1.39 self.dispatch(compiler.ast.Name("None"))
1.40
1.41 - self.set_target("result")
1.42 -
1.43 if self.in_exception_handler:
1.44 self.new_op(ClearException(target="exception"))
1.45
1.46 @@ -932,6 +932,7 @@
1.47 self.dispatch(node.test)
1.48
1.49 temp = self.optimiser.optimise_temp_storage()
1.50 + self.new_op(temp)
1.51 self._generateTestBoolean(node, temp)
1.52
1.53 if node.else_ is not None:
2.1 --- a/micropython/code.py Wed Aug 24 01:01:24 2011 +0200
2.2 +++ b/micropython/code.py Wed Aug 24 01:05:46 2011 +0200
2.3 @@ -168,13 +168,6 @@
2.4 self.insert_op(-1, expr)
2.5 self.last_op().source = "source"
2.6
2.7 - def set_working(self, expr):
2.8 - if expr is not None:
2.9 - expr = expr.copy()
2.10 - expr.target = "working"
2.11 - self.insert_op(-1, expr)
2.12 - self.last_op().source = "working"
2.13 -
2.14 def set_target(self, target):
2.15
2.16 "Reset the target of the active instruction to 'target'."
3.1 --- a/micropython/trans.py Wed Aug 24 01:01:24 2011 +0200
3.2 +++ b/micropython/trans.py Wed Aug 24 01:05:46 2011 +0200
3.3 @@ -562,7 +562,7 @@
3.4 # Adjust the invocation frame for unknown invocations.
3.5 # Test the first argument if appropriate.
3.6
3.7 - self._generateCallFuncContextTest(temp_target, target, temp_context, temp_first_argument, node)
3.8 + self._generateCallFuncContextTest(target, temp_context, temp_first_argument, node)
3.9
3.10 # Traverse the keyword arguments adding them at the appropriate frame
3.11 # positions.
3.12 @@ -735,13 +735,13 @@
3.13 self.new_op(LoadAddress(target.default_attrs[pos - nargs_min]))
3.14 self.new_op(StoreFrame(pos))
3.15
3.16 - def _generateCallFuncContextTest(self, temp_target, target, temp_context, temp_first_argument, node):
3.17 + def _generateCallFuncContextTest(self, target, temp_context, temp_first_argument, node):
3.18
3.19 """
3.20 - Generate code to test for 'temp_target', representing the given
3.21 - 'target', the context provided by 'temp_context' against
3.22 - 'temp_first_argument', and to signal an exception (using 'node') if the
3.23 - context is incompatible with the first frame argument.
3.24 + Generate code involved in a call to the given 'target' to test the
3.25 + context provided by 'temp_context' against 'temp_first_argument', and to
3.26 + signal an exception (using 'node') if the context is incompatible with
3.27 + the first frame argument.
3.28
3.29 In addition, the invocation frame will be shifted if 'temp_context'
3.30 indicates a function or a class.
3.31 @@ -770,23 +770,28 @@
3.32 self.new_op(CheckClass(target="status"))
3.33 self.new_op(JumpIfFalse(continue_block, working="status"))
3.34
3.35 + # Test any explicit first argument against the context.
3.36 +
3.37 if temp_first_argument is not None:
3.38 - self.new_op(temp_first_argument)
3.39
3.40 # Check the current value (the argument) against the known context
3.41 # (given as the source).
3.42
3.43 - self.new_op(CheckInstance(target="status"))
3.44 - self.set_working(temp_context)
3.45 + temp_context = temp_context.copy()
3.46 + temp_context.target = "source"
3.47 + self.new_op(temp_context)
3.48 + self.new_op(temp_first_argument)
3.49 + self.new_op(CheckInstance(source="source", target="status"))
3.50
3.51 - self.new_op(JumpIfTrue(adjust_block, working="status"))
3.52 + if target is None:
3.53 + self.new_op(JumpIfTrue(adjust_block, working="status"))
3.54 + else:
3.55 + self.new_op(JumpIfTrue(continue_block, working="status"))
3.56
3.57 # Where the context is inappropriate, drop the incomplete frame and
3.58 # raise an exception.
3.59
3.60 self.new_op(DropFrame())
3.61 - self.new_op(Transfer(source="result", target="working"))
3.62 - self.new_op(Transfer(source="result_context", target="working_context"))
3.63
3.64 self.make_exception("TypeError")
3.65 self.set_target("exception")
3.66 @@ -824,9 +829,6 @@
3.67 "Finish the invocation and tidy up afterwards."
3.68
3.69 self.new_op(DropFrame())
3.70 - if load_result:
3.71 - self.new_op(Transfer(source="result", target="working"))
3.72 - self.new_op(Transfer(source="result_context", target="working_context"))
3.73
3.74 # Discard any temporary storage instructions.
3.75
3.76 @@ -836,6 +838,10 @@
3.77 if temp_context is not None:
3.78 self.discard_temp(temp_context)
3.79
3.80 + # Reset the active values.
3.81 +
3.82 + self.optimiser.reset()
3.83 +
3.84 def _visitFunctionDeclaration(self, node):
3.85
3.86 """
3.87 @@ -933,7 +939,6 @@
3.88 if not fn.is_lambda():
3.89 self.dispatch(compiler.ast.Name("None"))
3.90
3.91 - self.set_target("result")
3.92 self.new_op(Return())
3.93
3.94 # Make sure that enough frame space is reserved from the start.
4.1 --- a/rsvp.py Wed Aug 24 01:01:24 2011 +0200
4.2 +++ b/rsvp.py Wed Aug 24 01:05:46 2011 +0200
4.3 @@ -46,7 +46,6 @@
4.4
4.5 * Registers: working context/value,
4.6 assignment source context/value,
4.7 - current result context/value,
4.8 current exception value,
4.9 boolean status value
4.10 """
4.11 @@ -125,8 +124,6 @@
4.12 "working_context",
4.13 "source",
4.14 "source_context",
4.15 - "result",
4.16 - "result_context",
4.17 "exception",
4.18 "status"
4.19 )
5.1 --- a/rsvplib.py Wed Aug 24 01:01:24 2011 +0200
5.2 +++ b/rsvplib.py Wed Aug 24 01:05:46 2011 +0200
5.3 @@ -92,8 +92,8 @@
5.4 # Return the new object.
5.5 # Introduce object as context for the new object.
5.6
5.7 - self.machine.LoadImmediate(addr, "result_context")
5.8 - self.machine.LoadImmediate(addr, "result")
5.9 + self.machine.LoadImmediate(addr, "working_context")
5.10 + self.machine.LoadImmediate(addr, "working")
5.11
5.12 def native_logical_op(self, op):
5.13 left = self.machine.load_from_frame(0)
5.14 @@ -105,11 +105,11 @@
5.15 # NOTE: The data is considered ready to use.
5.16
5.17 if op(self.machine.load(left_data), self.machine.load(right_data)):
5.18 - self.machine.LoadImmediate(self.constants[True], "result_context")
5.19 - self.machine.LoadImmediate(self.constants[True], "result")
5.20 + self.machine.LoadImmediate(self.constants[True], "working_context")
5.21 + self.machine.LoadImmediate(self.constants[True], "working")
5.22 else:
5.23 - self.machine.LoadImmediate(self.constants[False], "result_context")
5.24 - self.machine.LoadImmediate(self.constants[False], "result")
5.25 + self.machine.LoadImmediate(self.constants[False], "working_context")
5.26 + self.machine.LoadImmediate(self.constants[False], "working")
5.27
5.28 # Operators.
5.29 # Although this takes a short-cut by using the operator module, testing is
5.30 @@ -167,8 +167,8 @@
5.31 # Return the new object.
5.32 # Introduce object as context for the new object.
5.33
5.34 - self.machine.LoadImmediate(addr, "result_context")
5.35 - self.machine.LoadImmediate(addr, "result")
5.36 + self.machine.LoadImmediate(addr, "working_context")
5.37 + self.machine.LoadImmediate(addr, "working")
5.38
5.39 # Various built-in methods.
5.40
5.41 @@ -212,8 +212,8 @@
5.42 # Get the item itself.
5.43
5.44 data = self.machine.load(fragment.ref + self.fragment_data_offset + item_pos)
5.45 - self.machine.LoadImmediate(data.context, "result_context")
5.46 - self.machine.LoadImmediate(data.ref, "result")
5.47 + self.machine.LoadImmediate(data.context, "working_context")
5.48 + self.machine.LoadImmediate(data.ref, "working")
5.49
5.50 def builtins_list_len(self):
5.51 obj_value = self.machine.load_from_frame(0)
5.52 @@ -240,8 +240,8 @@
5.53 # Return the new object.
5.54 # Introduce object as context for the new object.
5.55
5.56 - self.machine.LoadImmediate(addr, "result_context")
5.57 - self.machine.LoadImmediate(addr, "result")
5.58 + self.machine.LoadImmediate(addr, "working_context")
5.59 + self.machine.LoadImmediate(addr, "working")
5.60
5.61 def builtins_list_append(self):
5.62 obj_value = self.machine.load_from_frame(0)
5.63 @@ -302,8 +302,8 @@
5.64 fragment_member = obj_value.ref + self.instance_data_offset
5.65
5.66 if self.machine._CheckInstance(obj_value.ref, self.tuple_class):
5.67 - self.machine.LoadImmediate(obj_value.context, "result_context")
5.68 - self.machine.LoadImmediate(obj_value.ref, "result")
5.69 + self.machine.LoadImmediate(obj_value.context, "working_context")
5.70 + self.machine.LoadImmediate(obj_value.ref, "working")
5.71 return
5.72
5.73 # Reject non-list, non-tuple types.
5.74 @@ -334,8 +334,8 @@
5.75 # Return the new object.
5.76 # Introduce object as context for the new object.
5.77
5.78 - self.machine.LoadImmediate(addr, "result_context")
5.79 - self.machine.LoadImmediate(addr, "result")
5.80 + self.machine.LoadImmediate(addr, "working_context")
5.81 + self.machine.LoadImmediate(addr, "working")
5.82
5.83 def builtins_tuple_len(self):
5.84 obj_value = self.machine.load_from_frame(0)
5.85 @@ -357,8 +357,8 @@
5.86 # Return the new object.
5.87 # Introduce object as context for the new object.
5.88
5.89 - self.machine.LoadImmediate(addr, "result_context")
5.90 - self.machine.LoadImmediate(addr, "result")
5.91 + self.machine.LoadImmediate(addr, "working_context")
5.92 + self.machine.LoadImmediate(addr, "working")
5.93
5.94 def builtins_tuple_get_single_item(self):
5.95 obj_value = self.machine.load_from_frame(0)
5.96 @@ -382,8 +382,8 @@
5.97 # Get the item.
5.98
5.99 data = self.machine.load(fragment_member + item_pos)
5.100 - self.machine.LoadImmediate(data.context, "result_context")
5.101 - self.machine.LoadImmediate(data.ref, "result")
5.102 + self.machine.LoadImmediate(data.context, "working_context")
5.103 + self.machine.LoadImmediate(data.ref, "working")
5.104
5.105 def builtins_getattr(self):
5.106 obj_value = self.machine.load_from_frame(0)
5.107 @@ -412,8 +412,8 @@
5.108 loaded_data = self.machine._LoadAddressContextCond(loaded_data.context, loaded_data.ref, obj_value.ref)
5.109 else:
5.110 loaded_data = self.machine.load(obj_value.ref + offset)
5.111 - self.machine.LoadImmediate(loaded_data.context, "result_context")
5.112 - self.machine.LoadImmediate(loaded_data.ref, "result")
5.113 + self.machine.LoadImmediate(loaded_data.context, "working_context")
5.114 + self.machine.LoadImmediate(loaded_data.ref, "working")
5.115 return
5.116
5.117 self.machine.LoadImmediate(self.machine._MakeObject(self.instance_size, self.attr_error_instance), "exception")
5.118 @@ -424,11 +424,11 @@
5.119 cls_value = self.machine.load_from_frame(1)
5.120
5.121 if self.machine._CheckInstance(obj_value.ref, cls_value.ref):
5.122 - self.machine.LoadImmediate(self.constants[True], "result_context")
5.123 - self.machine.LoadImmediate(self.constants[True], "result")
5.124 + self.machine.LoadImmediate(self.constants[True], "working_context")
5.125 + self.machine.LoadImmediate(self.constants[True], "working")
5.126 else:
5.127 - self.machine.LoadImmediate(self.constants[False], "result_context")
5.128 - self.machine.LoadImmediate(self.constants[False], "result")
5.129 + self.machine.LoadImmediate(self.constants[False], "working_context")
5.130 + self.machine.LoadImmediate(self.constants[False], "working")
5.131
5.132 def builtins_print(self):
5.133 # NOTE: Do nothing for now.