aboutsummaryrefslogtreecommitdiff
path: root/gcc/m2/gm2-compiler/M2Base.def
blob: 8d6546a4b1630bde8dd0374e57c241e7df07dfd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
(* M2Base.def provides a mechanism to check fundamental types.

Copyright (C) 2001-2025 Free Software Foundation, Inc.
Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.

This file is part of GNU Modula-2.

GNU Modula-2 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GNU Modula-2 is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Modula-2; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  *)

DEFINITION MODULE M2Base ;

(* M2Base implements the default base types and base procedures in the
   Modula-2 front end.  *)

FROM NameKey IMPORT Name ;
FROM gcctypes IMPORT location_t ;


VAR
   TemplateProcedure,
   ActivationPointer,

   Nil,
   Cardinal, Integer,
   Boolean, True, False,
   Char, Proc,
   LongInt, LongCard,
   ShortInt, ShortCard,
   ZType, RType, CType,
   Real,
   LongReal, ShortReal,
   Complex, LongComplex,
   ShortComplex,
   High, LengthS,
   Cap, Abs, Odd,
   Convert, Val,
   Chr,
   Re, Im, Cmplx,
   Min, Max,
   New, Dispose,
   Inc, Dec,
   Incl, Excl,
   ExceptionAssign,
   ExceptionReturn,
   ExceptionInc,
   ExceptionDec,
   ExceptionIncl,
   ExceptionExcl,
   ExceptionShift,
   ExceptionRotate,
   ExceptionStaticArray,
   ExceptionDynamicArray,
   ExceptionForLoopBegin,
   ExceptionForLoopTo,
   ExceptionForLoopEnd,
   ExceptionPointerNil,
   ExceptionNoReturn,
   ExceptionCase,
   ExceptionNonPosDiv,
   ExceptionNonPosMod,
   ExceptionZeroDiv,
   ExceptionZeroRem,
   ExceptionWholeValue,
   ExceptionRealValue,
   ExceptionParameterBounds,
   ExceptionNo             : CARDINAL ;


(*
   InitBase - initializes the base types and functions
              used in the Modula-2 compiler.
*)

PROCEDURE InitBase (location: location_t; VAR sym: CARDINAL) ;


(*
   GetBaseTypeMinMax - returns the minimum and maximum values for a
                       given base type.  This procedure should only
                       be called if the type is NOT a subrange.
*)

PROCEDURE GetBaseTypeMinMax (type: CARDINAL; VAR min, max: CARDINAL) ;


(*
   IsPseudoBaseFunction - returns true if Sym is a Base function.
*)

PROCEDURE IsPseudoBaseFunction (Sym: CARDINAL) : BOOLEAN ;


(*
   IsPseudoBaseProcedure - returns true if Sym is a Base procedure.
*)

PROCEDURE IsPseudoBaseProcedure (Sym: CARDINAL) : BOOLEAN ;


(*
   IsNeededAtRunTime - returns TRUE if procedure, sym, is a
                       runtime procedure. Ie a procedure which is
                       not a pseudo procedure and which is implemented
                       in M2RTS or SYSTEM and also exported.
*)

PROCEDURE IsNeededAtRunTime (tok: CARDINAL; sym: CARDINAL) : BOOLEAN ;


(*
   IsBaseType - returns TRUE if Sym is a Base type.
*)

PROCEDURE IsBaseType (Sym: CARDINAL) : BOOLEAN ;


(*
   IsOrdinalType - returns TRUE if, sym, is an ordinal type.
                   An ordinal type is defined as:
                   a base type which contains whole numbers or
                   a subrange type or an enumeration type.
*)

PROCEDURE IsOrdinalType (Sym: CARDINAL) : BOOLEAN ;


(*
   IsOrd - returns TRUE if, sym, is ORD or its typed counterparts
           ORDL, ORDS.
*)

PROCEDURE IsOrd (sym: CARDINAL) : BOOLEAN ;


(*
   IsTrunc - returns TRUE if, sym, is TRUNC or its typed counterparts
             TRUNCL, TRUNCS.
*)

PROCEDURE IsTrunc (sym: CARDINAL) : BOOLEAN ;


(*
   IsFloat - returns TRUE if, sym, is FLOAT or its typed counterparts
             FLOATL, FLOATS.
*)

PROCEDURE IsFloat (sym: CARDINAL) : BOOLEAN ;


(*
   IsInt - returns TRUE if, sym, is INT or its typed counterparts
           INTL, INTS.
*)

PROCEDURE IsInt (sym: CARDINAL) : BOOLEAN ;


(*
   AssignmentRequiresWarning - returns TRUE if t1 and t2 can be used during
                               an assignment, but should generate a warning.
                               For example in PIM we can assign ADDRESS
                               and WORD providing they are both the
                               same size.
*)

