1.1 --- a/generator.py Tue Dec 13 19:19:23 2016 +0100
1.2 +++ b/generator.py Tue Dec 13 22:46:52 2016 +0100
1.3 @@ -341,8 +341,8 @@
1.4
1.5 # Generate literal constants.
1.6
1.7 - for value, n in self.optimiser.constants.items():
1.8 - self.make_literal_constant(f_decls, f_defs, n, value)
1.9 + for constant, n in self.optimiser.constants.items():
1.10 + self.make_literal_constant(f_decls, f_defs, n, constant)
1.11
1.12 # Finish the main source file.
1.13
1.14 @@ -433,23 +433,20 @@
1.15 f_signatures.close()
1.16 f_code.close()
1.17
1.18 - def make_literal_constant(self, f_decls, f_defs, n, value):
1.19 + def make_literal_constant(self, f_decls, f_defs, n, constant):
1.20
1.21 """
1.22 Write literal constant details to 'f_decls' (to declare a structure) and
1.23 to 'f_defs' (to define the contents) for the constant with the number
1.24 - 'n' with the given literal 'value'.
1.25 + 'n' with the given 'constant'.
1.26 """
1.27
1.28 + value, value_type = constant
1.29 +
1.30 const_path = encode_literal_constant(n)
1.31 structure_name = encode_literal_reference(n)
1.32
1.33 - # NOTE: This makes assumptions about the __builtins__ structure.
1.34 -
1.35 - typename = get_builtin_type(value.__class__.__name__)
1.36 - modname = get_builtin_module(typename)
1.37 - ref = Reference("<instance>", "__builtins__.%s.%s" % (modname, typename))
1.38 -
1.39 + ref = Reference("<instance>", value_type)
1.40 self.make_constant(f_decls, f_defs, ref, const_path, structure_name, value)
1.41
1.42 def make_predefined_constant(self, f_decls, f_defs, path, name):
1.43 @@ -491,7 +488,7 @@
1.44
1.45 # Also set a key for dynamic attribute lookup, if a string.
1.46
1.47 - if cls == self.string_type:
1.48 + if attrs.has_key("__key__"):
1.49 if data in self.optimiser.all_attrnames:
1.50 attrs["__key__"] = data
1.51 else:
1.52 @@ -890,6 +887,7 @@
1.53
1.54 elif attrname in ("__file__", "__fname__", "__mname__", "__name__"):
1.55 path = ref.get_origin()
1.56 + value_type = self.string_type
1.57
1.58 if attrname == "__file__":
1.59 module = self.importer.get_module(path)
1.60 @@ -897,7 +895,7 @@
1.61 else:
1.62 value = path
1.63
1.64 - local_number = self.importer.all_constants[path][value]
1.65 + local_number = self.importer.all_constants[path][(value, value_type)]
1.66 constant_name = "$c%d" % local_number
1.67 attr_path = "%s.%s" % (path, constant_name)
1.68 constant_number = self.optimiser.constant_numbers[attr_path]