1.1 --- a/templates/ops.c Tue Mar 21 18:45:42 2017 +0100
1.2 +++ b/templates/ops.c Thu Mar 23 16:40:57 2017 +0100
1.3 @@ -23,6 +23,13 @@
1.4 #include "progconsts.h"
1.5 #include "progtypes.h"
1.6
1.7 +/* Get object reference from attribute. */
1.8 +
1.9 +__ref __VALUE(__attr attr)
1.10 +{
1.11 + return attr.value;
1.12 +}
1.13 +
1.14 /* Basic structure tests. */
1.15
1.16 static inline int __HASATTR(__ref obj, int pos, int code)
1.17 @@ -37,12 +44,12 @@
1.18 return __ATTRVALUE(obj);
1.19 }
1.20
1.21 -__attr __load_static_replace(__ref context, __ref obj)
1.22 +__attr __load_static_replace(__attr context, __ref obj)
1.23 {
1.24 return __update_context(context, __ATTRVALUE(obj));
1.25 }
1.26
1.27 -__attr __load_static_test(__ref context, __ref obj)
1.28 +__attr __load_static_test(__attr context, __ref obj)
1.29 {
1.30 return __test_context(context, __ATTRVALUE(obj));
1.31 }
1.32 @@ -92,12 +99,12 @@
1.33
1.34 int __is_subclass(__ref obj, __attr cls)
1.35 {
1.36 - return __HASATTR(obj, __TYPEPOS(cls.value), __TYPECODE(cls.value));
1.37 + return __HASATTR(obj, __TYPEPOS(__VALUE(cls)), __TYPECODE(__VALUE(cls)));
1.38 }
1.39
1.40 int __is_instance_subclass(__ref obj, __attr cls)
1.41 {
1.42 - return __is_instance(obj) && __HASATTR(__get_class(obj), __TYPEPOS(cls.value), __TYPECODE(cls.value));
1.43 + return __is_instance(obj) && __HASATTR(__get_class(obj), __TYPEPOS(__VALUE(cls)), __TYPECODE(__VALUE(cls)));
1.44 }
1.45
1.46 int __is_type_instance(__ref obj)
1.47 @@ -107,7 +114,7 @@
1.48
1.49 __ref __get_class(__ref obj)
1.50 {
1.51 - return __load_via_object(obj, __class__).value;
1.52 + return __VALUE(__load_via_object(obj, __class__));
1.53 }
1.54
1.55 __attr __get_class_attr(__ref obj)
1.56 @@ -174,7 +181,7 @@
1.57 __attr __check_and_load_via_any__(__ref obj, int pos, int code)
1.58 {
1.59 __attr out = __check_and_load_via_object_null(obj, pos, code);
1.60 - if (out.value == 0)
1.61 + if (__ISNULL(out))
1.62 out = __check_and_load_via_class__(obj, pos, code);
1.63 return out;
1.64 }
1.65 @@ -216,27 +223,28 @@
1.66
1.67 /* Context-related operations. */
1.68
1.69 -int __test_context_update(__ref context, __attr attr)
1.70 +int __test_context_update(__attr context, __attr attr)
1.71 {
1.72 /* Return whether the context should be updated for the attribute. */
1.73
1.74 - __ref attrcontext = __CONTEXT_AS_VALUE(attr).value;
1.75 + __attr attrcontext = __CONTEXT_AS_VALUE(attr);
1.76 + __ref attrcontextvalue = __VALUE(attrcontext);
1.77
1.78 /* Preserve any existing null or instance context. */
1.79
1.80 - if ((attrcontext == 0) || __is_instance(attrcontext))
1.81 + if (__ISNULL(attrcontext) || __is_instance(attrcontextvalue))
1.82 return 0;
1.83
1.84 /* Test any instance context against the context employed by the
1.85 attribute. */
1.86
1.87 - if (__is_instance(context))
1.88 + if (__is_instance(__VALUE(context)))
1.89 {
1.90 /* Obtain the special class attribute position and code identifying the
1.91 attribute context's class, inspecting the context instance for
1.92 compatibility. */
1.93
1.94 - if (__test_common_instance__(context, __TYPEPOS(attrcontext), __TYPECODE(attrcontext)))
1.95 + if (__test_common_instance__(__VALUE(context), __TYPEPOS(attrcontextvalue), __TYPECODE(attrcontextvalue)))
1.96 return 1;
1.97 else
1.98 __raise_type_error();
1.99 @@ -244,7 +252,7 @@
1.100
1.101 /* Test for access to a type class attribute using a type instance. */
1.102
1.103 - if (__test_specific_type(attrcontext, &__TYPE_CLASS_TYPE) && __is_type_instance(context))
1.104 + if (__test_specific_type(attrcontextvalue, &__TYPE_CLASS_TYPE) && __is_type_instance(__VALUE(context)))
1.105 return 1;
1.106
1.107 /* Otherwise, preserve the attribute as retrieved. */
1.108 @@ -252,7 +260,7 @@
1.109 return 0;
1.110 }
1.111
1.112 -__attr __test_context(__ref context, __attr attr)
1.113 +__attr __test_context(__attr context, __attr attr)
1.114 {
1.115 /* Update the context or return the unchanged attribute. */
1.116
1.117 @@ -262,22 +270,22 @@
1.118 return attr;
1.119 }
1.120
1.121 -__attr __update_context(__ref context, __attr attr)
1.122 +__attr __update_context(__attr context, __attr attr)
1.123 {
1.124 return __new_wrapper(context, attr);
1.125 }
1.126
1.127 -__attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[])
1.128 +__attr __test_context_revert(int target, __attr context, __attr attr, __attr contexts[])
1.129 {
1.130 /* Revert the local context to that employed by the attribute if the
1.131 supplied context is not appropriate. */
1.132
1.133 if (!__test_context_update(context, attr))
1.134 - contexts[target] = __CONTEXT_AS_VALUE(attr).value;
1.135 + contexts[target] = __CONTEXT_AS_VALUE(attr);
1.136 return attr;
1.137 }
1.138
1.139 -__attr __test_context_static(int target, __ref context, __ref value, __ref contexts[])
1.140 +__attr __test_context_static(int target, __attr context, __ref value, __attr contexts[])
1.141 {
1.142 /* Set the local context to the specified context if appropriate. */
1.143
1.144 @@ -288,53 +296,53 @@
1.145
1.146 /* Context testing for invocations. */
1.147
1.148 -int __type_method_invocation(__ref context, __attr target)
1.149 +int __type_method_invocation(__attr context, __attr target)
1.150 {
1.151 - __ref targetcontext = __CONTEXT_AS_VALUE(target).value;
1.152 + __attr targetcontext = __CONTEXT_AS_VALUE(target);
1.153
1.154 /* Require instances, not classes, where methods are function instances. */
1.155
1.156 - if (!__is_instance(target.value))
1.157 + if (!__is_instance(__VALUE(target)))
1.158 return 0;
1.159
1.160 /* Access the context of the callable and test if it is the type object. */
1.161
1.162 - return ((targetcontext != 0) && __test_specific_type(targetcontext, &__TYPE_CLASS_TYPE) && __is_type_instance(context));
1.163 + return (!__ISNULL(targetcontext) && __test_specific_type(__VALUE(targetcontext), &__TYPE_CLASS_TYPE) && __is_type_instance(__VALUE(context)));
1.164 }
1.165
1.166 __attr __unwrap_callable(__attr callable)
1.167 {
1.168 - __attr value = __check_and_load_via_object_null(callable.value, __ATTRPOS(__value__), __ATTRCODE(__value__));
1.169 - return value.value ? value : callable;
1.170 + __attr value = __check_and_load_via_object_null(__VALUE(callable), __ATTRPOS(__value__), __ATTRCODE(__value__));
1.171 + return __VALUE(value) ? value : callable;
1.172 }
1.173
1.174 __attr (*__get_function_unchecked(__attr target))(__attr[])
1.175 {
1.176 - return __load_via_object(__unwrap_callable(target).value, __fn__).fn;
1.177 + return __load_via_object(__VALUE(__unwrap_callable(target)), __fn__).fn;
1.178 }
1.179
1.180 -__attr (*__get_function(__ref context, __attr target))(__attr[])
1.181 +__attr (*__get_function(__attr context, __attr target))(__attr[])
1.182 {
1.183 target = __unwrap_callable(target);
1.184
1.185 /* Require null or instance contexts for functions and methods respectively,
1.186 or type instance contexts for type methods. */
1.187
1.188 - if ((context == 0) || __is_instance(context) || __type_method_invocation(context, target))
1.189 - return __load_via_object(target.value, __fn__).fn;
1.190 + if (__ISNULL(context) || __is_instance(__VALUE(context)) || __type_method_invocation(context, target))
1.191 + return __load_via_object(__VALUE(target), __fn__).fn;
1.192 else
1.193 return __unbound_method;
1.194 }
1.195
1.196 -__attr (*__check_and_get_function(__ref context, __attr target))(__attr[])
1.197 +__attr (*__check_and_get_function(__attr context, __attr target))(__attr[])
1.198 {
1.199 target = __unwrap_callable(target);
1.200
1.201 /* Require null or instance contexts for functions and methods respectively,
1.202 or type instance contexts for type methods. */
1.203
1.204 - if ((context == 0) || __is_instance(context) || __type_method_invocation(context, target))
1.205 - return __check_and_load_via_object__(target.value, __ATTRPOS(__fn__), __ATTRCODE(__fn__)).fn;
1.206 + if (__ISNULL(context) || __is_instance(__VALUE(context)) || __type_method_invocation(context, target))
1.207 + return __check_and_load_via_object__(__VALUE(target), __ATTRPOS(__fn__), __ATTRCODE(__fn__)).fn;
1.208 else
1.209 return __unbound_method;
1.210 }
1.211 @@ -359,7 +367,7 @@
1.212
1.213 __attr __CONTEXT_AS_VALUE(__attr attr)
1.214 {
1.215 - return __check_and_load_via_object_null(attr.value, __ATTRPOS(__context__), __ATTRCODE(__context__));
1.216 + return __check_and_load_via_object_null(__VALUE(attr), __ATTRPOS(__context__), __ATTRCODE(__context__));
1.217 }
1.218
1.219 /* Type testing. */