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