1 (* M2Bitset.mod provides the BITSET type.
3 Copyright (C) 2003-2022 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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)
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.
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/>. *)
22 IMPLEMENTATION MODULE M2Bitset ;
25 FROM M2Debug IMPORT Assert ;
26 FROM m2tree IMPORT Tree ;
27 FROM m2linemap IMPORT BuiltinsLocation ;
28 FROM m2type IMPORT GetWordType ;
29 FROM m2decl IMPORT GetBitsPerBitset ;
30 FROM m2expr IMPORT GetSizeOf ;
31 FROM M2ALU IMPORT PushCard, PushIntegerTree ;
32 FROM NameKey IMPORT MakeKey ;
33 FROM M2System IMPORT Word ;
34 FROM M2Base IMPORT Cardinal ;
35 FROM M2LexBuf IMPORT BuiltinTokenNo ;
37 FROM SymbolTable IMPORT NulSym,
49 MinBitset, MaxBitset : CARDINAL ;
53 MakeBitset - creates and declares the type BITSET.
56 PROCEDURE MakeBitset ;
58 Bitset := MakeSet (BuiltinTokenNo, MakeKey('BITSET')) ; (* Base Type *)
61 MinBitset := MakeConstLit (BuiltinTokenNo, MakeKey('0'), Cardinal) ;
64 MaxBitset := MakeConstVar (BuiltinTokenNo, MakeKey('MaxBitset')) ;
65 PushCard (GetBitsPerBitset()-1) ;
66 PopValue (MaxBitset) ;
68 Assert (Word#NulSym) ;
69 Bitnum := MakeSubrange (BuiltinTokenNo, MakeKey('BITNUM')) ;
70 PutSubrange (Bitnum, MinBitset, MaxBitset, Cardinal) ;
71 PutSet (Bitset, Bitnum, FALSE) ;
73 PushIntegerTree (GetSizeOf(BuiltinsLocation(), GetWordType())) ;
79 GetBitsetMinMax - assigns min and max to the minimum and maximum values of BITSET.
82 PROCEDURE GetBitsetMinMax (VAR min, max: CARDINAL) ;