PROCEDURE AssignmentRequiresWarning (t1, t2: CARDINAL) : BOOLEAN ;


(*
   IsAssignmentCompatible - returns TRUE if t1 and t2 are assignment
                            compatible.
*)

PROCEDURE IsAssignmentCompatible (t1, t2: CARDINAL) : BOOLEAN ;


(*
   IsExpressionCompatible - returns TRUE if t1 and t2 are expression
                            compatible.
*)

PROCEDURE IsExpressionCompatible (t1, t2: CARDINAL) : BOOLEAN ;


(*
   IsParameterCompatible - returns TRUE if types t1 and t2 are parameter
                           compatible.
*)

PROCEDURE IsParameterCompatible (t1, t2: CARDINAL) : BOOLEAN ;


(*
   IsComparisonCompatible - returns TRUE if t1 and t2 are comparison
                            compatible.  PIM allows INTEGER and ADDRESS within
                            expressions but we warn against their comparison.
*)

PROCEDURE IsComparisonCompatible (t1, t2: CARDINAL) : BOOLEAN ;


(*
   IsValidParameter - returns TRUE if an, actual, parameter can be passed
                      to the, formal, parameter.   This differs from
                      IsParameterCompatible as this procedure includes checks
                      for unbounded formal parameters, var parameters and
                      constant actual parameters.
*)

PROCEDURE IsValidParameter (formal, actual: CARDINAL) : BOOLEAN ;


(*
   CheckExpressionCompatible - returns if t1 and t2 are compatible types for
                               +, -, *, DIV, >, <, =, etc.
                               If t1 and t2 are not compatible then an error
                               message is displayed.
*)

PROCEDURE CheckExpressionCompatible (tok: CARDINAL;
                                     left, right: CARDINAL) ;


(*
   CheckAssignmentCompatible - returns if t1 and t2 are compatible types for
                               :=, =, #.
                               If t1 and t2 are not compatible then an error
                               message is displayed.
*)

PROCEDURE CheckAssignmentCompatible (tok: CARDINAL;
                                     left, right: CARDINAL) ;


(*
   CheckParameterCompatible - checks to see if types, t1, and, t2, are
                              compatible for parameter passing.
*)

PROCEDURE CheckParameterCompatible (tok: CARDINAL;
                                    t1, t2: CARDINAL) ;


(*
   CannotCheckTypeInPass3 - returns TRUE if we are unable to check the
                            type of, e, in pass 3.
*)

PROCEDURE CannotCheckTypeInPass3 (e: CARDINAL) : BOOLEAN ;


(*
   MixTypes - given types leftType and rightType return a type symbol that
              provides expression type compatibility.
              NearTok is used to identify the source position if a type
              incompatability occurs.
*)

PROCEDURE MixTypes (leftType, rightType: CARDINAL; NearTok: CARDINAL) : CARDINAL ;


(*
   MixTypesDecl - returns a type symbol which provides expression compatibility
                  between leftType and rightType.  An error is emitted if this
                  is not possible.  left and right are the source (variable,
                  constant) of leftType and rightType respectively.
*)

PROCEDURE MixTypesDecl (left, right, leftType, rightType: CARDINAL;
                        NearTok: CARDINAL) : CARDINAL ;


(*
   NegateType - if the type is unsigned then returns the
                signed equivalent.
*)

PROCEDURE NegateType (type: CARDINAL (* ; sympos: CARDINAL *) ) : CARDINAL ;


(*
   IsMathType - returns TRUE if the type is a mathematical type.
                A mathematical type has a range larger than INTEGER.
                (Typically REAL/LONGREAL/LONGINT)
*)

PROCEDURE IsMathType (type: CARDINAL) : BOOLEAN ;


(*
   IsRealType - returns TRUE if, t, is a real type.
*)

PROCEDURE IsRealType (t: CARDINAL) : BOOLEAN ;


(*
   IsComplexType - returns TRUE if, sym, is COMPLEX,
                   LONGCOMPLEX or SHORTCOMPLEX.
*)

PROCEDURE IsComplexType (sym: CARDINAL) : BOOLEAN ;


(*
   ComplexToScalar - returns the scalar (or base type) of the complex type, sym.
*)

PROCEDURE ComplexToScalar (sym: CARDINAL) : CARDINAL ;


(*
   ScalarToComplex - given a real type, t, return the equivalent complex type.
*)

PROCEDURE ScalarToComplex (sym: CARDINAL) : CARDINAL ;


(*
   GetCmplxReturnType - this code implements the table given in the
                        ISO standard Page 293 with an addition for
                        SHORTCOMPLEX and the fixed sized COMPLEX
                        types found in the GNU Modula-2 SYSTEM
                        Module.
*)

PROCEDURE GetCmplxReturnType (t1, t2: CARDINAL) : CARDINAL ;


END M2Base.