a68g-optimiser.h
1 //! @file a68g-optimiser.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 [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 #if !defined (__A68G_OPTIMISER_H__)
23 #define __A68G_OPTIMISER_H__
24
25 extern BOOL_T constant_unit (NODE_T *);
26 extern BOOL_T folder_mode (MOID_T *);
27 extern void build_script (void);
28 extern void compiler (FILE_T);
29 extern void load_script (void);
30 extern void push_unit (NODE_T *);
31 extern void rewrite_script_source (void);
32
33 // Library for code generator
34
35 extern INT_T a68_add_int (INT_T, INT_T);
36 extern INT_T a68_sub_int (INT_T, INT_T);
37 extern INT_T a68_mul_int (INT_T, INT_T);
38 extern INT_T a68_over_int (INT_T, INT_T);
39 extern INT_T a68_mod_int (INT_T, INT_T);
40 extern REAL_T a68_div_int (INT_T, INT_T);
41
42 extern void a68_ln_complex (A68_REAL *, A68_REAL *);
43 extern void a68_sqrt_complex (A68_REAL *, A68_REAL *);
44 extern void a68_sin_complex (A68_REAL *, A68_REAL *);
45 extern void a68_cos_complex (A68_REAL *, A68_REAL *);
46 extern void a68_tan_complex (A68_REAL *, A68_REAL *);
47 extern void a68_asin_complex (A68_REAL *, A68_REAL *);
48 extern void a68_acos_complex (A68_REAL *, A68_REAL *);
49 extern void a68_atan_complex (A68_REAL *, A68_REAL *);
50 extern void a68_sinh_complex (A68_REAL *, A68_REAL *);
51 extern void a68_cosh_complex (A68_REAL *, A68_REAL *);
52 extern void a68_tanh_complex (A68_REAL *, A68_REAL *);
53 extern void a68_asinh_complex (A68_REAL *, A68_REAL *);
54 extern void a68_acosh_complex (A68_REAL *, A68_REAL *);
55 extern void a68_atanh_complex (A68_REAL *, A68_REAL *);
56
57 // Operators that are inlined in compiled code
58
59 #define a68_eq_complex(x, y) (RE (x) == RE (y) && IM (x) == IM (y))
60 #define a68_ne_complex(x, y) (! a68_eq_complex (x, y))
61 #define a68_plusab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) += (j), (i))
62 #define a68_minusab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) -= (j), (i))
63 #define a68_timesab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) *= (j), (i))
64 #define a68_overab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) /= (j), (i))
65 #define a68_entier(x) ((int) floor (x))
66 #define a68_plusab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) += (j), (i))
67 #define a68_minusab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) -= (j), (i))
68 #define a68_timesab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) *= (j), (i))
69 #define a68_divab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) /= (j), (i))
70 #define a68_re_complex(z) (RE (z))
71 #define a68_im_complex(z) (IM (z))
72 #define a68_abs_complex(z) a68_hypot (RE (z), IM (z))
73 #define a68_arg_complex(z) atan2 (IM (z), RE (z))
74
75 #define a68_i_complex(z, re, im) {\
76 STATUS_RE (z) = INIT_MASK;\
77 STATUS_IM (z) = INIT_MASK;\
78 RE (z) = re;\
79 IM (z) = im;}
80
81 #define a68_minus_complex(z, x) {\
82 STATUS_RE (z) = INIT_MASK;\
83 STATUS_IM (z) = INIT_MASK;\
84 RE (z) = -RE (x);\
85 IM (z) = -IM (x);}
86
87 #define a68_conj_complex(z, x) {\
88 STATUS_RE (z) = INIT_MASK;\
89 STATUS_IM (z) = INIT_MASK;\
90 RE (z) = RE (x);\
91 IM (z) = -IM (x);}
92
93 #define a68_add_complex(z, x, y) {\
94 STATUS_RE (z) = INIT_MASK;\
95 STATUS_IM (z) = INIT_MASK;\
96 RE (z) = RE (x) + RE (y);\
97 IM (z) = IM (x) + IM (y);}
98
99 #define a68_sub_complex(z, x, y) {\
100 STATUS_RE (z) = INIT_MASK;\
101 STATUS_IM (z) = INIT_MASK;\
102 RE (z) = RE (x) - RE (y);\
103 IM (z) = IM (x) - IM (y);}
104
105 #define a68_mul_complex(z, x, y) {\
106 STATUS_RE (z) = INIT_MASK;\
107 STATUS_IM (z) = INIT_MASK;\
108 RE (z) = RE (x) * RE (y) - IM (x) * IM (y);\
109 IM (z) = IM (x) * RE (y) + RE (x) * IM (y);}
110
111 #endif