# HG changeset patch # User Paul Boddie # Date 1488203677 -3600 # Node ID 05ad7964265c739b224c2557724572a31d3b6951 # Parent c5371b8f4981642fa4163ed159fe1eed11fe1eaf# Parent 650c24cf71f125e9af2d1e529bce0bf570b5b3ec Merged convenience macro changes. diff -r c5371b8f4981 -r 05ad7964265c generator.py --- a/generator.py Mon Feb 27 14:41:27 2017 +0100 +++ b/generator.py Mon Feb 27 14:54:37 2017 +0100 @@ -564,7 +564,7 @@ # Define a macro for the constant. attr_name = encode_path(const_path) - print >>f_decls, "#define %s ((__attr) {.value=&%s})" % (attr_name, structure_name) + print >>f_decls, "#define %s __ATTRVALUE(&%s)" % (attr_name, structure_name) def make_parameter_table(self, f_decls, f_defs, argmin, parameters): @@ -1180,14 +1180,14 @@ } __Catch(__tmp_exc) { - if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.value=&__builtins___exception_system_SystemExit}))) + if (__ISINSTANCE(__tmp_exc.arg, __ATTRVALUE(&__builtins___exception_system_SystemExit))) return __load_via_object( __load_via_object(__tmp_exc.arg.value, __data__).value, value).intvalue; fprintf(stderr, "Program terminated due to exception: %%s.\\n", __load_via_object( - %s((__attr[]) {__NULL, __tmp_exc.arg}).value, + %s(__ARGS(__NULL, __tmp_exc.arg)).value, __data__).strvalue); return 1; } diff -r c5371b8f4981 -r 05ad7964265c templates/ops.c diff -r c5371b8f4981 -r 05ad7964265c templates/types.h --- a/templates/types.h Mon Feb 27 14:41:27 2017 +0100 +++ b/templates/types.h Mon Feb 27 14:54:37 2017 +0100 @@ -105,13 +105,10 @@ #define __INSTANCEPOS 0 -/* Special null values. */ - -#define __NULL ((__attr) {.value=0}) +/* Attribute value setting. */ -/* Function pointer type. */ - -typedef __attr (*__func)(); +#define __ATTRVALUE(VALUE) ((__attr) {.value=VALUE}) +#define __NULL __ATTRVALUE(0) /* Argument lists. */ diff -r c5371b8f4981 -r 05ad7964265c translator.py --- a/translator.py Mon Feb 27 14:41:27 2017 +0100 +++ b/translator.py Mon Feb 27 14:54:37 2017 +0100 @@ -154,7 +154,7 @@ elif static_name: parent = ref.parent() context = ref.has_kind("") and encode_path(parent) or None - return "((__attr) {.value=&%s})" % static_name + return "__ATTRVALUE(&%s)" % static_name # Qualified names must be converted into parent-relative accesses. @@ -938,9 +938,8 @@ ref = self.importer.identify(class_name) if not ref.static(): - self.process_assignment_for_object( - n.name, make_expression("((__attr) {.value=&%s})" % - encode_path(class_name))) + self.process_assignment_for_object(n.name, + make_expression("__ATTRVALUE(&%s)" % encode_path(class_name))) self.enter_namespace(n.name) @@ -1117,7 +1116,7 @@ context = self.is_method(objpath) self.process_assignment_for_object(original_name, - make_expression("((__attr) {.value=&%s})" % encode_path(objpath))) + make_expression("__ATTRVALUE(&%s)" % encode_path(objpath))) def process_function_defaults(self, n, name, objpath, instance_name=None): @@ -1326,7 +1325,7 @@ if context_required: if have_access_context: - args = ["(__attr) {.value=%s}" % context_identity] + args = ["__ATTRVALUE(%s)" % context_identity] else: args = ["__CONTEXT_AS_VALUE(%s)" % target_var] else: @@ -1507,14 +1506,14 @@ # Without defaults, produce an attribute referring to the function. if not defaults: - return make_expression("((__attr) {.value=&%s})" % encode_path(function_name)) + return make_expression("__ATTRVALUE(&%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) {.value=__tmp_value})" % ( + return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, __ATTRVALUE(__tmp_value))" % ( encode_path(function_name), encode_symbol("obj", function_name), ", ".join(defaults)))