1.1 --- a/micropython/ast.py Mon Jan 26 01:25:30 2009 +0100
1.2 +++ b/micropython/ast.py Mon Feb 02 01:34:35 2009 +0100
1.3 @@ -197,9 +197,11 @@
1.4 Request a new object with the given class 'cls' and with 'n' attributes.
1.5 """
1.6
1.7 + self.new_op(LoadConst(cls))
1.8 +
1.9 + # NOTE: Provide __call__ details, if any.
1.10 # NOTE: Object headers are one location.
1.11
1.12 - self.new_op(LoadConst(cls))
1.13 self.new_op(MakeObject(n + 1))
1.14
1.15 # Name-related methods.
1.16 @@ -517,36 +519,45 @@
1.17 try:
1.18 attr = self.unit.parent.instance_attributes()[attrname]
1.19 self.new_op(AttrInstruction(attr))
1.20 + return
1.21
1.22 # Or generate an instruction operating on a class attribute.
1.23
1.24 except KeyError:
1.25 - attr = self.unit.parent.all_attributes()[attrname]
1.26 -
1.27 - # Switch the context if the class attribute is compatible with
1.28 - # the instance.
1.29 -
1.30 - if attr.defined_within_hierarchy():
1.31 -
1.32 - # Only permit loading (not storing) of class attributes via self.
1.33 -
1.34 - if AddressContextInstruction is not None:
1.35 - self.new_op(AddressContextInstruction(attr))
1.36 +
1.37 + try:
1.38 + attr = self.unit.parent.all_attributes()[attrname]
1.39 +
1.40 + # Switch the context if the class attribute is compatible with
1.41 + # the instance.
1.42 +
1.43 + if attr.defined_within_hierarchy():
1.44 +
1.45 + # Only permit loading (not storing) of class attributes via self.
1.46 +
1.47 + if AddressContextInstruction is not None:
1.48 + self.new_op(AddressContextInstruction(attr))
1.49 + else:
1.50 + raise TranslateError(self.module.full_name(), node,
1.51 + "Storing of class attribute %r via self not permitted." % attrname)
1.52 +
1.53 + # Preserve the context if the class attribute comes from an
1.54 + # incompatible class.
1.55 +
1.56 else:
1.57 - raise TranslateError(self.module.full_name(), node,
1.58 - "Storing of class attribute %r via self not permitted." % attrname)
1.59 -
1.60 - # Preserve the context if the class attribute comes from an
1.61 - # incompatible class.
1.62 -
1.63 - else:
1.64 - if AddressInstruction is not None:
1.65 - self.new_op(AddressInstruction(attr))
1.66 - else:
1.67 - raise TranslateError(self.module.full_name(), node,
1.68 - "Storing of class attribute %r via self not permitted." % attrname)
1.69 -
1.70 - return
1.71 + if AddressInstruction is not None:
1.72 + self.new_op(AddressInstruction(attr))
1.73 + else:
1.74 + raise TranslateError(self.module.full_name(), node,
1.75 + "Storing of class attribute %r via self not permitted." % attrname)
1.76 +
1.77 + return
1.78 +
1.79 + # Or delegate the attribute access to a general instruction
1.80 + # since the kind of attribute cannot be deduced.
1.81 +
1.82 + except KeyError:
1.83 + pass
1.84
1.85 # Otherwise, perform a normal operation.
1.86