1.1 --- a/encoders.py Sun Feb 12 23:24:42 2017 +0100
1.2 +++ b/encoders.py Mon Feb 13 15:35:36 2017 +0100
1.3 @@ -207,7 +207,7 @@
1.4 )
1.5
1.6 static_ops = (
1.7 - "__load_static",
1.8 + "__load_static_ignore", "__load_static_replace", "__load_static_test",
1.9 )
1.10
1.11 reference_acting_ops = attribute_ops + checked_ops + typename_ops
1.12 @@ -274,8 +274,7 @@
1.13 # Obtain addresses of static objects.
1.14
1.15 elif op in static_ops:
1.16 - a[0] = "&%s" % a[0]
1.17 - a[1] = "&%s" % a[1]
1.18 + a[-1] = "&%s" % a[-1]
1.19
1.20 argstr = "(%s)" % ", ".join(map(str, a))
1.21
2.1 --- a/generator.py Sun Feb 12 23:24:42 2017 +0100
2.2 +++ b/generator.py Mon Feb 13 15:35:36 2017 +0100
2.3 @@ -533,7 +533,7 @@
2.4 # Define a macro for the constant.
2.5
2.6 attr_name = encode_path(const_path)
2.7 - print >>f_decls, "#define %s ((__attr) {{.context=&%s, .value=&%s}})" % (attr_name, structure_name, structure_name)
2.8 + print >>f_decls, "#define %s ((__attr) {.value=&%s})" % (attr_name, structure_name)
2.9
2.10 def make_parameter_table(self, f_decls, f_defs, parameters):
2.11
2.12 @@ -874,16 +874,10 @@
2.13
2.14 if kind == "<class>":
2.15 attr = encode_instantiator_pointer(attr)
2.16 - unbound_attr = attr
2.17 -
2.18 - # Provide bound method and unbound function pointers if
2.19 - # populating methods in a class.
2.20 -
2.21 else:
2.22 attr = encode_function_pointer(attr)
2.23 - unbound_attr = "__unbound_method"
2.24
2.25 - structure.append("{{.inv=%s, .fn=%s}}" % (unbound_attr, attr))
2.26 + structure.append("{.fn=%s}" % attr)
2.27 continue
2.28
2.29 # Special argument specification member.
2.30 @@ -892,7 +886,7 @@
2.31 signature = self.get_signature_for_callable(ref.get_origin())
2.32 ptable = encode_tablename("<function>", signature)
2.33
2.34 - structure.append("{{.min=%s, .ptable=&%s}}" % (attr, ptable))
2.35 + structure.append("{.min=%s, .ptable=&%s}" % (attr, ptable))
2.36 continue
2.37
2.38 # Special internal data member.
2.39 @@ -906,8 +900,8 @@
2.40 # Special internal key member.
2.41
2.42 elif attrname == "__key__":
2.43 - structure.append("{{.code=%s, .pos=%s}}" % (attr and encode_symbol("code", attr) or "0",
2.44 - attr and encode_symbol("pos", attr) or "0"))
2.45 + structure.append("{.code=%s, .pos=%s}" % (attr and encode_symbol("code", attr) or "0",
2.46 + attr and encode_symbol("pos", attr) or "0"))
2.47 continue
2.48
2.49 # Special cases.
2.50 @@ -950,13 +944,33 @@
2.51 # object paths.
2.52
2.53 value = path.rsplit(".", 1)[0]
2.54 - structure.append("{{.context=0, .value=&%s}}" % encode_path(value))
2.55 + structure.append("{.value=&%s}" % encode_path(value))
2.56 + continue
2.57 +
2.58 + # Special context member.
2.59 + # Set the context depending on the kind of attribute.
2.60 + # For methods: <parent>
2.61 + # For other attributes: __NULL
2.62 +
2.63 + elif attrname == "__context__":
2.64 + path = ref.get_origin()
2.65 +
2.66 + # Contexts of methods are derived from their object paths.
2.67 +
2.68 + context = "0"
2.69 +
2.70 + if ref.get_kind() == "<function>":
2.71 + parent = path.rsplit(".", 1)[0]
2.72 + if self.importer.classes.has_key(parent):
2.73 + context = "&%s" % encode_path(parent)
2.74 +
2.75 + structure.append("{.value=%s}" % context)
2.76 continue
2.77
2.78 # Special class relationship attributes.
2.79
2.80 elif is_type_attribute(attrname):
2.81 - structure.append("{{.context=0, .value=&%s}}" % encode_path(decode_type_attribute(attrname)))
2.82 + structure.append("{.value=&%s}" % encode_path(decode_type_attribute(attrname)))
2.83 continue
2.84
2.85 # All other kinds of members.
2.86 @@ -995,33 +1009,22 @@
2.87
2.88 if kind == "<instance>" and origin == self.none_type:
2.89 attr_path = encode_predefined_reference(self.none_value)
2.90 - return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name)
2.91 + return "{.value=&%s} /* %s */" % (attr_path, name)
2.92
2.93 # Predefined constant members.
2.94
2.95 if (path, name) in self.predefined_constant_members:
2.96 attr_path = encode_predefined_reference("%s.%s" % (path, name))
2.97 - return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name)
2.98 + return "{.value=&%s} /* %s */" % (attr_path, name)
2.99
2.100 # General undetermined members.
2.101
2.102 if kind in ("<var>", "<instance>"):
2.103 attr_path = encode_predefined_reference(self.none_value)
2.104 - return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name)
2.105 -
2.106 - # Set the context depending on the kind of attribute.
2.107 - # For methods: {&<parent>, &<attr>}
2.108 - # For other attributes: {&<attr>, &<attr>}
2.109 + return "{.value=&%s} /* %s */" % (attr_path, name)
2.110
2.111 else:
2.112 - if kind == "<function>" and structure_type == "<class>":
2.113 - parent = origin.rsplit(".", 1)[0]
2.114 - context = "&%s" % encode_path(parent)
2.115 - elif kind == "<instance>":
2.116 - context = "&%s" % encode_path(origin)
2.117 - else:
2.118 - context = "0"
2.119 - return "{{.context=%s, .value=&%s}}" % (context, encode_path(origin))
2.120 + return "{.value=&%s}" % encode_path(origin)
2.121
2.122 def append_defaults(self, path, structure):
2.123
2.124 @@ -1129,7 +1132,7 @@
2.125 }
2.126 __Catch(__tmp_exc)
2.127 {
2.128 - if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {{.context=0, .value=&__builtins___exception_system_SystemExit}})))
2.129 + if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.value=&__builtins___exception_system_SystemExit})))
2.130 return __load_via_object(
2.131 __load_via_object(__tmp_exc.arg.value, %s).value,
2.132 %s).intvalue;
3.1 --- a/inspector.py Sun Feb 12 23:24:42 2017 +0100
3.2 +++ b/inspector.py Mon Feb 13 15:35:36 2017 +0100
3.3 @@ -521,14 +521,17 @@
3.4 # class. Function instances provide these attributes.
3.5
3.6 if class_name != "__builtins__.core.function":
3.7 +
3.8 self.set_name("__fn__") # special instantiator attribute
3.9 self.set_name("__args__") # special instantiator attribute
3.10
3.11 - # Provide leafname and parent attributes.
3.12 + # Provide leafname, parent and context attributes.
3.13
3.14 parent, leafname = class_name.rsplit(".", 1)
3.15 self.set_name("__name__", self.get_constant("string", leafname).reference())
3.16 - self.set_name("__parent__")
3.17 +
3.18 + if class_name != "__builtins__.core.function":
3.19 + self.set_name("__parent__")
3.20
3.21 self.process_structure_node(n.code)
3.22 self.exit_namespace()
4.1 --- a/lib/__builtins__/core.py Sun Feb 12 23:24:42 2017 +0100
4.2 +++ b/lib/__builtins__/core.py Mon Feb 13 15:35:36 2017 +0100
4.3 @@ -86,6 +86,7 @@
4.4 self.__args__ = None
4.5 self.__name__ = None
4.6 self.__parent__ = None
4.7 + self.__context__ = None
4.8
4.9 def __bool__(self):
4.10
4.11 @@ -122,6 +123,17 @@
4.12
4.13 __repr__ = __str__
4.14
4.15 +class wrapper:
4.16 +
4.17 + "A special method wrapper."
4.18 +
4.19 + def __init__(self, context, value):
4.20 +
4.21 + "Initialise a wrapper with the given 'context' and wrapped 'value'."
4.22 +
4.23 + self.__context__ = context
4.24 + self.__value__ = value
4.25 +
4.26 class Exception:
4.27
4.28 "The root of all exception types."
5.1 --- a/optimiser.py Sun Feb 12 23:24:42 2017 +0100
5.2 +++ b/optimiser.py Mon Feb 13 15:35:36 2017 +0100
5.3 @@ -510,16 +510,21 @@
5.4 emit(("__store_via_object", parent, attrname, "<assexpr>"))
5.5
5.6 elif final_method in ("static", "static-invoke"):
5.7 - parent, attrname = origin.rsplit(".", 1)
5.8 - accessor = ("__load_static", parent, origin)
5.9 + accessor = ("__load_static_ignore", origin)
5.10
5.11 # Wrap accesses in context operations.
5.12
5.13 if context_test == "test":
5.14 - emit(("__test_context", context_var, accessor))
5.15 + if final_method in ("static", "static-invoke"):
5.16 + emit(("__load_static_test", context_var, origin))
5.17 + else:
5.18 + emit(("__test_context", context_var, accessor))
5.19
5.20 elif context_test == "replace":
5.21 - emit(("__update_context", context_var, accessor))
5.22 + if final_method in ("static", "static-invoke"):
5.23 + emit(("__load_static_replace", context_var, origin))
5.24 + else:
5.25 + emit(("__update_context", context_var, accessor))
5.26
5.27 elif final_method not in ("assign", "static-assign"):
5.28 emit(accessor)
6.1 --- a/templates/native/iconv.c Sun Feb 12 23:24:42 2017 +0100
6.2 +++ b/templates/native/iconv.c Mon Feb 13 15:35:36 2017 +0100
6.3 @@ -156,7 +156,6 @@
6.4
6.5 /* Return the descriptor as an opaque value. */
6.6
6.7 - attr.context = 0;
6.8 attr.datavalue = (void *) result;
6.9 return attr;
6.10 }
7.1 --- a/templates/native/io.c Sun Feb 12 23:24:42 2017 +0100
7.2 +++ b/templates/native/io.c Mon Feb 13 15:35:36 2017 +0100
7.3 @@ -80,7 +80,6 @@
7.4
7.5 else
7.6 {
7.7 - attr.context = 0;
7.8 attr.datavalue = (void *) f;
7.9 return attr;
7.10 }
7.11 @@ -113,7 +112,6 @@
7.12
7.13 else
7.14 {
7.15 - attr.context = 0;
7.16 attr.datavalue = (void *) f;
7.17 return attr;
7.18 }
8.1 --- a/templates/ops.c Sun Feb 12 23:24:42 2017 +0100
8.2 +++ b/templates/ops.c Mon Feb 13 15:35:36 2017 +0100
8.3 @@ -25,10 +25,19 @@
8.4
8.5 /* Direct access and manipulation of static objects. */
8.6
8.7 -__attr __load_static(__ref parent, __ref obj)
8.8 +__attr __load_static_ignore(__ref obj)
8.9 +{
8.10 + return (__attr) {.value=obj};
8.11 +}
8.12 +
8.13 +__attr __load_static_replace(__ref context, __ref obj)
8.14 {
8.15 - __attr out = {.context=parent, .value=obj};
8.16 - return out;
8.17 + return __update_context(context, (__attr) {.value=obj});
8.18 +}
8.19 +
8.20 +__attr __load_static_test(__ref context, __ref obj)
8.21 +{
8.22 + return __test_context(context, (__attr) {.value=obj});
8.23 }
8.24
8.25 /* Direct retrieval operations, returning and setting attributes. */
8.26 @@ -192,9 +201,11 @@
8.27
8.28 __attr __test_context(__ref context, __attr attr)
8.29 {
8.30 + __ref attrcontext = __CONTEXT_AS_VALUE(attr).value;
8.31 +
8.32 /* Preserve any existing null or instance context. */
8.33
8.34 - if ((attr.context == 0) || __is_instance(attr.context))
8.35 + if ((attrcontext == 0) || __is_instance(attrcontext))
8.36 return attr;
8.37
8.38 /* Test any instance context against the context employed by the
8.39 @@ -202,7 +213,7 @@
8.40
8.41 if (__is_instance(context))
8.42 {
8.43 - if (__test_common_instance(context, __TYPEPOS(attr.context), __TYPECODE(attr.context)))
8.44 + if (__test_common_instance(context, __TYPEPOS(attrcontext), __TYPECODE(attrcontext)))
8.45 return __update_context(context, attr);
8.46 else
8.47 __raise_type_error();
8.48 @@ -210,7 +221,7 @@
8.49
8.50 /* Test for access to a type class attribute using a type instance. */
8.51
8.52 - if (__test_specific_type(attr.context, &__TYPE_CLASS_TYPE) && __is_type_instance(context))
8.53 + if (__test_specific_type(attrcontext, &__TYPE_CLASS_TYPE) && __is_type_instance(context))
8.54 return __update_context(context, attr);
8.55
8.56 /* Otherwise, preserve the attribute as retrieved. */
8.57 @@ -220,47 +231,55 @@
8.58
8.59 __attr __update_context(__ref context, __attr attr)
8.60 {
8.61 - __attr out = {.context=context, .value=attr.value};
8.62 - return out;
8.63 + return __new_wrapper(context, attr);
8.64 }
8.65
8.66 /* Context testing for invocations. */
8.67
8.68 -int __type_method_invocation(__attr attr)
8.69 +int __type_method_invocation(__ref context, __attr target)
8.70 {
8.71 - __attr parent;
8.72 + __ref targetcontext = __CONTEXT_AS_VALUE(target).value;
8.73
8.74 /* Require instances, not classes, where methods are function instances. */
8.75
8.76 - if (!__is_instance(attr.value))
8.77 + if (!__is_instance(target.value))
8.78 return 0;
8.79
8.80 - /* Access the parent of the callable and test if it is the type object. */
8.81 + /* Access the context of the callable and test if it is the type object. */
8.82
8.83 - parent = __check_and_load_via_object_null(attr.value, __ATTRPOS(__parent__), __ATTRCODE(__parent__));
8.84 - return ((parent.value != 0) && __test_specific_type(parent.value, &__TYPE_CLASS_TYPE) && __is_type_instance(attr.context));
8.85 + return ((targetcontext != 0) && __test_specific_type(targetcontext, &__TYPE_CLASS_TYPE) && __is_type_instance(context));
8.86 }
8.87
8.88 -__attr (*__get_function(__attr attr))(__attr[])
8.89 +__attr __unwrap_callable(__attr callable)
8.90 {
8.91 + __attr value = __check_and_load_via_object_null(callable.value, __ATTRPOS(__value__), __ATTRCODE(__value__));
8.92 + return value.value ? value : callable;
8.93 +}
8.94 +
8.95 +__attr (*__get_function(__ref context, __attr target))(__attr[])
8.96 +{
8.97 + target = __unwrap_callable(target);
8.98 +
8.99 /* Require null or instance contexts for functions and methods respectively,
8.100 or type instance contexts for type methods. */
8.101
8.102 - if ((attr.context == 0) || __is_instance(attr.context) || __type_method_invocation(attr))
8.103 - return __load_via_object(attr.value, __ATTRPOS(__fn__)).fn;
8.104 + if ((context == 0) || __is_instance(context) || __type_method_invocation(context, target))
8.105 + return __load_via_object(target.value, __ATTRPOS(__fn__)).fn;
8.106 else
8.107 - return __load_via_object(attr.value, __ATTRPOS(__fn__)).inv;
8.108 + return __unbound_method;
8.109 }
8.110
8.111 -__attr (*__check_and_get_function(__attr attr))(__attr[])
8.112 +__attr (*__check_and_get_function(__ref context, __attr target))(__attr[])
8.113 {
8.114 + target = __unwrap_callable(target);
8.115 +
8.116 /* Require null or instance contexts for functions and methods respectively,
8.117 or type instance contexts for type methods. */
8.118
8.119 - if ((attr.context == 0) || __is_instance(attr.context) || __type_method_invocation(attr))
8.120 - return __check_and_load_via_object(attr.value, __ATTRPOS(__fn__), __ATTRCODE(__fn__)).fn;
8.121 + if ((context == 0) || __is_instance(context) || __type_method_invocation(context, target))
8.122 + return __check_and_load_via_object(target.value, __ATTRPOS(__fn__), __ATTRCODE(__fn__)).fn;
8.123 else
8.124 - return __check_and_load_via_object(attr.value, __ATTRPOS(__fn__), __ATTRCODE(__fn__)).inv;
8.125 + return __unbound_method;
8.126 }
8.127
8.128 /* Basic structure tests. */
8.129 @@ -295,10 +314,7 @@
8.130
8.131 __attr __CONTEXT_AS_VALUE(__attr attr)
8.132 {
8.133 - __attr out;
8.134 - out.context = attr.context;
8.135 - out.value = attr.context;
8.136 - return out;
8.137 + return __check_and_load_via_object_null(attr.value, __ATTRPOS(__context__), __ATTRCODE(__context__));
8.138 }
8.139
8.140 /* Type testing. */
8.141 @@ -310,7 +326,6 @@
8.142
8.143 int __ISNULL(__attr value)
8.144 {
8.145 - /* (value.context == __NULL.context) is superfluous */
8.146 return (value.value == 0); /* __NULL.value */
8.147 }
8.148
9.1 --- a/templates/ops.h Sun Feb 12 23:24:42 2017 +0100
9.2 +++ b/templates/ops.h Mon Feb 13 15:35:36 2017 +0100
9.3 @@ -24,7 +24,9 @@
9.4
9.5 /* Direct access and manipulation of static objects. */
9.6
9.7 -__attr __load_static(__ref parent, __ref obj);
9.8 +__attr __load_static_ignore(__ref obj);
9.9 +__attr __load_static_replace(__ref context, __ref obj);
9.10 +__attr __load_static_test(__ref context, __ref obj);
9.11
9.12 /* Direct retrieval operations, returning attributes. */
9.13
9.14 @@ -77,8 +79,9 @@
9.15
9.16 /* Context testing for invocations. */
9.17
9.18 -__attr (*__get_function(__attr attr))(__attr[]);
9.19 -__attr (*__check_and_get_function(__attr attr))(__attr[]);
9.20 +__attr __unwrap_callable(__attr callable);
9.21 +__attr (*__get_function(__ref context, __attr target))(__attr[]);
9.22 +__attr (*__check_and_get_function(__ref context, __attr target))(__attr[]);
9.23
9.24 /* Basic structure tests. */
9.25
10.1 --- a/templates/progops.c Sun Feb 12 23:24:42 2017 +0100
10.2 +++ b/templates/progops.c Mon Feb 13 15:35:36 2017 +0100
10.3 @@ -30,11 +30,14 @@
10.4 __attr __new(const __table * table, __ref cls, size_t size)
10.5 {
10.6 __ref obj = (__ref) __ALLOCATE(1, size);
10.7 - __attr self = {.context=obj, .value=obj};
10.8 - __attr tmp = {.context=0, .value=cls};
10.9 obj->table = table;
10.10 - __store_via_object(obj, __ATTRPOS(__class__), tmp);
10.11 - return self;
10.12 + __store_via_object(obj, __ATTRPOS(__class__), (__attr) {.value=cls});
10.13 + return (__attr) {.value=obj};
10.14 +}
10.15 +
10.16 +__attr __new_wrapper(__ref context, __attr attr)
10.17 +{
10.18 + return __new___builtins___core_wrapper((__attr[]) {__NULL, {.value=context}, attr});
10.19 }
10.20
10.21 /* Generic internal data allocation. */
10.22 @@ -181,9 +184,13 @@
10.23 unsigned int nkwargs, __param kwcodes[], __attr kwargs[],
10.24 unsigned int nargs, __attr args[])
10.25 {
10.26 + /* Unwrap any wrapped function. */
10.27 +
10.28 + __attr target = __unwrap_callable(callable);
10.29 +
10.30 /* Obtain the __args__ special member, referencing the parameter table. */
10.31
10.32 - __attr minparams = __check_and_load_via_object(callable.value, __ATTRPOS(__args__), __ATTRCODE(__args__));
10.33 + __attr minparams = __check_and_load_via_object(target.value, __ATTRPOS(__args__), __ATTRCODE(__args__));
10.34
10.35 /* Refer to the table and minimum/maximum. */
10.36
10.37 @@ -240,12 +247,12 @@
10.38 for (pos = nargs; pos < max; pos++)
10.39 {
10.40 if (allargs[pos].value == 0)
10.41 - allargs[pos] = __GETDEFAULT(callable.value, pos - min);
10.42 + allargs[pos] = __GETDEFAULT(target.value, pos - min);
10.43 }
10.44
10.45 /* Call with the prepared arguments. */
10.46
10.47 - return (always_callable ? __get_function(callable) : __check_and_get_function(callable))(allargs);
10.48 + return (always_callable ? __get_function(allargs[0].value, target) : __check_and_get_function(allargs[0].value, target))(allargs);
10.49 }
10.50
10.51 /* Error routines. */
11.1 --- a/templates/progops.h Sun Feb 12 23:24:42 2017 +0100
11.2 +++ b/templates/progops.h Mon Feb 13 15:35:36 2017 +0100
11.3 @@ -25,6 +25,7 @@
11.4 /* Generic instantiation operations, defining common members. */
11.5
11.6 __attr __new(const __table *table, __ref cls, size_t size);
11.7 +__attr __new_wrapper(__ref context, __attr attr);
11.8
11.9 /* Generic internal data allocation. */
11.10
12.1 --- a/templates/types.h Sun Feb 12 23:24:42 2017 +0100
12.2 +++ b/templates/types.h Mon Feb 13 15:35:36 2017 +0100
12.3 @@ -51,44 +51,35 @@
12.4 const __param params[];
12.5 } __ptable;
12.6
12.7 -/* Attributes are context and value pairs.
12.8 +/* Attributes are values referring to objects or encoding other information.
12.9 Objects are collections of attributes.
12.10 Object references are references to tables and collections of attributes.
12.11 Attribute references are references to single attributes. */
12.12
12.13 typedef struct __obj __obj;
12.14 typedef struct __fragment __fragment;
12.15 +typedef union __attr __attr;
12.16 +typedef __obj * __ref;
12.17
12.18 -typedef struct __attr
12.19 +typedef union __attr
12.20 {
12.21 - /* One of... */
12.22 - union
12.23 - {
12.24 - struct {
12.25 - __obj * context; /* attribute context */
12.26 - __obj * value; /* attribute value */
12.27 - };
12.28 - struct {
12.29 - __ppos min; /* minimum number of parameters */
12.30 - const __ptable * ptable; /* parameter table */
12.31 - };
12.32 - struct {
12.33 - __pcode code; /* parameter table code for key */
12.34 - __ppos pos; /* parameter table position for key */
12.35 - };
12.36 - struct {
12.37 - struct __attr (*inv)(); /* unbound callable details */
12.38 - struct __attr (*fn)(); /* callable details */
12.39 - };
12.40 - union
12.41 - {
12.42 - int intvalue; /* integer value */
12.43 - double floatvalue; /* floating point value */
12.44 - char * strvalue; /* string value */
12.45 - __fragment * seqvalue; /* sequence data */
12.46 - void * datavalue; /* object-specific data */
12.47 - };
12.48 + __ref value; /* attribute value */
12.49 + struct {
12.50 + __ppos min; /* minimum number of parameters */
12.51 + const __ptable * ptable; /* parameter table */
12.52 + };
12.53 + struct {
12.54 + __pcode code; /* parameter table code for key */
12.55 + __ppos pos; /* parameter table position for key */
12.56 };
12.57 + struct {
12.58 + __attr (*fn)(); /* callable details */
12.59 + };
12.60 + int intvalue; /* integer value */
12.61 + double floatvalue; /* floating point value */
12.62 + char * strvalue; /* string value */
12.63 + __fragment * seqvalue; /* sequence data */
12.64 + void * datavalue; /* object-specific data */
12.65 } __attr;
12.66
12.67 typedef struct __obj
12.68 @@ -98,7 +89,7 @@
12.69 __attr attrs[]; /* attributes */
12.70 } __obj;
12.71
12.72 -typedef __obj * __ref;
12.73 +#define __INSTANCE_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + sizeof(__table *) + sizeof(__ppos))
12.74
12.75 /* Fragments are simple collections of attributes employed by sequence types.
12.76 They provide the basis of lists and tuples. */
12.77 @@ -109,7 +100,7 @@
12.78 __attr attrs[];
12.79 } __fragment;
12.80
12.81 -#define __FRAGMENT_SIZE(NUMBER) (NUMBER * sizeof(__attr) + 2 * sizeof(unsigned int))
12.82 +#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int))
12.83
12.84 /* Special instance position value. The pos member of __obj refers to the
12.85 special type attribute for classes, indicating which position holds the
12.86 @@ -119,7 +110,7 @@
12.87
12.88 /* Special null values. */
12.89
12.90 -#define __NULL ((__attr) {{.context=0, .value=0}})
12.91 +#define __NULL ((__attr) {.value=0})
12.92
12.93 /* Function pointer type. */
12.94
13.1 --- a/translator.py Sun Feb 12 23:24:42 2017 +0100
13.2 +++ b/translator.py Mon Feb 13 15:35:36 2017 +0100
13.3 @@ -142,7 +142,7 @@
13.4 elif static_name:
13.5 parent = ref.parent()
13.6 context = ref.has_kind("<function>") and encode_path(parent) or None
13.7 - return "((__attr) {{.context=%s, .value=&%s}})" % (context and "&%s" % context or "0", static_name)
13.8 + return "((__attr) {.value=&%s})" % static_name
13.9
13.10 # Qualified names must be converted into parent-relative accesses.
13.11
13.12 @@ -875,7 +875,7 @@
13.13
13.14 if not ref.static():
13.15 self.process_assignment_for_object(
13.16 - n.name, make_expression("((__attr) {{.context=0, .value=&%s}})" %
13.17 + n.name, make_expression("((__attr) {.value=&%s})" %
13.18 encode_path(class_name)))
13.19
13.20 self.enter_namespace(n.name)
13.21 @@ -1054,9 +1054,7 @@
13.22 context = self.is_method(objpath)
13.23
13.24 self.process_assignment_for_object(original_name,
13.25 - make_expression("((__attr) {{.context=%s, .value=&%s}})" % (
13.26 - context and "&%s" % encode_path(context) or "0",
13.27 - encode_path(objpath))))
13.28 + make_expression("((__attr) {.value=&%s})" % encode_path(objpath)))
13.29
13.30 def process_function_defaults(self, n, name, objpath, instance_name=None):
13.31
13.32 @@ -1349,7 +1347,8 @@
13.33 self.record_temp("__tmp_targets")
13.34
13.35 if context_required:
13.36 - stages.append("__get_function(__tmp_targets[%d])" % self.function_target)
13.37 + stages.append("__get_function(__CONTEXT_AS_VALUE(__tmp_targets[%d]).value, __tmp_targets[%d])" % (
13.38 + self.function_target, self.function_target))
13.39 else:
13.40 stages.append("__load_via_object(__tmp_targets[%d].value, %s).fn" % (
13.41 self.function_target, encode_symbol("pos", "__fn__")))
13.42 @@ -1414,14 +1413,14 @@
13.43 # Without defaults, produce an attribute referring to the function.
13.44
13.45 if not defaults:
13.46 - return make_expression("((__attr) {{.context=0, .value=&%s}})" % encode_path(function_name))
13.47 + return make_expression("((__attr) {.value=&%s})" % encode_path(function_name))
13.48
13.49 # With defaults, copy the function structure and set the defaults on the
13.50 # copy.
13.51
13.52 else:
13.53 self.record_temp("__tmp_value")
13.54 - return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {{.context=0, .value=__tmp_value}})" % (
13.55 + return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {.value=__tmp_value})" % (
13.56 encode_path(function_name),
13.57 encode_symbol("obj", function_name),
13.58 ", ".join(defaults)))