# HG changeset patch # User Paul Boddie # Date 1486741877 -3600 # Node ID 8e8ebe75ee9eefb18c5bfb141713ce4054b796f1 # Parent 5347d06d47977751adc7a37b32bdeeccd00590e9 Restructured the __attr type to bundle related members together. diff -r 5347d06d4797 -r 8e8ebe75ee9e generator.py --- a/generator.py Fri Feb 10 16:01:18 2017 +0100 +++ b/generator.py Fri Feb 10 16:51:17 2017 +0100 @@ -551,7 +551,7 @@ # Define a macro for the constant. attr_name = encode_path(const_path) - print >>f_decls, "#define %s ((__attr) {.context=&%s, .value=&%s})" % (attr_name, structure_name, structure_name) + print >>f_decls, "#define %s ((__attr) {{.context=&%s, .value=&%s}})" % (attr_name, structure_name, structure_name) def make_parameter_table(self, f_decls, f_defs, parameters): @@ -887,7 +887,7 @@ attr = encode_function_pointer(attr) unbound_attr = "__unbound_method" - structure.append("{.inv=%s, .fn=%s}" % (unbound_attr, attr)) + structure.append("{{.inv=%s, .fn=%s}}" % (unbound_attr, attr)) continue # Special argument specification member. @@ -896,13 +896,13 @@ signature = self.get_signature_for_callable(ref.get_origin()) ptable = encode_tablename("", signature) - structure.append("{.min=%s, .ptable=&%s}" % (attr, ptable)) + structure.append("{{.min=%s, .ptable=&%s}}" % (attr, ptable)) continue # Special internal data member. elif attrname == "__data__": - structure.append("{.size=%d, .%s=%s}" % ( + structure.append("{{.size=%d, .%s=%s}}" % ( encode_literal_constant_size(attr), encode_literal_constant_member(attr), encode_literal_constant_value(attr))) @@ -911,8 +911,8 @@ # Special internal key member. elif attrname == "__key__": - structure.append("{.code=%s, .pos=%s}" % (attr and encode_symbol("code", attr) or "0", - attr and encode_symbol("pos", attr) or "0")) + structure.append("{{.code=%s, .pos=%s}}" % (attr and encode_symbol("code", attr) or "0", + attr and encode_symbol("pos", attr) or "0")) continue # Special cases. @@ -955,13 +955,13 @@ # object paths. value = path.rsplit(".", 1)[0] - structure.append("{.context=0, .value=&%s}" % encode_path(value)) + structure.append("{{.context=0, .value=&%s}}" % encode_path(value)) continue # Special class relationship attributes. elif is_type_attribute(attrname): - structure.append("{.context=0, .value=&%s}" % encode_path(decode_type_attribute(attrname))) + structure.append("{{.context=0, .value=&%s}}" % encode_path(decode_type_attribute(attrname))) continue # All other kinds of members. @@ -1000,19 +1000,19 @@ if kind == "" and origin == self.none_type: attr_path = encode_predefined_reference(self.none_value) - return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name) + return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name) # Predefined constant members. if (path, name) in self.predefined_constant_members: attr_path = encode_predefined_reference("%s.%s" % (path, name)) - return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name) + return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name) # General undetermined members. if kind in ("", ""): attr_path = encode_predefined_reference(self.none_value) - return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name) + return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name) # Set the context depending on the kind of attribute. # For methods: {&, &} @@ -1026,7 +1026,7 @@ context = "&%s" % encode_path(origin) else: context = "0" - return "{.context=%s, .value=&%s}" % (context, encode_path(origin)) + return "{{.context=%s, .value=&%s}}" % (context, encode_path(origin)) def append_defaults(self, path, structure): @@ -1138,7 +1138,7 @@ } __Catch(__tmp_exc) { - if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.context=0, .value=&__builtins___exception_system_SystemExit}))) + if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {{.context=0, .value=&__builtins___exception_system_SystemExit}}))) return __load_via_object( __load_via_object(__tmp_exc.arg.value, %s).value, %s).intvalue; diff -r 5347d06d4797 -r 8e8ebe75ee9e templates/native/list.c --- a/templates/native/list.c Fri Feb 10 16:01:18 2017 +0100 +++ b/templates/native/list.c Fri Feb 10 16:51:17 2017 +0100 @@ -32,7 +32,7 @@ __attr * const size = &__args[1]; /* size.__data__ interpreted as int */ unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; - __attr attr = {{0}, .seqvalue=__new_fragment(n)}; + __attr attr = {{.size=0, .seqvalue=__new_fragment(n)}}; /* Return the __data__ attribute. */ return attr; @@ -61,7 +61,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __pos___data__, ((__attr) {{0}, .seqvalue=newdata})); + __store_via_object(self->value, __pos___data__, ((__attr) {{.size=0, .seqvalue=newdata}})); return __builtins___none_None; } @@ -92,7 +92,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __pos___data__, ((__attr) {{0}, .seqvalue=newdata})); + __store_via_object(self->value, __pos___data__, ((__attr) {{.size=0, .seqvalue=newdata}})); return __builtins___none_None; } diff -r 5347d06d4797 -r 8e8ebe75ee9e templates/progops.c --- a/templates/progops.c Fri Feb 10 16:01:18 2017 +0100 +++ b/templates/progops.c Fri Feb 10 16:51:17 2017 +0100 @@ -57,7 +57,7 @@ /* Calculate the size of the fragment. */ __fragment *data = __new_fragment(number); - __attr attr = {{0}, .seqvalue=data}; + __attr attr = {{.size=0, .seqvalue=data}}; unsigned int i, j; /* Copy the given number of values, starting from the second element. */ diff -r 5347d06d4797 -r 8e8ebe75ee9e templates/types.h --- a/templates/types.h Fri Feb 10 16:01:18 2017 +0100 +++ b/templates/types.h Fri Feb 10 16:51:17 2017 +0100 @@ -56,27 +56,33 @@ /* One of... */ union { - __obj * context; /* attribute context */ - unsigned int min; /* minimum number of parameters */ - unsigned int code; /* parameter table code for key */ - struct __attr (*inv)(); /* unbound callable details */ - - size_t size; /* size of value */ - }; - - /* One of... */ - union - { - __obj * value; /* attribute value */ - const __ptable * ptable;/* parameter table */ - unsigned int pos; /* parameter table position for key */ - struct __attr (*fn)(); /* callable details */ - - int intvalue; /* integer value */ - double floatvalue; /* floating point value */ - char * strvalue; /* string value */ - __fragment * seqvalue; /* sequence data */ - void * datavalue; /* object-specific data */ + struct { + __obj * context; /* attribute context */ + __obj * value; /* attribute value */ + }; + struct { + unsigned int min; /* minimum number of parameters */ + const __ptable * ptable; /* parameter table */ + }; + struct { + unsigned int code; /* parameter table code for key */ + unsigned int pos; /* parameter table position for key */ + }; + struct { + struct __attr (*inv)(); /* unbound callable details */ + struct __attr (*fn)(); /* callable details */ + }; + struct { + size_t size; /* size of value */ + union + { + int intvalue; /* integer value */ + double floatvalue; /* floating point value */ + char * strvalue; /* string value */ + __fragment * seqvalue; /* sequence data */ + void * datavalue; /* object-specific data */ + }; + }; }; } __attr; @@ -108,7 +114,7 @@ /* Special null values. */ -#define __NULL ((__attr) {{0}, {0}}) +#define __NULL ((__attr) {{.context=0, .value=0}}) /* Function pointer type. */ diff -r 5347d06d4797 -r 8e8ebe75ee9e translator.py --- a/translator.py Fri Feb 10 16:01:18 2017 +0100 +++ b/translator.py Fri Feb 10 16:51:17 2017 +0100 @@ -142,7 +142,7 @@ elif static_name: parent = ref.parent() context = ref.has_kind("") and encode_path(parent) or None - return "((__attr) {.context=%s, .value=&%s})" % (context and "&%s" % context or "0", static_name) + return "((__attr) {{.context=%s, .value=&%s}})" % (context and "&%s" % context or "0", static_name) # Qualified names must be converted into parent-relative accesses. @@ -875,7 +875,7 @@ if not ref.static(): self.process_assignment_for_object( - n.name, make_expression("((__attr) {.context=0, .value=&%s})" % + n.name, make_expression("((__attr) {{.context=0, .value=&%s}})" % encode_path(class_name))) self.enter_namespace(n.name) @@ -1054,7 +1054,7 @@ context = self.is_method(objpath) self.process_assignment_for_object(original_name, - make_expression("((__attr) {.context=%s, .value=&%s})" % ( + make_expression("((__attr) {{.context=%s, .value=&%s}})" % ( context and "&%s" % encode_path(context) or "0", encode_path(objpath)))) @@ -1414,14 +1414,14 @@ # Without defaults, produce an attribute referring to the function. if not defaults: - return make_expression("((__attr) {.context=0, .value=&%s})" % encode_path(function_name)) + return make_expression("((__attr) {{.context=0, .value=&%s}})" % encode_path(function_name)) # With defaults, copy the function structure and set the defaults on the # copy. else: self.record_temp("__tmp_value") - return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {.context=0, .value=__tmp_value})" % ( + return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {{.context=0, .value=__tmp_value}})" % ( encode_path(function_name), encode_symbol("obj", function_name), ", ".join(defaults)))