a68g-postulates.c

     
   1  //! @file a68g-postulates.c
   2  //! @author J. Marcel van der Veer
   3  
   4  //! @section Copyright
   5  //!
   6  //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
   7  //! Copyright 2001-2024 J. Marcel van der Veer [algol68g@xs4all.nl].
   8  
   9  //! @section License
  10  //!
  11  //! This program is free software; you can redistribute it and/or modify it 
  12  //! under the terms of the GNU General Public License as published by the 
  13  //! Free Software Foundation; either version 3 of the License, or 
  14  //! (at your option) any later version.
  15  //!
  16  //! This program is distributed in the hope that it will be useful, but 
  17  //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  18  //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
  19  //! more details. You should have received a copy of the GNU General Public 
  20  //! License along with this program. If not, see [http://www.gnu.org/licenses/].
  21  
  22  //! @section Synopsis
  23  //!
  24  //! Postulates needed for proving equivalence of modes.
  25  
  26  #include "a68g.h"
  27  #include "a68g-postulates.h"
  28  
  29  //! @brief Initialise use of postulate-lists.
  30  
  31  void init_postulates (void)
  32  {
  33    A68 (top_postulate) = NO_POSTULATE;
  34    A68 (top_postulate_list) = NO_POSTULATE;
  35  }
  36  
  37  //! @brief Make old postulates available for new use.
  38  
  39  void free_postulate_list (POSTULATE_T * start, const POSTULATE_T * stop)
  40  {
  41    if (start == stop) {
  42      return;
  43    }
  44    POSTULATE_T *last = start;
  45    for (; NEXT (last) != stop; FORWARD (last)) {
  46      ;
  47    }
  48    NEXT (last) = A68 (top_postulate_list);
  49    A68 (top_postulate_list) = start;
  50  }
  51  
  52  //! @brief Add postulates to postulate-list.
  53  
  54  void make_postulate (POSTULATE_T ** p, MOID_T * a, MOID_T * b)
  55  {
  56    POSTULATE_T *new_one;
  57    if (A68 (top_postulate_list) != NO_POSTULATE) {
  58      new_one = A68 (top_postulate_list);
  59      FORWARD (A68 (top_postulate_list));
  60    } else {
  61      new_one = (POSTULATE_T *) get_temp_heap_space ((size_t) SIZE_ALIGNED (POSTULATE_T));
  62      A68 (new_postulates)++;
  63    }
  64    A (new_one) = a;
  65    B (new_one) = b;
  66    NEXT (new_one) = *p;
  67    *p = new_one;
  68  }
  69  
  70  //! @brief Where postulates are in the list.
  71  
  72  POSTULATE_T *is_postulated_pair (POSTULATE_T * p, const MOID_T * a, const MOID_T * b)
  73  {
  74    for (; p != NO_POSTULATE; FORWARD (p)) {
  75      if (A (p) == a && B (p) == b) {
  76        return p;
  77      }
  78    }
  79    return NO_POSTULATE;
  80  }
  81  
  82  //! @brief Where postulate is in the list.
  83  
  84  POSTULATE_T *is_postulated (POSTULATE_T * p, const MOID_T * a)
  85  {
  86    for (; p != NO_POSTULATE; FORWARD (p)) {
  87      if (A (p) == a) {
  88        return p;
  89      }
  90    }
  91    return NO_POSTULATE;
  92  }