# HG changeset patch # User Paul Boddie # Date 1488203531 -3600 # Node ID 650c24cf71f125e9af2d1e529bce0bf570b5b3ec # Parent 669be6de0a37926579a6bc90334172b8593a46a7 Introduced a convenience macro for initialising attributes with values. Tidied up the main function exception handling slightly. diff -r 669be6de0a37 -r 650c24cf71f1 generator.py --- a/generator.py Mon Feb 27 14:44:30 2017 +0100 +++ b/generator.py Mon Feb 27 14:52:11 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, %s).value, %s).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, %s).strvalue); return 1; } diff -r 669be6de0a37 -r 650c24cf71f1 templates/types.h --- a/templates/types.h Mon Feb 27 14:44:30 2017 +0100 +++ b/templates/types.h Mon Feb 27 14:52:11 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 669be6de0a37 -r 650c24cf71f1 translator.py --- a/translator.py Mon Feb 27 14:44:30 2017 +0100 +++ b/translator.py Mon Feb 27 14:52:11 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) @@ -1118,7 +1117,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): @@ -1327,7 +1326,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: @@ -1509,14 +1508,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)))