1.1 --- a/generator.py Thu Jan 19 19:23:39 2017 +0100
1.2 +++ b/generator.py Thu Jan 19 23:33:10 2017 +0100
1.3 @@ -535,7 +535,7 @@
1.4 # Define a macro for the constant.
1.5
1.6 attr_name = encode_path(const_path)
1.7 - print >>f_decls, "#define %s ((__attr) {&%s, &%s})" % (attr_name, structure_name, structure_name)
1.8 + print >>f_decls, "#define %s ((__attr) {.context=&%s, .value=&%s})" % (attr_name, structure_name, structure_name)
1.9
1.10 def make_parameter_table(self, f_decls, f_defs, parameters):
1.11
1.12 @@ -851,7 +851,7 @@
1.13 # Handle gaps in the structure.
1.14
1.15 if attrname is None:
1.16 - structure.append("{0, 0}")
1.17 + structure.append("__NULL")
1.18
1.19 # Handle non-constant and constant members.
1.20
1.21 @@ -884,7 +884,7 @@
1.22 else:
1.23 attr = encode_function_pointer(attr)
1.24
1.25 - structure.append("{%s, .fn=%s}" % (bound_attr and ".b=&%s" % bound_attr or "0", attr))
1.26 + structure.append("{.b=%s, .fn=%s}" % (bound_attr and "&%s" % bound_attr or "0", attr))
1.27 continue
1.28
1.29 # Special argument specification member.
1.30 @@ -937,7 +937,7 @@
1.31 # Special class relationship attributes.
1.32
1.33 elif is_type_attribute(attrname):
1.34 - structure.append("{0, &%s}" % encode_path(decode_type_attribute(attrname)))
1.35 + structure.append("{.context=0, .value=&%s}" % encode_path(decode_type_attribute(attrname)))
1.36 continue
1.37
1.38 # All other kinds of members.
1.39 @@ -976,19 +976,19 @@
1.40
1.41 if kind == "<instance>" and origin == self.none_type:
1.42 attr_path = encode_predefined_reference(self.none_value)
1.43 - return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name)
1.44 + return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name)
1.45
1.46 # Predefined constant members.
1.47
1.48 if (path, name) in self.predefined_constant_members:
1.49 attr_path = encode_predefined_reference("%s.%s" % (path, name))
1.50 - return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name)
1.51 + return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name)
1.52
1.53 # General undetermined members.
1.54
1.55 if kind in ("<var>", "<instance>"):
1.56 attr_path = encode_predefined_reference(self.none_value)
1.57 - return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name)
1.58 + return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name)
1.59
1.60 # Set the context depending on the kind of attribute.
1.61 # For methods: {&<parent>, &<attr>}
1.62 @@ -1002,7 +1002,7 @@
1.63 context = "&%s" % encode_path(origin)
1.64 else:
1.65 context = "0"
1.66 - return "{%s, &%s}" % (context, encode_path(origin))
1.67 + return "{.context=%s, .value=&%s}" % (context, encode_path(origin))
1.68
1.69 def append_defaults(self, path, structure):
1.70
1.71 @@ -1111,21 +1111,22 @@
1.72 %s();""" % function_name
1.73
1.74 print >>f_code, """\
1.75 - return 0;
1.76 }
1.77 __Catch(__tmp_exc)
1.78 {
1.79 - if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {0, &__builtins___exception_system_SystemExit})))
1.80 + if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.context=0, .value=&__builtins___exception_system_SystemExit})))
1.81 return __load_via_object(
1.82 __load_via_object(__tmp_exc.arg.value, %s).value,
1.83 %s).intvalue;
1.84
1.85 fprintf(stderr, "Program terminated due to exception: %%s.\\n",
1.86 __load_via_object(
1.87 - %s((__attr[]) {{0, 0}, __tmp_exc.arg}).value,
1.88 + %s((__attr[]) {__NULL, __tmp_exc.arg}).value,
1.89 %s).strvalue);
1.90 return 1;
1.91 }
1.92 +
1.93 + return 0;
1.94 }
1.95 """ % (
1.96 encode_symbol("pos", "value"),
2.1 --- a/templates/Makefile Thu Jan 19 19:23:39 2017 +0100
2.2 +++ b/templates/Makefile Thu Jan 19 23:33:10 2017 +0100
2.3 @@ -1,6 +1,6 @@
2.4 SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c)
2.5 OBJ = $(SRC:.c=.o)
2.6 -CFLAGS = -I. -finput-charset=UTF-8
2.7 +CFLAGS = -Wall -I. -finput-charset=UTF-8
2.8 LDFLAGS = -lm -lgc
2.9
2.10 ifdef ARCH
3.1 --- a/templates/Makefile-debug Thu Jan 19 19:23:39 2017 +0100
3.2 +++ b/templates/Makefile-debug Thu Jan 19 23:33:10 2017 +0100
3.3 @@ -1,6 +1,6 @@
3.4 SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c)
3.5 OBJ = $(SRC:.c=.o)
3.6 -CFLAGS = -I. -finput-charset=UTF-8 -g
3.7 +CFLAGS = -Wall -I. -finput-charset=UTF-8 -g
3.8 LDFLAGS = -lm -lgc
3.9
3.10 ifdef ARCH
4.1 --- a/templates/native/common.c Thu Jan 19 19:23:39 2017 +0100
4.2 +++ b/templates/native/common.c Thu Jan 19 23:33:10 2017 +0100
4.3 @@ -40,7 +40,7 @@
4.4 __attr attr = __new(&__InstanceTable___builtins___str_string, &__builtins___str_string, sizeof(__obj___builtins___str_string));
4.5 attr.value->attrs[__pos___data__].size = size;
4.6 attr.value->attrs[__pos___data__].strvalue = s;
4.7 - attr.value->attrs[__pos___key__] = (__attr) {0, 0};
4.8 + attr.value->attrs[__pos___key__] = __NULL;
4.9 return attr;
4.10 }
4.11
5.1 --- a/templates/native/iconv.c Thu Jan 19 19:23:39 2017 +0100
5.2 +++ b/templates/native/iconv.c Thu Jan 19 23:33:10 2017 +0100
5.3 @@ -33,7 +33,7 @@
5.4 static void __raise_incomplete_sequence_error(__attr value, __attr arg)
5.5 {
5.6 #ifdef __HAVE_posix_iconv_IncompleteSequenceError
5.7 - __attr args[3] = {{0, 0}, value, arg};
5.8 + __attr args[3] = {__NULL, value, arg};
5.9 __attr exc = __new_posix_iconv_IncompleteSequenceError(args);
5.10 __Raise(exc);
5.11 #endif /* __HAVE_posix_iconv_IncompleteSequenceError */
5.12 @@ -42,7 +42,7 @@
5.13 static void __raise_invalid_sequence_error(__attr value, __attr arg)
5.14 {
5.15 #ifdef __HAVE_posix_iconv_InvalidSequenceError
5.16 - __attr args[3] = {{0, 0}, value, arg};
5.17 + __attr args[3] = {__NULL, value, arg};
5.18 __attr exc = __new_posix_iconv_InvalidSequenceError(args);
5.19 __Raise(exc);
5.20 #endif /* __HAVE_posix_iconv_InvalidSequenceError */
5.21 @@ -117,6 +117,10 @@
5.22
5.23 else
5.24 __raise_os_error(__new_int(errno), __builtins___none_None);
5.25 +
5.26 + /* Should never be reached: included to satisfy the compiler. */
5.27 +
5.28 + return __builtins___none_None;
5.29 }
5.30
5.31 __attr __fn_native_iconv_iconv_close(__attr __args[])
6.1 --- a/templates/native/io.c Thu Jan 19 19:23:39 2017 +0100
6.2 +++ b/templates/native/io.c Thu Jan 19 23:33:10 2017 +0100
6.3 @@ -84,6 +84,10 @@
6.4 attr.datavalue = (void *) f;
6.5 return attr;
6.6 }
6.7 +
6.8 + /* Should never be reached: included to satisfy the compiler. */
6.9 +
6.10 + return __builtins___none_None;
6.11 }
6.12
6.13 __attr __fn_native_io_fdopen(__attr __args[])
6.14 @@ -113,6 +117,10 @@
6.15 attr.datavalue = (void *) f;
6.16 return attr;
6.17 }
6.18 +
6.19 + /* Should never be reached: included to satisfy the compiler. */
6.20 +
6.21 + return __builtins___none_None;
6.22 }
6.23
6.24 __attr __fn_native_io_fread(__attr __args[])
6.25 @@ -134,7 +142,7 @@
6.26 {
6.27 if (feof(f) && (have_read == 0))
6.28 __raise_eof_error();
6.29 - else if (error = ferror(f))
6.30 + else if ((error = ferror(f)))
6.31 __raise_io_error(__new_int(error));
6.32 }
6.33
6.34 @@ -162,7 +170,7 @@
6.35 {
6.36 if (feof(f))
6.37 __raise_eof_error();
6.38 - else if (error = ferror(f))
6.39 + else if ((error = ferror(f)))
6.40 __raise_io_error(__new_int(error));
6.41 }
6.42
7.1 --- a/templates/native/limits.c Thu Jan 19 19:23:39 2017 +0100
7.2 +++ b/templates/native/limits.c Thu Jan 19 23:33:10 2017 +0100
7.3 @@ -30,15 +30,11 @@
7.4
7.5 __attr __fn_native_limits_get_maxint(__attr __args[])
7.6 {
7.7 - __attr * const status = &__args[1];
7.8 -
7.9 return __new_int(INT_MAX);
7.10 }
7.11
7.12 __attr __fn_native_limits_get_minint(__attr __args[])
7.13 {
7.14 - __attr * const status = &__args[1];
7.15 -
7.16 return __new_int(INT_MIN);
7.17 }
7.18
8.1 --- a/templates/native/list.c Thu Jan 19 19:23:39 2017 +0100
8.2 +++ b/templates/native/list.c Thu Jan 19 23:33:10 2017 +0100
8.3 @@ -32,7 +32,7 @@
8.4 __attr * const size = &__args[1];
8.5 /* size.__data__ interpreted as int */
8.6 unsigned int n = __load_via_object(size->value, __pos___data__).intvalue;
8.7 - __attr attr = {0, .seqvalue=__new_fragment(n)};
8.8 + __attr attr = {{0}, .seqvalue=__new_fragment(n)};
8.9
8.10 /* Return the __data__ attribute. */
8.11 return attr;
8.12 @@ -61,7 +61,7 @@
8.13
8.14 /* Replace the __data__ attribute if appropriate. */
8.15 if (newdata != data)
8.16 - __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata}));
8.17 + __store_via_object(self->value, __pos___data__, ((__attr) {{0}, .seqvalue=newdata}));
8.18 return __builtins___none_None;
8.19 }
8.20
8.21 @@ -92,7 +92,7 @@
8.22
8.23 /* Replace the __data__ attribute if appropriate. */
8.24 if (newdata != data)
8.25 - __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata}));
8.26 + __store_via_object(self->value, __pos___data__, ((__attr) {{0}, .seqvalue=newdata}));
8.27 return __builtins___none_None;
8.28 }
8.29
9.1 --- a/templates/native/str.c Thu Jan 19 19:23:39 2017 +0100
9.2 +++ b/templates/native/str.c Thu Jan 19 23:33:10 2017 +0100
9.3 @@ -84,8 +84,6 @@
9.4 __attr __fn_native_str_str_len(__attr __args[])
9.5 {
9.6 __attr * const _data = &__args[1];
9.7 - /* _data interpreted as string */
9.8 - char *s = _data->strvalue;
9.9
9.10 /* Return the new integer. */
9.11 return __new_int(_data->size);
9.12 @@ -94,8 +92,6 @@
9.13 __attr __fn_native_str_str_nonempty(__attr __args[])
9.14 {
9.15 __attr * const _data = &__args[1];
9.16 - /* _data interpreted as string */
9.17 - char *s = _data->strvalue;
9.18
9.19 return _data->size ? __builtins___boolean_True : __builtins___boolean_False;
9.20 }
10.1 --- a/templates/native/system.c Thu Jan 19 19:23:39 2017 +0100
10.2 +++ b/templates/native/system.c Thu Jan 19 23:33:10 2017 +0100
10.3 @@ -37,16 +37,12 @@
10.4
10.5 __attr __fn_native_system_get_argv(__attr __args[])
10.6 {
10.7 - __attr * const status = &__args[1];
10.8 -
10.9 /* NOTE: To be written. */
10.10 return __builtins___none_None;
10.11 }
10.12
10.13 __attr __fn_native_system_get_path(__attr __args[])
10.14 {
10.15 - __attr * const status = &__args[1];
10.16 -
10.17 /* NOTE: To be written. */
10.18 return __builtins___none_None;
10.19 }
11.1 --- a/templates/ops.c Thu Jan 19 19:23:39 2017 +0100
11.2 +++ b/templates/ops.c Thu Jan 19 23:33:10 2017 +0100
11.3 @@ -200,10 +200,12 @@
11.4 attribute. */
11.5
11.6 if (__is_instance(context))
11.7 + {
11.8 if (__test_common_instance(context, __TYPEPOS(attr.context), __TYPECODE(attr.context)))
11.9 return __replace_context(context, attr);
11.10 else
11.11 __raise_type_error();
11.12 + }
11.13
11.14 /* Test for access to a type class attribute using a type instance. */
11.15
11.16 @@ -232,7 +234,7 @@
11.17
11.18 __attr __update_context(__ref context, __attr attr)
11.19 {
11.20 - __attr out = {context, .fn=attr.fn};
11.21 + __attr out = {.context=context, .fn=attr.fn};
11.22 return out;
11.23 }
11.24
12.1 --- a/templates/progops.c Thu Jan 19 19:23:39 2017 +0100
12.2 +++ b/templates/progops.c Thu Jan 19 23:33:10 2017 +0100
12.3 @@ -30,8 +30,8 @@
12.4 __attr __new(const __table * table, __ref cls, size_t size)
12.5 {
12.6 __ref obj = (__ref) __ALLOCATE(1, size);
12.7 - __attr self = {obj, obj};
12.8 - __attr tmp = {0, cls};
12.9 + __attr self = {.context=obj, .value=obj};
12.10 + __attr tmp = {.context=0, .value=cls};
12.11 obj->table = table;
12.12 __store_via_object(obj, __pos___class__, tmp);
12.13 return self;
12.14 @@ -57,7 +57,7 @@
12.15 /* Calculate the size of the fragment. */
12.16
12.17 __fragment *data = __new_fragment(number);
12.18 - __attr attr = {0, .seqvalue=data};
12.19 + __attr attr = {{0}, .seqvalue=data};
12.20 unsigned int i, j;
12.21
12.22 /* Copy the given number of values, starting from the second element. */
12.23 @@ -106,7 +106,7 @@
12.24 void __raise_io_error(__attr value)
12.25 {
12.26 #ifdef __HAVE___builtins___exception_io_IOError
12.27 - __attr args[2] = {{0, 0}, value};
12.28 + __attr args[2] = {__NULL, value};
12.29 __attr exc = __new___builtins___exception_io_IOError(args);
12.30 __Raise(exc);
12.31 #endif /* __HAVE___builtins___exception_io_IOError */
12.32 @@ -122,7 +122,7 @@
12.33 void __raise_os_error(__attr value, __attr arg)
12.34 {
12.35 #ifdef __HAVE___builtins___exception_system_OSError
12.36 - __attr args[3] = {{0, 0}, value, arg};
12.37 + __attr args[3] = {__NULL, value, arg};
12.38 __attr exc = __new___builtins___exception_system_OSError(args);
12.39 __Raise(exc);
12.40 #endif /* __HAVE___builtins___exception_system_OSError */
12.41 @@ -272,7 +272,7 @@
12.42
12.43 int __BOOL(__attr attr)
12.44 {
12.45 - __attr args[2] = {{0, 0}, attr};
12.46 + __attr args[2] = {__NULL, attr};
12.47
12.48 /* Invoke the bool function with the object and test against True. */
12.49
13.1 --- a/templates/progops.h Thu Jan 19 19:23:39 2017 +0100
13.2 +++ b/templates/progops.h Thu Jan 19 23:33:10 2017 +0100
13.3 @@ -19,7 +19,6 @@
13.4 #ifndef __PROGOPS_H__
13.5 #define __PROGOPS_H__
13.6
13.7 -#include <stdlib.h>
13.8 #include "types.h"
13.9
13.10 /* Generic instantiation operations, defining common members. */
13.11 @@ -76,6 +75,6 @@
13.12
13.13 /* Convenience definitions. */
13.14
13.15 -#define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {{0, 0}, __ATTR, __TYPE}))
13.16 +#define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE}))
13.17
13.18 #endif /* __PROGOPS_H__ */
14.1 --- a/templates/types.h Thu Jan 19 19:23:39 2017 +0100
14.2 +++ b/templates/types.h Thu Jan 19 23:33:10 2017 +0100
14.3 @@ -106,9 +106,9 @@
14.4
14.5 #define __INSTANCEPOS 0
14.6
14.7 -/* Special null value. */
14.8 +/* Special null values. */
14.9
14.10 -#define __NULL ((__attr) {0, 0})
14.11 +#define __NULL ((__attr) {{0}, {0}})
14.12
14.13 /* Function pointer type. */
14.14
15.1 --- a/translator.py Thu Jan 19 19:23:39 2017 +0100
15.2 +++ b/translator.py Thu Jan 19 23:33:10 2017 +0100
15.3 @@ -133,7 +133,7 @@
15.4 elif static_name:
15.5 parent = ref.parent()
15.6 context = ref.has_kind("<function>") and encode_path(parent) or None
15.7 - return "((__attr) {%s, &%s})" % (context and "&%s" % context or "0", static_name)
15.8 + return "((__attr) {.context=%s, .value=&%s})" % (context and "&%s" % context or "0", static_name)
15.9
15.10 # Qualified names must be converted into parent-relative accesses.
15.11
15.12 @@ -805,7 +805,7 @@
15.13
15.14 if not ref.static():
15.15 self.process_assignment_for_object(
15.16 - n.name, make_expression("((__attr) {0, &%s})" %
15.17 + n.name, make_expression("((__attr) {.context=0, .value=&%s})" %
15.18 encode_path(class_name)))
15.19
15.20 self.enter_namespace(n.name)
15.21 @@ -984,7 +984,7 @@
15.22 context = self.is_method(objpath)
15.23
15.24 self.process_assignment_for_object(original_name,
15.25 - make_expression("((__attr) {%s, &%s})" % (
15.26 + make_expression("((__attr) {.context=%s, .value=&%s})" % (
15.27 context and "&%s" % encode_path(context) or "0",
15.28 encode_path(objpath))))
15.29
15.30 @@ -1148,7 +1148,7 @@
15.31 if context_required:
15.32 args = ["__CONTEXT_AS_VALUE(__tmp_targets[%d])" % self.function_target]
15.33 else:
15.34 - args = ["(__attr) {0, 0}"]
15.35 + args = ["__NULL"]
15.36
15.37 args += [None] * (not parameters and len(n.args) or parameters and len(parameters) or 0)
15.38 kwcodes = []
15.39 @@ -1306,13 +1306,13 @@
15.40 # Without defaults, produce an attribute referring to the function.
15.41
15.42 if not defaults:
15.43 - return make_expression("((__attr) {0, &%s})" % encode_path(function_name))
15.44 + return make_expression("((__attr) {.context=0, .value=&%s})" % encode_path(function_name))
15.45
15.46 # With defaults, copy the function structure and set the defaults on the
15.47 # copy.
15.48
15.49 else:
15.50 - return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {0, __tmp_value})" % (
15.51 + return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {.context=0, .value=__tmp_value})" % (
15.52 encode_path(function_name),
15.53 encode_symbol("obj", function_name),
15.54 ", ".join(defaults)))