a68g-stack.h

You can download the current version of Algol 68 Genie and its documentation here.

   1 //! @file a68g-stack.h
   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 .
   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 .
  21 
  22 #if !defined (__A68G_STACK_H__)
  23 #define __A68G_STACK_H__
  24 
  25 // Macro's for stack checking. Since the stacks grow by small amounts at a time
  26 // (A68 rows are in the heap), we check the stacks only at certain points: where
  27 // A68 recursion may set in, or in the garbage collector. We check whether there
  28 // still is sufficient overhead to make it to the next check.
  29 
  30 #define TOO_COMPLEX "program too complex"
  31 
  32 #define SYSTEM_STACK_USED (ABS ((int) (A68 (system_stack_offset) - &stack_offset)))
  33 #define LOW_SYSTEM_STACK_ALERT(p) {\
  34   BYTE_T stack_offset;\
  35   if (A68 (stack_size) > 0 && SYSTEM_STACK_USED >= A68 (stack_limit)) {\
  36     if ((p) == NO_NODE) {\
  37       ABEND (A68_TRUE, TOO_COMPLEX, ERROR_STACK_OVERFLOW);\
  38     } else {\
  39       diagnostic (A68_RUNTIME_ERROR, (p), ERROR_STACK_OVERFLOW);\
  40       exit_genie ((p), A68_RUNTIME_ERROR);\
  41   }}}
  42 
  43 #define LOW_STACK_ALERT(p) {\
  44   LOW_SYSTEM_STACK_ALERT (p);\
  45   if ((p) != NO_NODE && (A68_FP >= A68 (frame_stack_limit) || A68_SP >= A68 (expr_stack_limit))) { \
  46     diagnostic (A68_RUNTIME_ERROR, (p), ERROR_STACK_OVERFLOW);\
  47     exit_genie ((p), A68_RUNTIME_ERROR);\
  48   }}
  49 
  50 #endif