1.1 --- a/micropython/ast.py Fri May 02 01:47:19 2008 +0200
1.2 +++ b/micropython/ast.py Sun May 04 02:42:03 2008 +0200
1.3 @@ -279,10 +279,7 @@
1.4
1.5 # Produce a suitable instruction.
1.6
1.7 - if isinstance(target, micropython.inspect.Const):
1.8 - self.replace_op(AttrInstruction(pos))
1.9 - else:
1.10 - self.replace_op(AddressInstruction(pos))
1.11 + self.replace_op(AddressInstruction(pos))
1.12
1.13 # Where the last operation involves the special 'self' name, check to
1.14 # see if the attribute is acceptably positioned and produce a direct
1.15 @@ -312,7 +309,11 @@
1.16
1.17 # NOTE: Only simple cases are used for optimisations.
1.18
1.19 - target, context = self._optimise_known_target()
1.20 + t = self._optimise_known_target()
1.21 + if t:
1.22 + target, context = t
1.23 + else:
1.24 + target, context = None, None
1.25
1.26 # Where a target is known and has a known context, avoid generating any
1.27 # first argument. Instance methods do not have a known target since they
1.28 @@ -650,11 +651,9 @@
1.29 # A special context is chosen to avoid generating unnecessary
1.30 # context loading and checking instructions.
1.31
1.32 + return target, context
1.33 else:
1.34 - target = None
1.35 - context = None
1.36 -
1.37 - return target, context
1.38 + return None
1.39
1.40 def _optimise_self_access(self, attrname, instruction):
1.41
1.42 @@ -730,9 +729,11 @@
1.43 # Get left method on temp1.
1.44
1.45 self._generateAttr(node, left_method, (LoadAddress, LoadAttr, LoadAttrIndex))
1.46 - self.dispatch(compiler.ast.Name("AttributeError"))
1.47 - self.new_op(CheckException())
1.48 - self.new_op(JumpIfTrue(end_left_label))
1.49 +
1.50 + if not self._optimise_known_target():
1.51 + self.dispatch(compiler.ast.Name("AttributeError"))
1.52 + self.new_op(CheckException())
1.53 + self.new_op(JumpIfTrue(end_left_label))
1.54
1.55 # Add arguments.
1.56
1.57 @@ -763,9 +764,11 @@
1.58 # Get right method on temp2.
1.59
1.60 self._generateAttr(node, right_method, (LoadAddress, LoadAttr, LoadAttrIndex))
1.61 - self.dispatch(compiler.ast.Name("AttributeError"))
1.62 - self.new_op(CheckException())
1.63 - self.new_op(JumpIfTrue(type_error_label))
1.64 +
1.65 + if not self._optimise_known_target():
1.66 + self.dispatch(compiler.ast.Name("AttributeError"))
1.67 + self.new_op(CheckException())
1.68 + self.new_op(JumpIfTrue(type_error_label))
1.69
1.70 # Add arguments.
1.71
2.1 --- a/test.py Fri May 02 01:47:19 2008 +0200
2.2 +++ b/test.py Sun May 04 02:42:03 2008 +0200
2.3 @@ -3,9 +3,13 @@
2.4 import micropython
2.5 import sys
2.6
2.7 +code = None
2.8 +
2.9 def show(importer, with_builtins=0, optimisations=None):
2.10 optimisations = optimisations or requested_optimisations
2.11 - for i, x in enumerate(importer.get_image(with_builtins, optimisations)):
2.12 + global code
2.13 + code = importer.get_image(with_builtins, optimisations)
2.14 + for i, x in enumerate(code):
2.15 print i, x
2.16
2.17 def attrs(obj):