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-2023 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-prelude.h"
  28  #include "a68g-mp.h"
  29  #include "a68g-genie.h"
  30  #include "a68g-postulates.h"
  31  
  32  //! @brief Initialise use of postulate-lists.
  33  
  34  void init_postulates (void)
  35  {
  36    A68 (top_postulate) = NO_POSTULATE;
  37    A68 (top_postulate_list) = NO_POSTULATE;
  38  }
  39  
  40  //! @brief Make old postulates available for new use.
  41  
  42  void free_postulate_list (POSTULATE_T * start, POSTULATE_T * stop)
  43  {
  44    POSTULATE_T *last;
  45    if (start == stop) {
  46      return;
  47    }
  48    for (last = start; NEXT (last) != stop; FORWARD (last)) {
  49      ;
  50    }
  51    NEXT (last) = A68 (top_postulate_list);
  52    A68 (top_postulate_list) = start;
  53  }
  54  
  55  //! @brief Add postulates to postulate-list.
  56  
  57  void make_postulate (POSTULATE_T ** p, MOID_T * a, MOID_T * b)
  58  {
  59    POSTULATE_T *new_one;
  60    if (A68 (top_postulate_list) != NO_POSTULATE) {
  61      new_one = A68 (top_postulate_list);
  62      FORWARD (A68 (top_postulate_list));
  63    } else {
  64      new_one = (POSTULATE_T *) get_temp_heap_space ((size_t) SIZE_ALIGNED (POSTULATE_T));
  65      A68 (new_postulates)++;
  66    }
  67    A (new_one) = a;
  68    B (new_one) = b;
  69    NEXT (new_one) = *p;
  70    *p = new_one;
  71  }
  72  
  73  //! @brief Where postulates are in the list.
  74  
  75  POSTULATE_T *is_postulated_pair (POSTULATE_T * p, MOID_T * a, MOID_T * b)
  76  {
  77    for (; p != NO_POSTULATE; FORWARD (p)) {
  78      if (A (p) == a && B (p) == b) {
  79        return p;
  80      }
  81    }
  82    return NO_POSTULATE;
  83  }
  84  
  85  //! @brief Where postulate is in the list.
  86  
  87  POSTULATE_T *is_postulated (POSTULATE_T * p, MOID_T * a)
  88  {
  89    for (; p != NO_POSTULATE; FORWARD (p)) {
  90      if (A (p) == a) {
  91        return p;
  92      }
  93    }
  94    return NO_POSTULATE;
  95  }