# HG changeset patch # User Paul Boddie # Date 1487539476 -3600 # Node ID fcb8c13028d5788617a1d61502cf4ee3b105f652 # Parent adcdaeb19307f6771844963d1b4cd1cf5976c445 Replaced context test macros with functions to avoid evaluation order errors. diff -r adcdaeb19307 -r fcb8c13028d5 encoders.py --- a/encoders.py Sun Feb 19 19:06:22 2017 +0100 +++ b/encoders.py Sun Feb 19 22:24:36 2017 +0100 @@ -218,6 +218,10 @@ "", "", "", "", ) +context_op_functions = ( + "", "", + ) + reference_acting_ops = attribute_ops + checked_ops + typename_ops attribute_producing_ops = attribute_loading_ops + checked_loading_ops @@ -289,6 +293,11 @@ if op in context_ops: a.insert(0, context_index) + # Add the local context array to certain operations. + + if op in context_op_functions: + a.append("__tmp_contexts") + # Define any argument string. if a: diff -r adcdaeb19307 -r fcb8c13028d5 templates/ops.c --- a/templates/ops.c Sun Feb 19 19:06:22 2017 +0100 +++ b/templates/ops.c Sun Feb 19 22:24:36 2017 +0100 @@ -249,6 +249,25 @@ return __new_wrapper(context, attr); } +__attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[]) +{ + /* Revert the local context to that employed by the attribute if the + supplied context is not appropriate. */ + + if (!__test_context_update(context, attr)) + contexts[target] = __CONTEXT_AS_VALUE(attr).value; + return attr; +} + +__attr __test_context_static(int target, __ref context, __ref value, __ref contexts[]) +{ + /* Set the local context to the specified context if appropriate. */ + + if (__test_context_update(context, (__attr) {.value=value})) + contexts[target] = context; + return (__attr) {.value=value}; +} + /* Context testing for invocations. */ int __type_method_invocation(__ref context, __attr target) diff -r adcdaeb19307 -r fcb8c13028d5 templates/ops.h --- a/templates/ops.h Sun Feb 19 19:06:22 2017 +0100 +++ b/templates/ops.h Sun Feb 19 22:24:36 2017 +0100 @@ -73,21 +73,8 @@ int __test_context_update(__ref context, __attr attr); __attr __test_context(__ref context, __attr attr); __attr __update_context(__ref context, __attr attr); - -/* Revert the local context to that employed by the attribute if the supplied - context is not appropriate. */ - -#define __test_context_revert(__TARGET, __CONTEXT, __ATTR) \ - (__test_context_update(__CONTEXT, __ATTR) \ - ? __ATTR \ - : (__set_context(__TARGET, __CONTEXT_AS_VALUE(__ATTR)), __ATTR)) - -/* Set the local context to the specified context if appropriate. */ - -#define __test_context_static(__TARGET, __CONTEXT, __REF) \ - (__test_context_update(__CONTEXT, (__attr) {.value=__REF}) \ - ? (__set_context(__TARGET, (__attr) {.value=__CONTEXT}), (__attr) {.value=__REF}) \ - : (__attr) {.value=__REF}) +__attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[]); +__attr __test_context_static(int target, __ref context, __ref value, __ref contexts[]); #define __get_context(__TARGET) (__tmp_contexts[__TARGET]) #define __set_context(__TARGET, __ATTR) (__tmp_contexts[__TARGET] = (__ATTR).value)