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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
(* M2System.mod defines the SYSTEM builtin 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/>. *)
IMPLEMENTATION MODULE M2System ;
(*
Title : M2System
Author : Gaius Mulley
System : UNIX (gm2)
Date : Mon Jul 10 20:24:31 2000
Description: gcc version of M2System. It defines the builtin types within the
SYSTEM.def module. Remember that these modules (SYSTEM.def, SYSTEM.mod)
really exist, but not all type definitions are expressed in this file.
We also need to tell the compiler the size of the data types.
*)
FROM SymbolTable IMPORT NulSym,
StartScope,
EndScope,
MakeConstLit,
MakeConstVar,
MakePointer,
MakeType,
MakeProcedure,
MakeSet,
MakeSubrange,
PutFunction,
PutType, PutPointer,
PutSet, PutVar,
PutSubrange,
PutExportQualified,
PutProcedureNoReturn,
GetSym, GetSymName,
GetCurrentModule, SetCurrentModule,
IsLegal, ProcedureKind,
PopValue,
PopSize ;
FROM Assertion IMPORT Assert ;
FROM M2LexBuf IMPORT BuiltinTokenNo ;
FROM M2Options IMPORT Iso, Pim2, Pedantic, DumpSystemExports ;
FROM NameKey IMPORT Name, MakeKey, NulName ;
FROM M2Batch IMPORT MakeDefinitionSource ;
FROM M2Base IMPORT Cardinal, ZType ;
FROM M2Size IMPORT Size, MakeSize ;
FROM M2ALU IMPORT PushCard, PushIntegerTree, PushRealTree, DivTrunc ;
FROM M2Error IMPORT InternalError ;
FROM Lists IMPORT List, InitList, IsItemInList, PutItemIntoList, GetItemFromList, NoOfItemsInList ;
FROM SymbolKey IMPORT SymbolTree, InitTree, GetSymKey, PutSymKey ;
FROM StrLib IMPORT StrEqual ;
FROM M2Printf IMPORT printf1 ;
FROM SymbolConversion IMPORT Mod2Gcc ;
FROM M2Base IMPORT Real, Cardinal, Integer, Complex,
LongReal, LongCard, LongInt, LongComplex,
ShortReal, ShortCard, ShortInt, ShortComplex ;
FROM gcctypes IMPORT tree ;
FROM m2linemap IMPORT BuiltinsLocation ;
FROM m2decl IMPORT GetBitsPerBitset, GetBitsPerUnit ;
FROM m2type IMPORT GetMaxFrom, GetMinFrom,
GetWordType, GetPointerType, GetByteType, GetISOLocType,
GetM2Integer8, GetM2Integer16, GetM2Integer32, GetM2Integer64,
GetM2Cardinal8, GetM2Cardinal16, GetM2Cardinal32, GetM2Cardinal64,
GetM2Word16, GetM2Word32, GetM2Word64,
GetM2Bitset8, GetM2Bitset16, GetM2Bitset32,
GetM2Real32, GetM2Real64, GetM2Real96, GetM2Real128,
GetM2Complex32, GetM2Complex64, GetM2Complex96, GetM2Complex128,
GetBitsetType, GetISOByteType, GetISOWordType,
GetCSizeTType, GetCSSizeTType, GetCOffTType,
InitSystemTypes ;
FROM m2expr IMPORT BuildSize, GetSizeOf, AreConstantsEqual ;
TYPE
IsP = PROCEDURE (CARDINAL) : BOOLEAN ;
VAR
MinValues,
MaxValues : SymbolTree ;
SystemTypes: List ;
(*
Init -
*)
PROCEDURE Init ;
BEGIN
InitList(SystemTypes) ;
InitTree(MinValues) ;
InitTree(MaxValues)
END Init ;
(*
CreateMinMaxFor - creates the min and max values for type given gccType.
*)
PROCEDURE CreateMinMaxFor (type: CARDINAL; min, max: ARRAY OF CHAR;
gccType: tree; realtype: BOOLEAN) ;
VAR
maxval, minval: CARDINAL ;
BEGIN
maxval := MakeConstVar (BuiltinTokenNo, MakeKey(max)) ;
IF realtype
THEN
PushRealTree (GetMaxFrom (BuiltinsLocation (), gccType))
ELSE
PushIntegerTree (GetMaxFrom (BuiltinsLocation (), gccType))
END ;
PopValue (maxval) ;
PutVar (maxval, type) ;
PutSymKey (MaxValues, GetSymName (type), maxval) ;
minval := MakeConstVar (BuiltinTokenNo, MakeKey(min)) ;
IF realtype
THEN
PushRealTree (GetMinFrom (BuiltinsLocation (), gccType))
ELSE
PushIntegerTree (GetMinFrom (BuiltinsLocation (), gccType))
END ;
PopValue (minval) ;
PutVar (minval, type) ;
PutSymKey (MinValues, GetSymName (type), minval)
END CreateMinMaxFor ;
(*
MapType - create a mapping of the M2 frontend type to gcctype.
*)
PROCEDURE MapType (type: CARDINAL;
name, min, max: ARRAY OF CHAR;
needsExporting: BOOLEAN;
gcctype: tree; realtype: BOOLEAN) ;
VAR
n: Name ;
BEGIN
PushIntegerTree (BuildSize (BuiltinsLocation (), gcctype, FALSE)) ;
PopSize (type) ;
IF IsItemInList (SystemTypes, type)
THEN
InternalError ('not expecting system type to already be declared')
END ;
PutItemIntoList (SystemTypes, type) ;
(* Create min, max constants if type is ordinal or a floating point type. *)
IF (NOT StrEqual (min, '')) AND (NOT StrEqual (max, ''))
THEN
CreateMinMaxFor (type, min, max, gcctype, realtype)
END ;
IF needsExporting AND DumpSystemExports
THEN
n := GetSymName (type) ;
printf1('SYSTEM module creates type: %a\n', n)
END
END MapType ;
(*
CreateType - create and return a frontend type which matches the GCC tree type.
*)
PROCEDURE CreateType (name, min, max: ARRAY OF CHAR;
needsExporting: BOOLEAN; gccType: tree;
realtype: BOOLEAN) : CARDINAL ;
VAR
type: CARDINAL ;
BEGIN
IF gccType=NIL
THEN
(* GCC backend does not support this type. *)
RETURN NulSym
ELSE
(* Create base type. *)
type := MakeType (BuiltinTokenNo, MakeKey (name)) ;
PutType (type, NulSym) ; (* a Base Type *)
MapType (type, name, min, max, needsExporting, gccType, realtype) ;
RETURN type
END
END CreateType ;
(*
AttemptToCreateType - attempts to create a frontend type which matches the
GCC tree type.
*)
PROCEDURE AttemptToCreateType (name, min, max: ARRAY OF CHAR;
needsExporting: BOOLEAN; gccType: tree;
realtype: BOOLEAN) ;
BEGIN
Assert (IsLegal (CreateType (name, min, max, needsExporting,
gccType, realtype)))
END AttemptToCreateType ;
(*
CreateSetType - creates and returns a, SET OF [0..highBit], type.
It maps this type onto the GCC type.
*)
PROCEDURE CreateSetType (name, highBit: ARRAY OF CHAR;
needsExporting: BOOLEAN; gccType: tree) : CARDINAL ;
VAR
low,
high,
subrange,
type : CARDINAL ;
BEGIN
IF gccType=NIL
THEN
(* GCC backend does not support this type *)
RETURN NulSym
ELSE
(* create base type *)
type := MakeSet (BuiltinTokenNo, MakeKey (name)) ;
low := MakeConstLit (BuiltinTokenNo, MakeKey ('0'), Cardinal) ;
high := MakeConstLit (BuiltinTokenNo, MakeKey (highBit), Cardinal) ;
subrange := MakeSubrange (BuiltinTokenNo, NulName) ;
PutSubrange (subrange, low, high, Cardinal) ;
PutSet (type, subrange, FALSE) ;
MapType (type, name, '', '', needsExporting, gccType, FALSE) ;
RETURN type
END
END CreateSetType ;
(*
AttemptToCreateSetType - creates and returns a, SET OF [0..highBit], type.
It maps this type onto the GCC type.
*)
PROCEDURE AttemptToCreateSetType (name, highBit: ARRAY OF CHAR;
needsExporting: BOOLEAN; gccType: tree) ;
BEGIN
Assert (IsLegal (CreateSetType (name, highBit, needsExporting, gccType)))
END AttemptToCreateSetType ;
(*
MakeFixedSizedTypes - creates the SYSTEM fixed sized types providing the
gcc backend supports them.
*)
PROCEDURE MakeFixedSizedTypes ;
BEGIN
AttemptToCreateType ('INTEGER8', 'MinInteger8', 'MaxInteger8', TRUE, GetM2Integer8 (), FALSE) ;
AttemptToCreateType ('INTEGER16', 'MinInteger16', 'MaxInteger16', TRUE, GetM2Integer16 (), FALSE) ;
AttemptToCreateType ('INTEGER32', 'MinInteger32', 'MaxInteger32', TRUE, GetM2Integer32 (), FALSE) ;
AttemptToCreateType ('INTEGER64', 'MinInteger64', 'MaxInteger64', TRUE, GetM2Integer64 (), FALSE) ;
AttemptToCreateType ('CARDINAL8', 'MinCardinal8', 'MaxCardinal8', TRUE, GetM2Cardinal8 (), FALSE) ;
AttemptToCreateType ('CARDINAL16', 'MinCardinal16', 'MaxCardinal16', TRUE, GetM2Cardinal16 (), FALSE) ;
AttemptToCreateType ('CARDINAL32', 'MinCardinal32', 'MaxCardinal32', TRUE, GetM2Cardinal32 (), FALSE) ;
AttemptToCreateType ('CARDINAL64', 'MinCardinal64', 'MaxCardinal64', TRUE, GetM2Cardinal64 (), FALSE) ;
AttemptToCreateType ('WORD16', '', '', TRUE, GetM2Word16 (), FALSE) ;
AttemptToCreateType ('WORD32', '', '', TRUE, GetM2Word32 (), FALSE) ;
AttemptToCreateType ('WORD64', '', '', TRUE, GetM2Word64 (), FALSE) ;
AttemptToCreateSetType ('BITSET8' , '7' , TRUE, GetM2Bitset8 ()) ;
AttemptToCreateSetType ('BITSET16', '15', TRUE, GetM2Bitset16 ()) ;
AttemptToCreateSetType ('BITSET32', '31', TRUE, GetM2Bitset32 ()) ;
AttemptToCreateType ('REAL32', 'MinReal32', 'MaxReal32', TRUE, GetM2Real32 (), TRUE) ;
AttemptToCreateType ('REAL64', 'MinReal64', 'MaxReal64', TRUE, GetM2Real64 (), TRUE) ;
AttemptToCreateType ('REAL96', 'MinReal96', 'MaxReal96', TRUE, GetM2Real96 (), TRUE) ;
AttemptToCreateType ('REAL128', 'MinReal128', 'MaxReal128', TRUE, GetM2Real128 (), TRUE) ;
AttemptToCreateType ('COMPLEX32', '', '', TRUE, GetM2Complex32 (), TRUE) ;
AttemptToCreateType ('COMPLEX64', '', '', TRUE, GetM2Complex64 (), TRUE) ;
AttemptToCreateType ('COMPLEX96', '', '', TRUE, GetM2Complex96 (), TRUE) ;
AttemptToCreateType ('COMPLEX128', '', '', TRUE, GetM2Complex128 (), TRUE)
END MakeFixedSizedTypes ;
(*
InitPIMTypes -
*)
PROCEDURE InitPIMTypes ;
BEGIN
Loc := CreateType ('LOC', '', '', TRUE, GetISOLocType(), FALSE) ;
InitSystemTypes(BuiltinsLocation(), Loc) ;
Word := CreateType ('WORD', '', '', TRUE, GetWordType(), FALSE) ;
Byte := CreateType ('BYTE', '', '', TRUE, GetByteType(), FALSE) ;
(* ADDRESS = POINTER TO BYTE *)
Address := MakePointer (BuiltinTokenNo, MakeKey('ADDRESS')) ;
PutPointer (Address, Byte) ; (* Base Type *)
MapType (Address, 'ADDRESS', '', '', TRUE, GetPointerType(), FALSE)
END InitPIMTypes ;
(*
InitISOTypes -
*)
PROCEDURE InitISOTypes ;
BEGIN
Loc := CreateType ('LOC', 'MinLoc', 'MaxLoc', TRUE, GetISOLocType (), FALSE) ;
InitSystemTypes (BuiltinsLocation (), Loc) ;
Address := MakePointer (BuiltinTokenNo, MakeKey ('ADDRESS')) ;
PutPointer (Address, Loc) ; (* Base Type *)
MapType (Address, 'ADDRESS', '', '', TRUE, GetPointerType(), FALSE) ;
Byte := CreateType ('BYTE', '', '', TRUE, GetISOByteType(), FALSE) ;
Word := CreateType ('WORD', '', '', TRUE, GetISOWordType(), FALSE) ;
END InitISOTypes ;
(*
MakeExtraSystemTypes - create any extra system types required
for portability.
*)
PROCEDURE MakeExtraSystemTypes ;
BEGIN
CSizeT := CreateType ('CSIZE_T' , '', '', TRUE, GetCSizeTType (), FALSE) ;
CSSizeT := CreateType ('CSSIZE_T', '', '', TRUE, GetCSSizeTType (), FALSE) ;
COffT := CreateType ('COFF_T', '', '', TRUE, GetCOffTType (), FALSE)
END MakeExtraSystemTypes ;
(*
InitSystem - creates the system dependant types and procedures.
Note that they are not exported here, but they are
exported in the textual module: SYSTEM.def.
We build our system types from those given in the gcc
backend. Essentially we perform double book keeping.
*)
PROCEDURE InitSystem ;
VAR
Previous: CARDINAL ;
BEGIN
Init ;
(* create SYSTEM module *)
System := MakeDefinitionSource(BuiltinTokenNo, MakeKey('SYSTEM')) ;
StartScope(System) ;
Previous := GetCurrentModule() ;
SetCurrentModule(System) ;
IF Iso
THEN
InitISOTypes ;
MakeSize ;
PutExportQualified(BuiltinTokenNo, MakeKey('SIZE'))
ELSE
InitPIMTypes ;
(* SIZE is declared in SYSTEM.def in PIM-2 but not PIM-[34] *)
IF Pedantic
THEN
IF Pim2
THEN
MakeSize ;
PutExportQualified(BuiltinTokenNo, MakeKey('SIZE'))
END
ELSE
MakeSize ;
PutExportQualified(BuiltinTokenNo, MakeKey('SIZE'))
END
END ;
(* The predefined pseudo functions. *)
Adr := MakeProcedure(BuiltinTokenNo,
MakeKey('ADR')) ; (* Function *)
PutFunction (BuiltinTokenNo, Adr, DefProcedure, Address) ;
(* Return Type *)
(* Address *)
TSize := MakeProcedure(BuiltinTokenNo,
MakeKey('TSIZE')) ; (* Function *)
PutFunction (BuiltinTokenNo, TSize, DefProcedure, ZType) ;
(* Return Type *)
(* ZType *)
TBitSize := MakeProcedure(BuiltinTokenNo,
MakeKey('TBITSIZE')) ; (* GNU extension *)
(* Function *)
PutFunction (BuiltinTokenNo, TBitSize, DefProcedure, ZType) ;
(* Return Type *)
(* ZType *)
(* The ISO specific predefined pseudo functions. *)
AddAdr := MakeProcedure(BuiltinTokenNo,
MakeKey('ADDADR')) ; (* Function *)
PutFunction (BuiltinTokenNo, AddAdr, DefProcedure, Address) ;
(* Return Type *)
SubAdr := MakeProcedure(BuiltinTokenNo,
MakeKey('SUBADR')) ; (* Function *)
PutFunction (BuiltinTokenNo, SubAdr, DefProcedure, Address) ;
(* Return Type *)
DifAdr := MakeProcedure (BuiltinTokenNo,
MakeKey ('DIFADR')) ; (* Function *)
PutFunction (BuiltinTokenNo, DifAdr, DefProcedure, Address) ;
(* Return Type *)
MakeAdr := MakeProcedure (BuiltinTokenNo,
MakeKey ('MAKEADR')) ; (* Function *)
PutFunction (BuiltinTokenNo, MakeAdr, DefProcedure, Address) ;
(* Return Type *)
(* The return value for ROTATE, SHIFT and CAST is the
same as the first parameter and is faked in M2Quads. *)
Rotate := MakeProcedure(BuiltinTokenNo,
MakeKey('ROTATE')) ; (* Function *)
Shift := MakeProcedure(BuiltinTokenNo,
MakeKey('SHIFT')) ; (* Function *)
Cast := MakeProcedure(BuiltinTokenNo,
MakeKey('CAST')) ; (* Function *)
Throw := MakeProcedure(BuiltinTokenNo,
MakeKey('THROW')) ; (* Procedure *)
PutProcedureNoReturn (Throw, DefProcedure, TRUE) ;
CreateMinMaxFor(Word, 'MinWord', 'MaxWord', GetWordType(), FALSE) ;
CreateMinMaxFor(Address, 'MinAddress', 'MaxAddress', GetPointerType(), FALSE) ;
CreateMinMaxFor(Byte, 'MinByte', 'MaxByte', GetByteType(), FALSE) ;
MakeFixedSizedTypes ;
MakeExtraSystemTypes ;
EndScope ;
SetCurrentModule(Previous)
END InitSystem ;
(*
GetSystemTypeMinMax - returns the minimum and maximum values for a given system type.
*)
PROCEDURE GetSystemTypeMinMax (type: CARDINAL; VAR min, max: CARDINAL) ;
BEGIN
IF IsItemInList(SystemTypes, type)
THEN
min := GetSymKey(MinValues, GetSymName(type)) ;
max := GetSymKey(MaxValues, GetSymName(type))
ELSE
InternalError ('system does not know about this type')
END
END GetSystemTypeMinMax ;
(*
IsISOPseudoSystemFunction -
*)
PROCEDURE IsISOPseudoSystemFunction (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN Iso AND ((sym=AddAdr) OR (sym=SubAdr) OR (sym=DifAdr) OR
(sym=MakeAdr) OR (sym=Rotate) OR (sym=Shift) OR
(sym=Cast))
END IsISOPseudoSystemFunction ;
(*
IsPIMPseudoSystemFunction - returns TRUE if sym is specifically a PIM
system function.
*)
PROCEDURE IsPIMPseudoSystemFunction (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN (NOT Iso) AND ((sym=Size) OR (sym=Shift) OR (sym=Rotate))
END IsPIMPseudoSystemFunction ;
(*
IsPseudoSystemFunction - returns true if sym is a SYSTEM pseudo function.
*)
PROCEDURE IsPseudoSystemFunction (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN( (sym=Adr) OR (sym=TSize) OR (sym=TBitSize) OR
IsPIMPseudoSystemFunction(sym) OR
IsISOPseudoSystemFunction(sym) )
END IsPseudoSystemFunction ;
(*
IsPseudoSystemFunctionConstExpression - returns TRUE if this procedure
is legal in a constant expression.
*)
PROCEDURE IsPseudoSystemFunctionConstExpression (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym=Size) OR (sym=TSize) OR (sym=Rotate) OR (sym=Shift) OR
(Iso AND ((sym=Cast) OR (sym=MakeAdr)))
)
END IsPseudoSystemFunctionConstExpression ;
(*
IsPseudoSystemProcedure - returns true if sym is a SYSTEM pseudo procedure.
*)
PROCEDURE IsPseudoSystemProcedure (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN( sym=Throw )
END IsPseudoSystemProcedure ;
(*
IsSystemType - returns TRUE if sym is a SYSTEM (inbuilt) type.
It does not search your SYSTEM implementation module.
*)
PROCEDURE IsSystemType (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN( IsItemInList(SystemTypes, sym) )
END IsSystemType ;
(*
GetSafeSystem -
*)
PROCEDURE GetSafeSystem (name: Name) : CARDINAL ;
VAR
sym,
i, n: CARDINAL ;
BEGIN
n := NoOfItemsInList(SystemTypes) ;
i := 1 ;
WHILE i<=n DO
sym := GetItemFromList(SystemTypes, i) ;
IF GetSymName(sym)=name
THEN
RETURN( sym )
END ;
INC(i)
END ;
RETURN( NulSym )
END GetSafeSystem ;
(*
IntegerN - returns the symbol associated with INTEGER[N].
NulSym is returned if the type does not exist.
*)
PROCEDURE IntegerN (bitlength: CARDINAL) : CARDINAL ;
BEGIN
CASE bitlength OF
8 : RETURN( GetSafeSystem(MakeKey('INTEGER8')) ) |
16: RETURN( GetSafeSystem(MakeKey('INTEGER16')) ) |
32: RETURN( GetSafeSystem(MakeKey('INTEGER32')) ) |
64: RETURN( GetSafeSystem(MakeKey('INTEGER64')) )
ELSE
InternalError ('system does not know about this type')
END
END IntegerN ;
(*
CardinalN - returns the symbol associated with CARDINAL[N].
NulSym is returned if the type does not exist.
*)
PROCEDURE CardinalN (bitlength: CARDINAL) : CARDINAL ;
BEGIN
CASE bitlength OF
8 : RETURN( GetSafeSystem(MakeKey('CARDINAL8')) ) |
16: RETURN( GetSafeSystem(MakeKey('CARDINAL16')) ) |
32: RETURN( GetSafeSystem(MakeKey('CARDINAL32')) ) |
64: RETURN( GetSafeSystem(MakeKey('CARDINAL64')) )
ELSE
InternalError ('system does not know about this type')
END
END CardinalN ;
(*
WordN - returns the symbol associated with WORD[N].
NulSym is returned if the type does not exist.
*)
PROCEDURE WordN (bitlength: CARDINAL) : CARDINAL ;
BEGIN
CASE bitlength OF
16: RETURN( GetSafeSystem(MakeKey('WORD16')) ) |
32: RETURN( GetSafeSystem(MakeKey('WORD32')) ) |
64: RETURN( GetSafeSystem(MakeKey('WORD64')) )
ELSE
InternalError ('system does not know about this type')
END
END WordN ;
(*
SetN - returns the symbol associated with SET[N].
NulSym is returned if the type does not exist.
*)
PROCEDURE SetN (bitlength: CARDINAL) : CARDINAL ;
BEGIN
CASE bitlength OF
8 : RETURN( GetSafeSystem(MakeKey('BITSET8')) ) |
16: RETURN( GetSafeSystem(MakeKey('BITSET16')) ) |
32: RETURN( GetSafeSystem(MakeKey('BITSET32')) )
ELSE
InternalError ('system does not know about this type')
END
END SetN ;
(*
RealN - returns the symbol associated with REAL[N].
NulSym is returned if the type does not exist.
*)
PROCEDURE RealN (bitlength: CARDINAL) : CARDINAL ;
BEGIN
CASE bitlength OF
32 : RETURN( GetSafeSystem(MakeKey('REAL32')) ) |
64 : RETURN( GetSafeSystem(MakeKey('REAL64')) ) |
96 : RETURN( GetSafeSystem(MakeKey('REAL96')) ) |
128: RETURN( GetSafeSystem(MakeKey('REAL128')) )
ELSE
InternalError ('system does not know about this type')
END
END RealN ;
(*
ComplexN - returns the symbol associated with COMPLEX[N].
NulSym is returned if the type does not exist.
*)
PROCEDURE ComplexN (bitlength: CARDINAL) : CARDINAL ;
BEGIN
CASE bitlength OF
32 : RETURN( GetSafeSystem(MakeKey('COMPLEX32')) ) |
64 : RETURN( GetSafeSystem(MakeKey('COMPLEX64')) ) |
96 : RETURN( GetSafeSystem(MakeKey('COMPLEX96')) ) |
128: RETURN( GetSafeSystem(MakeKey('COMPLEX128')) )
ELSE
InternalError ('system does not know about this type')
END
END ComplexN ;
(*
IsIntegerN - returns the TRUE if, sym, is one of the SYSTEM
INTEGER types (not the base INTEGER type).
*)
PROCEDURE IsIntegerN (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
((sym=IntegerN(8)) OR (sym=IntegerN(16)) OR
(sym=IntegerN(32)) OR (sym=IntegerN(64)))
)
END IsIntegerN ;
(*
IsCardinalN - returns the TRUE if, sym, is one of the SYSTEM
CARDINAL types (not the base CARDINAL type).
*)
PROCEDURE IsCardinalN (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
((sym=CardinalN(8)) OR (sym=CardinalN(16)) OR
(sym=CardinalN(32)) OR (sym=CardinalN(64)))
)
END IsCardinalN ;
(*
IsWordN - returns the TRUE if, sym, is one of the SYSTEM
WORD[n] types (not the default SYSTEM WORD type).
*)
PROCEDURE IsWordN (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
((sym=WordN(16)) OR
(sym=WordN(32)) OR (sym=WordN(64)))
)
END IsWordN ;
(*
IsSetN - returns the TRUE if, sym, is one of the SYSTEM
SET[n] types (not the default SYSTEM BITSET type).
*)
PROCEDURE IsSetN (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
((sym=SetN(8)) OR (sym=SetN(16)) OR (sym=SetN(32)))
)
END IsSetN ;
(*
IsRealN - returns the TRUE if, sym, is one of the SYSTEM
REAL[n] types (not the default base REAL type).
*)
PROCEDURE IsRealN (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
((sym=RealN(32)) OR (sym=RealN(64)) OR
(sym=RealN(96)) OR (sym=RealN(128)))
)
END IsRealN ;
(*
IsComplexN - returns the TRUE if, sym, is one of the SYSTEM
COMPLEX[n] types (not the default base COMPLEX,
LONGCOMPLEX or SHORTCOMPLEX types).
*)
PROCEDURE IsComplexN (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
((sym=ComplexN(32)) OR (sym=ComplexN(64)) OR
(sym=ComplexN(96)) OR (sym=ComplexN(128)))
)
END IsComplexN ;
(*
IsGenericSystemType - returns TRUE if, sym, is of type
BYTE, WORD or any other length.
*)
PROCEDURE IsGenericSystemType (sym: CARDINAL) : BOOLEAN ;
BEGIN
RETURN(
(sym#NulSym) AND
(IsWordN(sym) OR (sym=Word) OR (sym=Byte) OR (sym=Loc))
)
END IsGenericSystemType ;
(*
IsSameSize - return TRUE if SIZE(a)=SIZE(b)
*)
PROCEDURE IsSameSize (a, b: CARDINAL) : BOOLEAN ;
BEGIN
RETURN( AreConstantsEqual(BuildSize(BuiltinsLocation(), Mod2Gcc(a), FALSE),
BuildSize(BuiltinsLocation(), Mod2Gcc(b), FALSE)) )
END IsSameSize ;
(*
IsSameType - returns TRUE if, t, is the same type as a or b
and a or b are a type, p.
*)
PROCEDURE IsSameType (t: CARDINAL; p: IsP; a, b: CARDINAL) : BOOLEAN ;
BEGIN
IF t=a
THEN
RETURN( p(b) AND IsSameSize(a, b) )
ELSIF t=b
THEN
RETURN( p(a) AND IsSameSize(a, b) )
ELSE
RETURN( FALSE )
END
END IsSameType ;
(*
IsSameSizePervasiveType - returns TRUE if a or b are CARDINAL, INTEGER, REAL,
LONGREAL, SHORTREAL and the other type is the same
size and of the same type.
*)
PROCEDURE IsSameSizePervasiveType (a, b: CARDINAL) : BOOLEAN ;
BEGIN
RETURN( IsSameType(Integer, IsIntegerN, a, b) OR
IsSameType(Cardinal, IsCardinalN, a, b) OR
IsSameType(Word, IsWordN, a, b) OR
IsSameType(Real, IsRealN, a, b) OR
IsSameType(Complex, IsComplexN, a, b) OR
IsSameType(LongInt, IsIntegerN, a, b) OR
IsSameType(LongCard, IsCardinalN, a, b) OR
IsSameType(LongComplex, IsComplexN, a, b) OR
IsSameType(LongReal, IsRealN, a, b) OR
IsSameType(ShortInt, IsIntegerN, a, b) OR
IsSameType(ShortCard, IsCardinalN, a, b) OR
IsSameType(ShortComplex, IsComplexN, a, b) OR
IsSameType(ShortReal, IsRealN, a, b) )
END IsSameSizePervasiveType ;
END M2System.
|