1.1 --- a/generator.py Tue Nov 29 23:13:18 2016 +0100
1.2 +++ b/generator.py Wed Nov 30 16:18:17 2016 +0100
1.3 @@ -24,6 +24,7 @@
1.4 encode_instantiator_pointer, \
1.5 encode_literal_constant, encode_literal_constant_member, \
1.6 encode_literal_constant_value, \
1.7 + encode_literal_data_initialiser, \
1.8 encode_literal_instantiator, encode_literal_reference, \
1.9 encode_path, \
1.10 encode_predefined_reference, encode_size, \
1.11 @@ -65,12 +66,17 @@
1.12 ("__builtins__.notimplemented", "NotImplemented"),
1.13 )
1.14
1.15 - literal_instantiator_types = (
1.16 + literal_mapping_types = (
1.17 "__builtins__.dict.dict",
1.18 + )
1.19 +
1.20 + literal_sequence_types = (
1.21 "__builtins__.list.list",
1.22 "__builtins__.tuple.tuple",
1.23 )
1.24
1.25 + literal_instantiator_types = literal_mapping_types + literal_sequence_types
1.26 +
1.27 def __init__(self, importer, optimiser, output):
1.28 self.importer = importer
1.29 self.optimiser = optimiser
1.30 @@ -910,19 +916,19 @@
1.31 # initialisers but instead populate the structures directly.
1.32
1.33 if path in self.literal_instantiator_types:
1.34 + if path in self.literal_mapping_types:
1.35 + style = "mapping"
1.36 + else:
1.37 + style = "sequence"
1.38 +
1.39 print >>f_code, """\
1.40 __attr %s(__attr __args[], unsigned int number)
1.41 {
1.42 - __attr data;
1.43 -
1.44 /* Allocate the structure. */
1.45 __args[0] = __new(&%s, &%s, sizeof(%s));
1.46
1.47 - /* Allocate a structure for the data. */
1.48 - data = __newfragment(__args, number);
1.49 -
1.50 - /* Store a reference to the data in the object's __data__ attribute. */
1.51 - __store_via_object(__args[0].value, %s, data);
1.52 + /* Allocate a structure for the data and set it on the __data__ attribute. */
1.53 + %s(__args, number);
1.54
1.55 /* Return the allocated object details. */
1.56 return __args[0];
1.57 @@ -932,7 +938,7 @@
1.58 encode_tablename("<instance>", path),
1.59 encode_path(path),
1.60 encode_symbol("obj", path),
1.61 - encode_symbol("pos", "__data__")
1.62 + encode_literal_data_initialiser(style)
1.63 )
1.64
1.65 print >>f_signatures, "__attr %s(__attr[], unsigned int);" % encode_literal_instantiator(path)