1.1 --- a/generator.py Tue Mar 07 17:32:14 2017 +0100
1.2 +++ b/generator.py Tue Mar 07 18:10:00 2017 +0100
1.3 @@ -1183,60 +1183,52 @@
1.4 NOTE: where __call__ is provided by the class.
1.5 """
1.6
1.7 - parameters = self.importer.function_parameters[init_ref.get_origin()]
1.8 initialiser = init_ref.get_origin()
1.9 + parameters = self.importer.function_parameters[initialiser]
1.10 argmin, argmax = self.get_argument_limits(initialiser)
1.11
1.12 + l = []
1.13 + for name in parameters:
1.14 + l.append("__attr %s" % name)
1.15 +
1.16 print >>f_code, """\
1.17 -__attr %s(__attr __args[])
1.18 +__attr %s(__attr __self%s)
1.19 {
1.20 - /* Allocate the structure. */
1.21 - __args[0] = __NEWINSTANCE(%s);
1.22 -
1.23 - /* Call the initialiser. */
1.24 - %s(%s, __args);
1.25 -
1.26 - /* Return the allocated object details. */
1.27 - return __args[0];
1.28 + return %s(__NEWINSTANCE(%s)%s);
1.29 }
1.30 """ % (
1.31 - encode_instantiator_pointer(path),
1.32 - encode_path(path),
1.33 - "__CALL%d" % argmax,
1.34 - encode_function_pointer(initialiser)
1.35 - )
1.36 + encode_instantiator_pointer(path),
1.37 + l and ", %s" % ",".join(l) or "",
1.38 + encode_function_pointer(initialiser),
1.39 + encode_path(path),
1.40 + parameters and ", %s" % ", ".join(parameters) or ""
1.41 + )
1.42 +
1.43 + # Signature: __new_typename(__attr __self, ...)
1.44 +
1.45 + print >>f_signatures, "__attr %s(__attr __self%s);" % (
1.46 + encode_instantiator_pointer(path),
1.47 + l and ", %s" % ", ".join(l) or ""
1.48 + )
1.49
1.50 print >>f_signatures, "#define __HAVE_%s" % encode_path(path)
1.51 - print >>f_signatures, "__attr %s(__attr[]);" % encode_instantiator_pointer(path)
1.52
1.53 # Write additional literal instantiators. These do not call the
1.54 # initialisers but instead populate the structures directly.
1.55
1.56 + # Signature: __newliteral_sequence(ARGS, NUM)
1.57 +
1.58 if path in self.literal_instantiator_types:
1.59 if path in self.literal_mapping_types:
1.60 style = "mapping"
1.61 else:
1.62 style = "sequence"
1.63
1.64 - print >>f_code, """\
1.65 -__attr %s(__attr __args[], __pos number)
1.66 -{
1.67 - /* Allocate the structure. */
1.68 - __args[0] = __NEWINSTANCE(%s);
1.69 -
1.70 - /* Allocate a structure for the data and set it on the __data__ attribute. */
1.71 - %s(__args, number);
1.72 -
1.73 - /* Return the allocated object details. */
1.74 - return __args[0];
1.75 -}
1.76 -""" % (
1.77 - encode_literal_instantiator(path),
1.78 - encode_path(path),
1.79 - encode_literal_data_initialiser(style)
1.80 - )
1.81 -
1.82 - print >>f_signatures, "__attr %s(__attr[], __pos);" % encode_literal_instantiator(path)
1.83 + print >>f_signatures, "#define %s(ARGS, NUM) (%s(__NEWINSTANCE(%s), ARGS, NUM))" % (
1.84 + encode_literal_instantiator(path),
1.85 + encode_literal_data_initialiser(style),
1.86 + encode_path(path)
1.87 + )
1.88
1.89 def write_main_program(self, f_code, f_signatures):
1.90