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-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 //! Definitions for the plugin compiler.
25
26 #if !defined (__A68G_OPTIMISER_H__)
27 #define __A68G_OPTIMISER_H__
28
29 BOOL_T constant_unit (NODE_T *);
30 BOOL_T folder_mode (MOID_T *);
31 void build_script (void);
32 void load_script (void);
33 void plugin_driver_clean (int);
34 void plugin_driver_code (void);
35 void plugin_driver_compile (void);
36 void plugin_driver_emit (FILE_T);
37 void plugin_driver_genie (void);
38 void push_unit (NODE_T *);
39 void rewrite_script_source (void);
40
41 // Library for code generator
42
43 INT_T a68_add_int (INT_T, INT_T);
44 INT_T a68_sub_int (INT_T, INT_T);
45 INT_T a68_mul_int (INT_T, INT_T);
46 INT_T a68_over_int (INT_T, INT_T);
47 INT_T a68_mod_int (INT_T, INT_T);
48 REAL_T a68_div_int (INT_T, INT_T);
49
50 void a68_ln_complex (A68_REAL *, A68_REAL *);
51 void a68_sqrt_complex (A68_REAL *, A68_REAL *);
52 void a68_sin_complex (A68_REAL *, A68_REAL *);
53 void a68_cos_complex (A68_REAL *, A68_REAL *);
54 void a68_tan_complex (A68_REAL *, A68_REAL *);
55 void a68_asin_complex (A68_REAL *, A68_REAL *);
56 void a68_acos_complex (A68_REAL *, A68_REAL *);
57 void a68_atan_complex (A68_REAL *, A68_REAL *);
58 void a68_sinh_complex (A68_REAL *, A68_REAL *);
59 void a68_cosh_complex (A68_REAL *, A68_REAL *);
60 void a68_tanh_complex (A68_REAL *, A68_REAL *);
61 void a68_asinh_real_complex (A68_REAL *, A68_REAL *);
62 void a68_acosh_real_complex (A68_REAL *, A68_REAL *);
63 void a68_atanh_real_complex (A68_REAL *, A68_REAL *);
64
65 // Operators that are inlined in compiled code
66
67 #define a68_eq_complex(x, y) (RE (x) == RE (y) && IM (x) == IM (y))
68 #define a68_ne_complex(x, y) (! a68_eq_complex (x, y))
69 #define a68_plusab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) += (j), (i))
70 #define a68_min_realusab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) -= (j), (i))
71 #define a68_timesab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) *= (j), (i))
72 #define a68_overab_int(i, j) (VALUE ((A68_INT *) ADDRESS (i)) /= (j), (i))
73 #define a68_entier(x) ((int) floor (x))
74 #define a68_plusab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) += (j), (i))
75 #define a68_min_realusab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) -= (j), (i))
76 #define a68_timesab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) *= (j), (i))
77 #define a68_divab_real(i, j) (VALUE ((A68_REAL *) ADDRESS (i)) /= (j), (i))
78 #define a68_re_complex(z) (RE (z))
79 #define a68_im_complex(z) (IM (z))
80 #define a68_abs_real_complex(z) a68_hypot_real (RE (z), IM (z))
81 #define a68_arg_complex(z) atan2 (IM (z), RE (z))
82
83 #define a68_i_complex(z, re, im) {\
84 STATUS_RE (z) = INIT_MASK;\
85 STATUS_IM (z) = INIT_MASK;\
86 RE (z) = re;\
87 IM (z) = im;}
88
89 #define a68_min_realus_complex(z, x) {\
90 STATUS_RE (z) = INIT_MASK;\
91 STATUS_IM (z) = INIT_MASK;\
92 RE (z) = -RE (x);\
93 IM (z) = -IM (x);}
94
95 #define a68_conj_complex(z, x) {\
96 STATUS_RE (z) = INIT_MASK;\
97 STATUS_IM (z) = INIT_MASK;\
98 RE (z) = RE (x);\
99 IM (z) = -IM (x);}
100
101 #define a68_add_complex(z, x, y) {\
102 STATUS_RE (z) = INIT_MASK;\
103 STATUS_IM (z) = INIT_MASK;\
104 RE (z) = RE (x) + RE (y);\
105 IM (z) = IM (x) + IM (y);}
106
107 #define a68_sub_complex(z, x, y) {\
108 STATUS_RE (z) = INIT_MASK;\
109 STATUS_IM (z) = INIT_MASK;\
110 RE (z) = RE (x) - RE (y);\
111 IM (z) = IM (x) - IM (y);}
112
113 #define a68_mul_complex(z, x, y) {\
114 STATUS_RE (z) = INIT_MASK;\
115 STATUS_IM (z) = INIT_MASK;\
116 RE (z) = RE (x) * RE (y) - IM (x) * IM (y);\
117 IM (z) = IM (x) * RE (y) + RE (x) * IM (y);}
118
119 #endif
© 2002-2024 J.M. van der Veer (jmvdveer@xs4all.nl)
|