# HG changeset patch # User Paul Boddie # Date 1531406785 -7200 # Node ID 7c314a9d17241b43a3b15bb0e4e9690fa0eed0d8 # Parent b8314380f391b3e1ec2dbeae71de6ff9759f5da9 Attempt to reintroduce function acquisition optimisations by extending context tests related to invocations of access results. diff -r b8314380f391 -r 7c314a9d1724 deducer.py --- a/deducer.py Thu Jul 12 15:25:53 2018 +0200 +++ b/deducer.py Thu Jul 12 16:46:25 2018 +0200 @@ -2938,7 +2938,13 @@ # Produce an advisory instruction regarding the context. if context_var: - if context_test in ("ignore", "replace"): + + # Only verify the context for invocation purposes if a suitable + # test has been performed. + + if context_test in ("ignore", "replace") or \ + final_method in ("access-invoke", "static-invoke"): + emit(("", context_var)) else: emit(("", context_var)) diff -r b8314380f391 -r 7c314a9d1724 templates/ops.c --- a/templates/ops.c Thu Jul 12 15:25:53 2018 +0200 +++ b/templates/ops.c Thu Jul 12 16:46:25 2018 +0200 @@ -1,6 +1,6 @@ /* Common operations. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -231,7 +231,7 @@ /* Context-related operations. */ -int __test_context_update(__attr context, __attr attr) +int __test_context_update(__attr context, __attr attr, int invoke) { /* Return whether the context should be updated for the attribute. */ @@ -258,6 +258,11 @@ __raise_type_error(); } + /* Without a null or instance context, an invocation cannot be performed. */ + + if (invoke) + __raise_unbound_method_error(); + /* Test for access to a type class attribute using a type instance. */ if (__test_specific_type(attrcontextvalue, &__TYPE_CLASS_TYPE) && __is_type_instance(__VALUE(context))) @@ -272,7 +277,7 @@ { /* Update the context or return the unchanged attribute. */ - if (__test_context_update(context, attr)) + if (__test_context_update(context, attr, 0)) return __update_context(context, attr); else return attr; @@ -288,7 +293,7 @@ /* Revert the local context to that employed by the attribute if the supplied context is not appropriate. */ - if (!__test_context_update(context, attr)) + if (!__test_context_update(context, attr, 1)) contexts[target] = __CONTEXT_AS_VALUE(attr); return attr; } @@ -297,7 +302,7 @@ { /* Set the local context to the specified context if appropriate. */ - if (__test_context_update(context, __ATTRVALUE(value))) + if (__test_context_update(context, __ATTRVALUE(value), 1)) contexts[target] = context; return __ATTRVALUE(value); } diff -r b8314380f391 -r 7c314a9d1724 templates/ops.h --- a/templates/ops.h Thu Jul 12 15:25:53 2018 +0200 +++ b/templates/ops.h Thu Jul 12 16:46:25 2018 +0200 @@ -101,7 +101,7 @@ /* Context-related operations. */ -int __test_context_update(__attr context, __attr attr); +int __test_context_update(__attr context, __attr attr, int invoke); __attr __test_context(__attr context, __attr attr); __attr __update_context(__attr context, __attr attr); __attr __test_context_revert(int target, __attr context, __attr attr, __attr contexts[]); diff -r b8314380f391 -r 7c314a9d1724 templates/progops.c --- a/templates/progops.c Thu Jul 12 15:25:53 2018 +0200 +++ b/templates/progops.c Thu Jul 12 16:46:25 2018 +0200 @@ -151,6 +151,11 @@ __Raise(__new___builtins___core_OverflowError(__NULL)); } +void __raise_unbound_method_error() +{ + __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL)); +} + void __raise_type_error() { __Raise(__new___builtins___core_TypeError(__NULL)); diff -r b8314380f391 -r 7c314a9d1724 templates/progops.h --- a/templates/progops.h Thu Jul 12 15:25:53 2018 +0200 +++ b/templates/progops.h Thu Jul 12 16:46:25 2018 +0200 @@ -1,6 +1,6 @@ /* Operations depending on program specifics. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -55,6 +55,8 @@ void __raise_overflow_error(); +void __raise_unbound_method_error(); + void __raise_zero_division_error(); void __raise_type_error(); diff -r b8314380f391 -r 7c314a9d1724 translator.py --- a/translator.py Thu Jul 12 15:25:53 2018 +0200 +++ b/translator.py Thu Jul 12 16:46:25 2018 +0200 @@ -1070,9 +1070,21 @@ context_required = True have_access_context = isinstance(expr, AttrResult) + + # The context identity is merely the thing providing the context. + # A verified context is one that does not need further testing for + # suitability. + context_identity = have_access_context and expr.context() context_verified = have_access_context and expr.context_verified() + + # The presence of any test operations in the accessor expression. + # With such operations present, the expression cannot be eliminated. + tests_accessor = have_access_context and expr.tests_accessor() + + # Parameter details and parameter list dimensions. + parameters = None num_parameters = None num_defaults = None