Lichen

Changeset

852:7c314a9d1724
2018-07-12 Paul Boddie raw files shortlog changelog graph Attempt to reintroduce function acquisition optimisations by extending context tests related to invocations of access results.
deducer.py (file) templates/ops.c (file) templates/ops.h (file) templates/progops.c (file) templates/progops.h (file) translator.py (file)
     1.1 --- a/deducer.py	Thu Jul 12 15:25:53 2018 +0200
     1.2 +++ b/deducer.py	Thu Jul 12 16:46:25 2018 +0200
     1.3 @@ -2938,7 +2938,13 @@
     1.4              # Produce an advisory instruction regarding the context.
     1.5  
     1.6              if context_var:
     1.7 -                if context_test in ("ignore", "replace"):
     1.8 +
     1.9 +                # Only verify the context for invocation purposes if a suitable
    1.10 +                # test has been performed.
    1.11 +
    1.12 +                if context_test in ("ignore", "replace") or \
    1.13 +                   final_method in ("access-invoke", "static-invoke"):
    1.14 +
    1.15                      emit(("<context_identity_verified>", context_var))
    1.16                  else:
    1.17                      emit(("<context_identity>", context_var))
     2.1 --- a/templates/ops.c	Thu Jul 12 15:25:53 2018 +0200
     2.2 +++ b/templates/ops.c	Thu Jul 12 16:46:25 2018 +0200
     2.3 @@ -1,6 +1,6 @@
     2.4  /* Common operations.
     2.5  
     2.6 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     2.7 +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     2.8  
     2.9  This program is free software; you can redistribute it and/or modify it under
    2.10  the terms of the GNU General Public License as published by the Free Software
    2.11 @@ -231,7 +231,7 @@
    2.12  
    2.13  /* Context-related operations. */
    2.14  
    2.15 -int __test_context_update(__attr context, __attr attr)
    2.16 +int __test_context_update(__attr context, __attr attr, int invoke)
    2.17  {
    2.18      /* Return whether the context should be updated for the attribute. */
    2.19  
    2.20 @@ -258,6 +258,11 @@
    2.21              __raise_type_error();
    2.22      }
    2.23  
    2.24 +    /* Without a null or instance context, an invocation cannot be performed. */
    2.25 +
    2.26 +    if (invoke)
    2.27 +        __raise_unbound_method_error();
    2.28 +
    2.29      /* Test for access to a type class attribute using a type instance. */
    2.30  
    2.31      if (__test_specific_type(attrcontextvalue, &__TYPE_CLASS_TYPE) && __is_type_instance(__VALUE(context)))
    2.32 @@ -272,7 +277,7 @@
    2.33  {
    2.34      /* Update the context or return the unchanged attribute. */
    2.35  
    2.36 -    if (__test_context_update(context, attr))
    2.37 +    if (__test_context_update(context, attr, 0))
    2.38          return __update_context(context, attr);
    2.39      else
    2.40          return attr;
    2.41 @@ -288,7 +293,7 @@
    2.42      /* Revert the local context to that employed by the attribute if the
    2.43         supplied context is not appropriate. */
    2.44  
    2.45 -    if (!__test_context_update(context, attr))
    2.46 +    if (!__test_context_update(context, attr, 1))
    2.47          contexts[target] = __CONTEXT_AS_VALUE(attr);
    2.48      return attr;
    2.49  }
    2.50 @@ -297,7 +302,7 @@
    2.51  {
    2.52      /* Set the local context to the specified context if appropriate. */
    2.53  
    2.54 -    if (__test_context_update(context, __ATTRVALUE(value)))
    2.55 +    if (__test_context_update(context, __ATTRVALUE(value), 1))
    2.56          contexts[target] = context;
    2.57      return __ATTRVALUE(value);
    2.58  }
     3.1 --- a/templates/ops.h	Thu Jul 12 15:25:53 2018 +0200
     3.2 +++ b/templates/ops.h	Thu Jul 12 16:46:25 2018 +0200
     3.3 @@ -101,7 +101,7 @@
     3.4  
     3.5  /* Context-related operations. */
     3.6  
     3.7 -int __test_context_update(__attr context, __attr attr);
     3.8 +int __test_context_update(__attr context, __attr attr, int invoke);
     3.9  __attr __test_context(__attr context, __attr attr);
    3.10  __attr __update_context(__attr context, __attr attr);
    3.11  __attr __test_context_revert(int target, __attr context, __attr attr, __attr contexts[]);
     4.1 --- a/templates/progops.c	Thu Jul 12 15:25:53 2018 +0200
     4.2 +++ b/templates/progops.c	Thu Jul 12 16:46:25 2018 +0200
     4.3 @@ -151,6 +151,11 @@
     4.4      __Raise(__new___builtins___core_OverflowError(__NULL));
     4.5  }
     4.6  
     4.7 +void __raise_unbound_method_error()
     4.8 +{
     4.9 +    __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL));
    4.10 +}
    4.11 +
    4.12  void __raise_type_error()
    4.13  {
    4.14      __Raise(__new___builtins___core_TypeError(__NULL));
     5.1 --- a/templates/progops.h	Thu Jul 12 15:25:53 2018 +0200
     5.2 +++ b/templates/progops.h	Thu Jul 12 16:46:25 2018 +0200
     5.3 @@ -1,6 +1,6 @@
     5.4  /* Operations depending on program specifics.
     5.5  
     5.6 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
     5.7 +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
     5.8  
     5.9  This program is free software; you can redistribute it and/or modify it under
    5.10  the terms of the GNU General Public License as published by the Free Software
    5.11 @@ -55,6 +55,8 @@
    5.12  
    5.13  void __raise_overflow_error();
    5.14  
    5.15 +void __raise_unbound_method_error();
    5.16 +
    5.17  void __raise_zero_division_error();
    5.18  
    5.19  void __raise_type_error();
     6.1 --- a/translator.py	Thu Jul 12 15:25:53 2018 +0200
     6.2 +++ b/translator.py	Thu Jul 12 16:46:25 2018 +0200
     6.3 @@ -1070,9 +1070,21 @@
     6.4  
     6.5          context_required = True
     6.6          have_access_context = isinstance(expr, AttrResult)
     6.7 +
     6.8 +        # The context identity is merely the thing providing the context.
     6.9 +        # A verified context is one that does not need further testing for
    6.10 +        # suitability.
    6.11 +
    6.12          context_identity = have_access_context and expr.context()
    6.13          context_verified = have_access_context and expr.context_verified()
    6.14 +
    6.15 +        # The presence of any test operations in the accessor expression.
    6.16 +        # With such operations present, the expression cannot be eliminated.
    6.17 +
    6.18          tests_accessor = have_access_context and expr.tests_accessor()
    6.19 +
    6.20 +        # Parameter details and parameter list dimensions.
    6.21 +
    6.22          parameters = None
    6.23          num_parameters = None
    6.24          num_defaults = None