1.1 --- a/generator.py Tue Mar 07 17:32:14 2017 +0100
1.2 +++ b/generator.py Tue Mar 07 18:10:00 2017 +0100
1.3 @@ -1183,60 +1183,52 @@
1.4 NOTE: where __call__ is provided by the class.
1.5 """
1.6
1.7 - parameters = self.importer.function_parameters[init_ref.get_origin()]
1.8 initialiser = init_ref.get_origin()
1.9 + parameters = self.importer.function_parameters[initialiser]
1.10 argmin, argmax = self.get_argument_limits(initialiser)
1.11
1.12 + l = []
1.13 + for name in parameters:
1.14 + l.append("__attr %s" % name)
1.15 +
1.16 print >>f_code, """\
1.17 -__attr %s(__attr __args[])
1.18 +__attr %s(__attr __self%s)
1.19 {
1.20 - /* Allocate the structure. */
1.21 - __args[0] = __NEWINSTANCE(%s);
1.22 -
1.23 - /* Call the initialiser. */
1.24 - %s(%s, __args);
1.25 -
1.26 - /* Return the allocated object details. */
1.27 - return __args[0];
1.28 + return %s(__NEWINSTANCE(%s)%s);
1.29 }
1.30 """ % (
1.31 - encode_instantiator_pointer(path),
1.32 - encode_path(path),
1.33 - "__CALL%d" % argmax,
1.34 - encode_function_pointer(initialiser)
1.35 - )
1.36 + encode_instantiator_pointer(path),
1.37 + l and ", %s" % ",".join(l) or "",
1.38 + encode_function_pointer(initialiser),
1.39 + encode_path(path),
1.40 + parameters and ", %s" % ", ".join(parameters) or ""
1.41 + )
1.42 +
1.43 + # Signature: __new_typename(__attr __self, ...)
1.44 +
1.45 + print >>f_signatures, "__attr %s(__attr __self%s);" % (
1.46 + encode_instantiator_pointer(path),
1.47 + l and ", %s" % ", ".join(l) or ""
1.48 + )
1.49
1.50 print >>f_signatures, "#define __HAVE_%s" % encode_path(path)
1.51 - print >>f_signatures, "__attr %s(__attr[]);" % encode_instantiator_pointer(path)
1.52
1.53 # Write additional literal instantiators. These do not call the
1.54 # initialisers but instead populate the structures directly.
1.55
1.56 + # Signature: __newliteral_sequence(ARGS, NUM)
1.57 +
1.58 if path in self.literal_instantiator_types:
1.59 if path in self.literal_mapping_types:
1.60 style = "mapping"
1.61 else:
1.62 style = "sequence"
1.63
1.64 - print >>f_code, """\
1.65 -__attr %s(__attr __args[], __pos number)
1.66 -{
1.67 - /* Allocate the structure. */
1.68 - __args[0] = __NEWINSTANCE(%s);
1.69 -
1.70 - /* Allocate a structure for the data and set it on the __data__ attribute. */
1.71 - %s(__args, number);
1.72 -
1.73 - /* Return the allocated object details. */
1.74 - return __args[0];
1.75 -}
1.76 -""" % (
1.77 - encode_literal_instantiator(path),
1.78 - encode_path(path),
1.79 - encode_literal_data_initialiser(style)
1.80 - )
1.81 -
1.82 - print >>f_signatures, "__attr %s(__attr[], __pos);" % encode_literal_instantiator(path)
1.83 + print >>f_signatures, "#define %s(ARGS, NUM) (%s(__NEWINSTANCE(%s), ARGS, NUM))" % (
1.84 + encode_literal_instantiator(path),
1.85 + encode_literal_data_initialiser(style),
1.86 + encode_path(path)
1.87 + )
1.88
1.89 def write_main_program(self, f_code, f_signatures):
1.90
2.1 --- a/templates/native/iconv.c Tue Mar 07 17:32:14 2017 +0100
2.2 +++ b/templates/native/iconv.c Tue Mar 07 18:10:00 2017 +0100
2.3 @@ -33,18 +33,14 @@
2.4 static void __raise_incomplete_sequence_error(__attr value, __attr arg)
2.5 {
2.6 #ifdef __HAVE_posix_iconv_IncompleteSequenceError
2.7 - __attr args[3] = {__NULL, value, arg};
2.8 - __attr exc = __new_posix_iconv_IncompleteSequenceError(args);
2.9 - __Raise(exc);
2.10 + __Raise(__new_posix_iconv_IncompleteSequenceError(__NULL, value, arg));
2.11 #endif /* __HAVE_posix_iconv_IncompleteSequenceError */
2.12 }
2.13
2.14 static void __raise_invalid_sequence_error(__attr value, __attr arg)
2.15 {
2.16 #ifdef __HAVE_posix_iconv_InvalidSequenceError
2.17 - __attr args[3] = {__NULL, value, arg};
2.18 - __attr exc = __new_posix_iconv_InvalidSequenceError(args);
2.19 - __Raise(exc);
2.20 + __Raise(__new_posix_iconv_InvalidSequenceError(__NULL, value, arg));
2.21 #endif /* __HAVE_posix_iconv_InvalidSequenceError */
2.22 }
2.23
3.1 --- a/templates/progops.c Tue Mar 07 17:32:14 2017 +0100
3.2 +++ b/templates/progops.c Tue Mar 07 18:10:00 2017 +0100
3.3 @@ -33,13 +33,13 @@
3.4 __ref obj = (__ref) __ALLOCATE(1, size);
3.5 obj->table = table;
3.6 obj->pos = __INSTANCEPOS;
3.7 - __store_via_object(obj, __class__, (__attr) {.value=cls});
3.8 + __store_via_object(obj, __class__, __ATTRVALUE(cls));
3.9 return (__attr) {.value=obj};
3.10 }
3.11
3.12 __attr __new_wrapper(__ref context, __attr attr)
3.13 {
3.14 - return __new___builtins___core_wrapper((__attr[]) {__NULL, {.value=context}, attr});
3.15 + return __new___builtins___core_wrapper(__NULL, __ATTRVALUE(context), attr);
3.16 }
3.17
3.18 /* Generic internal data allocation. */
3.19 @@ -57,43 +57,40 @@
3.20 return data;
3.21 }
3.22
3.23 -void __newdata_sequence(__attr args[], unsigned int number)
3.24 +__attr __newdata_sequence(__attr self, __attr args[], unsigned int number)
3.25 {
3.26 /* Calculate the size of the fragment. */
3.27
3.28 __fragment *data = __new_fragment(number);
3.29 __attr attr = {.seqvalue=data};
3.30 - unsigned int i, j;
3.31 + unsigned int i;
3.32
3.33 - /* Copy the given number of values, starting from the second element. */
3.34 + /* Copy the given number of values. */
3.35
3.36 - for (i = 1, j = 0; i <= number; i++, j++)
3.37 - data->attrs[j] = args[i];
3.38 + for (i = 0; i <= number; i++)
3.39 + data->attrs[i] = args[i];
3.40
3.41 data->size = number;
3.42
3.43 /* Store a reference to the data in the object's __data__ attribute. */
3.44
3.45 - __store_via_object(args[0].value, __data__, attr);
3.46 + __store_via_object(self.value, __data__, attr);
3.47 + return self;
3.48 }
3.49
3.50 #ifdef __HAVE___builtins___dict_dict
3.51 -void __newdata_mapping(__attr args[], unsigned int number)
3.52 +__attr __newdata_mapping(__attr self, __attr args[], unsigned int number)
3.53 {
3.54 - __attr dict = args[0];
3.55 __attr callargs[2];
3.56
3.57 /* Create a temporary list using the arguments. */
3.58
3.59 - __newliteral___builtins___list_list(args, number);
3.60 + __attr tmp = __newliteral___builtins___list_list(args, number);
3.61
3.62 /* Call __init__ with the dict object and list argument. */
3.63
3.64 - callargs[0] = dict;
3.65 - callargs[1] = args[0];
3.66 -
3.67 - __fn___builtins___dict_dict___init__(callargs);
3.68 - args[0] = dict;
3.69 + __fn___builtins___dict_dict___init__(self, tmp);
3.70 + return self;
3.71 }
3.72 #endif /* __HAVE___builtins___dict_dict */
3.73
3.74 @@ -102,56 +99,42 @@
3.75 void __raise_eof_error()
3.76 {
3.77 #ifdef __HAVE___builtins___exception_io_EOFError
3.78 - __attr args[1];
3.79 - __attr exc = __new___builtins___exception_io_EOFError(args);
3.80 - __Raise(exc);
3.81 + __Raise(__new___builtins___exception_io_EOFError(__NULL));
3.82 #endif /* __HAVE___builtins___exception_io_EOFError */
3.83 }
3.84
3.85 void __raise_io_error(__attr value)
3.86 {
3.87 #ifdef __HAVE___builtins___exception_io_IOError
3.88 - __attr args[2] = {__NULL, value};
3.89 - __attr exc = __new___builtins___exception_io_IOError(args);
3.90 - __Raise(exc);
3.91 + __Raise(__new___builtins___exception_io_IOError(__NULL, value));
3.92 #endif /* __HAVE___builtins___exception_io_IOError */
3.93 }
3.94
3.95 void __raise_memory_error()
3.96 {
3.97 - __attr args[1];
3.98 - __attr exc = __new___builtins___core_MemoryError(args);
3.99 - __Raise(exc);
3.100 + __Raise(__new___builtins___core_MemoryError(__NULL));
3.101 }
3.102
3.103 void __raise_os_error(__attr value, __attr arg)
3.104 {
3.105 #ifdef __HAVE___builtins___exception_system_OSError
3.106 - __attr args[3] = {__NULL, value, arg};
3.107 - __attr exc = __new___builtins___exception_system_OSError(args);
3.108 - __Raise(exc);
3.109 + __Raise(__new___builtins___exception_system_OSError(__NULL, value, arg));
3.110 #endif /* __HAVE___builtins___exception_system_OSError */
3.111 }
3.112
3.113 void __raise_overflow_error()
3.114 {
3.115 - __attr args[1];
3.116 - __attr exc = __new___builtins___core_OverflowError(args);
3.117 - __Raise(exc);
3.118 + __Raise(__new___builtins___core_OverflowError(__NULL));
3.119 }
3.120
3.121 void __raise_type_error()
3.122 {
3.123 - __attr args[1];
3.124 - __attr exc = __new___builtins___core_TypeError(args);
3.125 - __Raise(exc);
3.126 + __Raise(__new___builtins___core_TypeError(__NULL));
3.127 }
3.128
3.129 void __raise_zero_division_error()
3.130 {
3.131 - __attr args[1];
3.132 - __attr exc = __new___builtins___core_ZeroDivisionError(args);
3.133 - __Raise(exc);
3.134 + __Raise(__new___builtins___core_ZeroDivisionError(__NULL));
3.135 }
3.136
3.137 /* Helper for raising exception instances. */
3.138 @@ -266,9 +249,7 @@
3.139
3.140 __attr __unbound_method(__attr __self)
3.141 {
3.142 - __attr excargs[1];
3.143 - __attr exc = __new___builtins___core_UnboundMethodInvocation(excargs);
3.144 - __Raise(exc);
3.145 + __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL));
3.146 return __builtins___none_None; /* superfluous */
3.147 }
3.148
4.1 --- a/templates/progops.h Tue Mar 07 17:32:14 2017 +0100
4.2 +++ b/templates/progops.h Tue Mar 07 18:10:00 2017 +0100
4.3 @@ -31,10 +31,10 @@
4.4
4.5 __fragment *__new_fragment(unsigned int n);
4.6
4.7 -void __newdata_sequence(__attr args[], unsigned int number);
4.8 +__attr __newdata_sequence(__attr self, __attr args[], unsigned int number);
4.9
4.10 #ifdef __HAVE___builtins___dict_dict
4.11 -void __newdata_mapping(__attr args[], unsigned int number);
4.12 +__attr __newdata_mapping(__attr self, __attr args[], unsigned int number);
4.13 #endif /* __HAVE___builtins___dict_dict */
4.14
4.15 /* Helpers for raising errors within common operations. */
5.1 --- a/translator.py Tue Mar 07 17:32:14 2017 +0100
5.2 +++ b/translator.py Tue Mar 07 18:10:00 2017 +0100
5.3 @@ -811,7 +811,12 @@
5.4
5.5 # Produce the body and any additional return statement.
5.6
5.7 - expr = self.process_structure_node(n.code) or PredefinedConstantRef("None")
5.8 + expr = self.process_structure_node(n.code) or \
5.9 + self.in_method() and \
5.10 + function_name.rsplit(".", 1)[-1] == "__init__" and \
5.11 + TrResolvedNameRef("self", self.importer.function_locals[function_name]["self"]) or \
5.12 + PredefinedConstantRef("None")
5.13 +
5.14 if not isinstance(expr, ReturnRef):
5.15 self.writestmt("return %s;" % expr)
5.16
5.17 @@ -847,7 +852,6 @@
5.18
5.19 # Produce an appropriate access to an attribute's value.
5.20
5.21 - parameters = self.importer.function_parameters.get(self.get_namespace_path())
5.22 name_to_value = "%s.value" % name
5.23
5.24 # Write a test that raises a TypeError upon failure.
5.25 @@ -1184,18 +1188,17 @@
5.26
5.27 # Encode the arguments.
5.28
5.29 - argstr = ", ".join(args)
5.30 + # Where literal instantiation is occurring, add an argument indicating
5.31 + # the number of values. The context is excluded.
5.32 +
5.33 + if literal_instantiation:
5.34 + argstr = "__ARGS(%s), %d" % (", ".join(args[1:]), len(args) - 1)
5.35 + else:
5.36 + argstr = ", ".join(args)
5.37 +
5.38 kwargstr = kwargs and ("__ARGS(%s)" % ", ".join(kwargs)) or "0"
5.39 kwcodestr = kwcodes and ("__KWARGS(%s)" % ", ".join(kwcodes)) or "0"
5.40
5.41 - # Where literal instantiation is occurring, add an argument indicating
5.42 - # the number of values.
5.43 -
5.44 - if literal_instantiation:
5.45 - argstr = "__ARGS(%s), %d" % (argstr, len(args) - 1)
5.46 - elif instantiation:
5.47 - argstr = "__ARGS(%s)" % argstr
5.48 -
5.49 # First, the invocation expression is presented.
5.50
5.51 stages = []