1.1 --- a/generator.py Fri Dec 09 23:30:41 2016 +0100
1.2 +++ b/generator.py Fri Dec 09 23:51:47 2016 +0100
1.3 @@ -56,6 +56,7 @@
1.4 # NOTE: These must be synchronised with the library.
1.5
1.6 function_type = "__builtins__.core.function"
1.7 + string_type = "__builtins__.str.string"
1.8 type_type = "__builtins__.core.type"
1.9
1.10 predefined_constant_members = (
1.11 @@ -491,6 +492,14 @@
1.12 if data is not None:
1.13 attrs["__data__"] = data
1.14
1.15 + # Also set a key for dynamic attribute lookup, if a string.
1.16 +
1.17 + if cls == self.string_type:
1.18 + if data in self.optimiser.all_attrnames:
1.19 + attrs["__key__"] = data
1.20 + else:
1.21 + attrs["__key__"] = None
1.22 +
1.23 # Define the structure details. An object is created for the constant,
1.24 # but an attribute is provided, referring to the object, for access to
1.25 # the constant in the program.
1.26 @@ -871,6 +880,13 @@
1.27 encode_literal_constant_value(attr)))
1.28 continue
1.29
1.30 + # Special internal key member.
1.31 +
1.32 + elif attrname == "__key__":
1.33 + structure.append("{.code=%s, .pos=%s}" % (attr and encode_symbol("code", attr) or "0",
1.34 + attr and encode_symbol("pos", attr) or "0"))
1.35 + continue
1.36 +
1.37 # Special cases.
1.38
1.39 elif attrname in ("__file__", "__fname__", "__mname__", "__name__"):