# HG changeset patch # User Paul Boddie # Date 1490544220 -7200 # Node ID 7cfb3ba084601dc7275972e2d6d993ec919b2cd0 # Parent 1f07b0aa675e7c4444a004d4fa67a8a54ebfc98a Moved literal instantiator definitions to the templates, reordering the parameters and employing bare arguments. diff -r 1f07b0aa675e -r 7cfb3ba08460 generator.py --- a/generator.py Sun Mar 26 17:41:56 2017 +0200 +++ b/generator.py Sun Mar 26 18:03:40 2017 +0200 @@ -25,8 +25,7 @@ encode_instantiator_pointer, \ encode_literal_constant, encode_literal_constant_member, \ encode_literal_constant_size, encode_literal_constant_value, \ - encode_literal_data_initialiser, \ - encode_literal_instantiator, encode_literal_reference, \ + encode_literal_reference, \ encode_path, encode_pcode, encode_pos, encode_ppos, \ encode_predefined_reference, encode_size, \ encode_symbol, encode_tablename, \ @@ -1237,19 +1236,6 @@ print >>f_signatures, "#define __HAVE_%s" % encode_path(path) - # Write additional literal instantiators. These do not call the - # initialisers but instead populate the structures directly. - - # Signature: __newliteral_sequence(ARGS, NUM) - - if path in self.literal_instantiator_types: - style = path.rsplit(".", 1)[-1] - - print >>f_signatures, "#define %s(ARGS, NUM) (%s(ARGS, NUM))" % ( - encode_literal_instantiator(path), - encode_literal_data_initialiser(style), - ) - def write_main_program(self, f_code, f_signatures): """ diff -r 1f07b0aa675e -r 7cfb3ba08460 templates/progops.c --- a/templates/progops.c Sun Mar 26 17:41:56 2017 +0200 +++ b/templates/progops.c Sun Mar 26 18:03:40 2017 +0200 @@ -62,9 +62,8 @@ return data; } -void __newdata_sequence(__attr self, __attr args[], unsigned int number, __fragment *data) +void __newdata_sequence(unsigned int number, __fragment *data, __attr args[]) { - __attr attr = {.seqvalue=data}; unsigned int i; /* Copy the given number of values. */ @@ -73,36 +72,38 @@ data->attrs[i] = args[i]; data->size = number; +} + +__attr __newdata_list(unsigned int number, __attr args[]) +{ + __attr self = __NEWINSTANCE(__builtins___list_list); + __fragment *data = __new_fragment(number); /* Store a reference to the data in the object's __data__ attribute. */ - __store_via_object(__VALUE(self), __data__, attr); -} - -__attr __newdata_list(__attr args[], unsigned int number) -{ - __attr self = __NEWINSTANCE(__builtins___list_list); - __fragment *data = __new_fragment(number); - __newdata_sequence(self, args, number, data); + __store_via_object(__VALUE(self), __data__, (__attr) {.seqvalue=data}); + __newdata_sequence(number, data, args); return self; } -__attr __newdata_tuple(__attr args[], unsigned int number) +__attr __newdata_tuple(unsigned int number, __attr args[]) { /* Allocate the tuple and fragment together. */ __attr self = __new(&__INSTANCETABLE(__builtins___tuple_tuple), - &__builtins___tuple_tuple, - __INSTANCESIZE(__builtins___tuple_tuple) + __FRAGMENT_SIZE(number), 0); + &__builtins___tuple_tuple, + __INSTANCESIZE(__builtins___tuple_tuple) + __FRAGMENT_SIZE(number), 0); + __fragment *data = (__fragment *) ((void *) __VALUE(self) + __INSTANCESIZE(__builtins___tuple_tuple)); - /* Initialise the fragment. */ + /* Store a reference to the data in the object's __data__ attribute. */ - __newdata_sequence(self, args, number, (__fragment *) ((void *) __VALUE(self) + __INSTANCESIZE(__builtins___tuple_tuple))); + __store_via_object(__VALUE(self), __data__, (__attr) {.seqvalue=data}); + __newdata_sequence(number, data, args); return self; } #ifdef __HAVE___builtins___dict_dict -__attr __newdata_dict(__attr args[], unsigned int number) +__attr __newdata_dict(unsigned int number, __attr args[]) { __attr self = __NEWINSTANCE(__builtins___dict_dict); diff -r 1f07b0aa675e -r 7cfb3ba08460 templates/progops.h --- a/templates/progops.h Sun Mar 26 17:41:56 2017 +0200 +++ b/templates/progops.h Sun Mar 26 18:03:40 2017 +0200 @@ -32,11 +32,15 @@ __fragment *__new_fragment(unsigned int n); -__attr __newdata_list(__attr args[], unsigned int number); -__attr __newdata_tuple(__attr args[], unsigned int number); +__attr __newdata_list(unsigned int number, __attr args[]); +__attr __newdata_tuple(unsigned int number, __attr args[]); + +#define __newliteral___builtins___list_list(NUM, ...) __newdata_list(NUM, __ARGS(__VA_ARGS__)) +#define __newliteral___builtins___tuple_tuple(NUM, ...) __newdata_tuple(NUM, __ARGS(__VA_ARGS__)) #ifdef __HAVE___builtins___dict_dict -__attr __newdata_dict(__attr args[], unsigned int number); +__attr __newdata_dict(unsigned int number, __attr args[]); +#define __newliteral___builtins___dict_dict(NUM, ...) __newdata_dict(NUM, __ARGS(__VA_ARGS__)) #endif /* __HAVE___builtins___dict_dict */ /* Helpers for raising errors within common operations. */ diff -r 1f07b0aa675e -r 7cfb3ba08460 translator.py --- a/translator.py Sun Mar 26 17:41:56 2017 +0200 +++ b/translator.py Sun Mar 26 18:03:40 2017 +0200 @@ -1318,7 +1318,7 @@ # the number of values. The context is excluded. if literal_instantiation: - argstr = "__ARGS(%s), %d" % (", ".join(args[1:]), len(args) - 1) + argstr = "%d, %s" % (len(args) - 1, ", ".join(args[1:])) else: argstr = ", ".join(args)