Debian Codegraph @

gcc/m2/gm2-compiler/M2Bitset.mod

raw
1 (* M2Bitset.mod provides the BITSET type.
2
3 Copyright (C) 2003-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
21
22 IMPLEMENTATION MODULE M2Bitset ;
23
24
25 FROM M2Debug IMPORT Assert ;
26 FROM m2linemap IMPORT BuiltinsLocation ;
27 FROM m2type IMPORT GetWordType ;
28 FROM m2decl IMPORT GetBitsPerBitset ;
29 FROM m2expr IMPORT GetSizeOf ;
30 FROM M2ALU IMPORT PushCard, PushIntegerTree ;
31 FROM NameKey IMPORT MakeKey ;
32 FROM M2System IMPORT Word ;
33 FROM M2Base IMPORT Cardinal ;
34 FROM M2LexBuf IMPORT BuiltinTokenNo ;
35
36 FROM SymbolTable IMPORT NulSym,
37 MakeConstLit,
38 MakeConstVar,
39 MakeSet,
40 MakeSubrange,
41 PutSet,
42 PutSubrange,
43 PopValue,
44 PopSize ;
45
46
47 VAR
48 MinBitset, MaxBitset : CARDINAL ;
49
50
51 (*
52 MakeBitset - creates and declares the type BITSET.
53 *)
54
55 PROCEDURE MakeBitset ;
56 BEGIN
57 Bitset := MakeSet (BuiltinTokenNo, MakeKey('BITSET')) ; (* Base Type *)
58
59 (* MinBitset *)
60 MinBitset := MakeConstLit (BuiltinTokenNo, MakeKey('0'), Cardinal) ;
61
62 (* MaxBitset *)
63 MaxBitset := MakeConstVar (BuiltinTokenNo, MakeKey('MaxBitset')) ;
64 PushCard (GetBitsPerBitset()-1) ;
65 PopValue (MaxBitset) ;
66
67 Assert (Word#NulSym) ;
68 Bitnum := MakeSubrange (BuiltinTokenNo, MakeKey('BITNUM')) ;
69 PutSubrange (Bitnum, MinBitset, MaxBitset, Cardinal) ;
70 PutSet (Bitset, Bitnum, FALSE) ;
71
72 PushIntegerTree (GetSizeOf(BuiltinsLocation(), GetWordType())) ;
73 PopSize (Bitset)
74 END MakeBitset ;
75
76
77 (*
78 GetBitsetMinMax - assigns min and max to the minimum and maximum values of BITSET.
79 *)
80
81 PROCEDURE GetBitsetMinMax (VAR min, max: CARDINAL) ;
82 BEGIN
83 min := MinBitset ;
84 max := MaxBitset
85 END GetBitsetMinMax ;
86
87
88 END M2Bitset.