a68g-plugin.h
1 //! @file a68g-plugin.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_PLUGIN_H__)
27 #define __A68G_PLUGIN_H__
28
29 typedef union UFU UFU;
30
31 union UFU
32 {
33 UNSIGNED_T u;
34 REAL_T f;
35 };
36
37 #define BASIC(p, n) (basic_unit (stems_from ((p), (n))))
38
39 #define CON "const"
40 #define ELM "elem"
41 #define TMP "tmp"
42 #define ARG "arg"
43 #define ARR "array"
44 #define DEC "declarer"
45 #define DRF "deref"
46 #define DSP "display"
47 #define FUN "function"
48 #define PUP "pop"
49 #define REF "ref"
50 #define SEL "field"
51 #define TUP "tuple"
52
53 #define A68_MAKE_NOTHING 0
54 #define A68_MAKE_OTHERS 1
55 #define A68_MAKE_FUNCTION 2
56
57 #define OFFSET_OFF(s) (OFFSET (NODE_PACK (SUB (s))))
58 #define WIDEN_TO(p, a, b) (MOID (p) == MODE (b) && MOID (SUB (p)) == MODE (a))
59
60 #define NEEDS_DNS(m) (m != NO_MOID && (IS (m, REF_SYMBOL) || IS (m, PROC_SYMBOL) || IS (m, UNION_SYMBOL) || IS (m, FORMAT_SYMBOL)))
61
62 #define CODE_EXECUTE(p) {\
63 indentf (out, a68_bufprt (A68 (edit_line), SNPRINTF_SIZE, "GENIE_UNIT_TRACE (_NODE_ (%d));", NUMBER (p)));\
64 }
65
66 #define NAME_SIZE 200
67
68 BOOK_T *signed_in (int, int, const char *);
69 BOOL_T basic_argument (NODE_T *);
70 BOOL_T basic_call (NODE_T *);
71 BOOL_T basic_collateral (NODE_T *);
72 BOOL_T basic_conditional (NODE_T *);
73 BOOL_T basic_formula (NODE_T *);
74 BOOL_T basic_indexer (NODE_T *);
75 BOOL_T basic_mode (MOID_T *);
76 BOOL_T basic_mode_non_row (MOID_T *);
77 BOOL_T basic_monadic_formula (NODE_T *);
78 BOOL_T basic_serial (NODE_T *, int);
79 BOOL_T basic_slice (NODE_T *);
80 BOOL_T basic_unit (NODE_T *);
81 BOOL_T basic_unit (NODE_T *);
82 BOOL_T need_initialise_frame (NODE_T *);
83 BOOL_T primitive_mode (const MOID_T *);
84 BOOL_T same_tree (NODE_T *, NODE_T *);
85 char *compile_call (NODE_T *, FILE_T);
86 char *compile_cast (NODE_T *, FILE_T);
87 char *compile_denotation (NODE_T *, FILE_T);
88 char *compile_dereference_identifier (NODE_T *, FILE_T);
89 char *compile_formula (NODE_T *, FILE_T);
90 char *compile_identifier (NODE_T *, FILE_T);
91 char *gen_basic_conditional (NODE_T *, FILE_T, int);
92 char *gen_basic (NODE_T *, FILE_T);
93 char *gen_call (NODE_T *, FILE_T, int);
94 char *gen_cast (NODE_T *, FILE_T, int);
95 char *gen_closed_clause (NODE_T *, FILE_T, int);
96 char *gen_code_clause (NODE_T *, FILE_T, int);
97 char *gen_collateral_clause (NODE_T *, FILE_T, int);
98 char *gen_conditional_clause (NODE_T *, FILE_T, int);
99 char *gen_denotation (NODE_T *, FILE_T, int);
100 char *gen_deproceduring (NODE_T *, FILE_T, int);
101 char *gen_dereference_identifier (NODE_T *, FILE_T, int);
102 char *gen_dereference_selection (NODE_T *, FILE_T, int);
103 char *gen_dereference_slice (NODE_T *, FILE_T, int);
104 char *gen_formula (NODE_T *, FILE_T, int);
105 char *gen_identifier (NODE_T *, FILE_T, int);
106 char *gen_identity_relation (NODE_T *, FILE_T, int);
107 char *gen_int_case_clause (NODE_T *, FILE_T, int);
108 char *gen_loop_clause (NODE_T *, FILE_T, int);
109 char *gen_selection (NODE_T *, FILE_T, int);
110 char *gen_slice (NODE_T *, FILE_T, int);
111 char *gen_uniting (NODE_T *, FILE_T, int);
112 char *gen_unit (NODE_T *, FILE_T, int);
113 char *gen_voiding_assignation_identifier (NODE_T *, FILE_T, int);
114 char *gen_voiding_assignation_selection (NODE_T *, FILE_T, int);
115 char *gen_voiding_assignation_slice (NODE_T *, FILE_T, int);
116 char *gen_voiding_call (NODE_T *, FILE_T, int);
117 char *gen_voiding_deproceduring (NODE_T *, FILE_T, int);
118 char *gen_voiding_formula (NODE_T *, FILE_T, int);
119 char *inline_mode (MOID_T *);
120 char *internal_mode (const MOID_T *);
121 char *make_name (char *, char *, char *, int);
122 char *make_unic_name (char *, char *, char *, char *);
123 char *moid_with_name (char *, MOID_T *, char *);
124 DEC_T *add_declaration (DEC_T **, char *, int, char *);
125 DEC_T *add_identifier (DEC_T **, int, char *);
126 NODE_T *stems_from (NODE_T *, int);
127 void comment_source (NODE_T *, FILE_T);
128 void constant_folder (NODE_T *, FILE_T, int);
129 void gen_assign (NODE_T *, FILE_T, char *);
130 void gen_basics (NODE_T *, FILE_T);
131 void gen_check_init (NODE_T *, FILE_T, char *);
132 void gen_declaration_list (NODE_T *, FILE_T, int *, char *);
133 void gen_push (NODE_T *, FILE_T);
134 void gen_serial_clause (NODE_T *, FILE_T, NODE_T **, int *, int *, char *, int);
135 void gen_units (NODE_T *, FILE_T);
136 void get_stack (NODE_T *, FILE_T, char *, char *);
137 void indentf (FILE_T, int);
138 void indentf (FILE_T, int);
139 void indent (FILE_T, char *);
140 void indent (FILE_T, char *);
141 void init_static_frame (FILE_T, NODE_T *);
142 void inline_arguments (NODE_T *, FILE_T, int, int *);
143 void inline_call (NODE_T *, FILE_T, int);
144 void inline_closed (NODE_T *, FILE_T, int);
145 void inline_collateral (NODE_T *, FILE_T, int);
146 void inline_collateral_units (NODE_T *, FILE_T, int);
147 void inline_comment_source (NODE_T *, FILE_T);
148 void inline_conditional (NODE_T *, FILE_T, int);
149 void inline_denotation (NODE_T *, FILE_T, int);
150 void inline_dereference_identifier (NODE_T *, FILE_T, int);
151 void inline_dereference_selection (NODE_T *, FILE_T, int);
152 void inline_dereference_slice (NODE_T *, FILE_T, int);
153 void inline_formula (NODE_T *, FILE_T, int);
154 void inline_identifier (NODE_T *, FILE_T, int);
155 void inline_identity_relation (NODE_T *, FILE_T, int);
156 void inline_indexer (NODE_T *, FILE_T, int, INT_T *, char *);
157 void inline_monadic_formula (NODE_T *, FILE_T, int);
158 void inline_ref_identifier (NODE_T *, FILE_T, int);
159 void inline_selection (NODE_T *, FILE_T, int);
160 void inline_selection_ref_to_ref (NODE_T *, FILE_T, int);
161 void inline_single_argument (NODE_T *, FILE_T, int);
162 void inline_slice (NODE_T *, FILE_T, int);
163 void inline_slice_ref_to_ref (NODE_T *, FILE_T, int);
164 void inline_unit (NODE_T *, FILE_T, int);
165 void inline_unit (NODE_T *, FILE_T, int);
166 void inline_widening (NODE_T *, FILE_T, int);
167 void print_declarations (FILE_T, DEC_T *);
168 void sign_in (int, int, char *, void *, int);
169 void sign_in_name (char *, int *);
170 void undentf (FILE_T, int);
171 void undent (FILE_T, char *);
172 void write_fun_postlude (NODE_T *, FILE_T, char *);
173 void write_fun_prelude (NODE_T *, FILE_T, char *);
174 void write_prelude (FILE_T);
175
176 // The phases we go through.
177
178 enum
179 { L_NONE = 0, L_DECLARE = 1, L_INITIALISE, L_EXECUTE, L_EXECUTE_2, L_YIELD, L_PUSH };
180
181 #define UNIC_NAME(k) (A68_OPT (unic_functions)[k].fun)
182
183 enum
184 { UNIC_EXISTS, UNIC_MAKE_NEW, UNIC_MAKE_ALT };
185
186 // TRANSLATION tabulates translations for genie actions.
187 // This tells what to call for an A68 action.
188
189 typedef int LEVEL_T;
190
191 typedef struct
192 {
193 GPROC *procedure;
194 char *code;
195 } TRANSLATION;
196
197 extern TRANSLATION *monadics, *dyadics, *functions;
198
199 extern TRANSLATION monadics_nocheck[];
200 extern TRANSLATION monadics_check[];
201 extern TRANSLATION dyadics_nocheck[];
202 extern TRANSLATION dyadics_check[];
203 extern TRANSLATION functions_nocheck[];
204 extern TRANSLATION functions_check[];
205 extern TRANSLATION constants[];
206
207 #endif
© 2002-2024 J.M. van der Veer (jmvdveer@xs4all.nl)
|