| 1 |
(* FifoQueue.mod provides a simple fifo queue. |
| 2 |
|
| 3 |
Copyright (C) 2001-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 FifoQueue ; |
| 23 |
|
| 24 |
FROM Lists IMPORT List, InitList, PutItemIntoList, GetItemFromList ; |
| 25 |
|
| 26 |
TYPE |
| 27 |
Fifo = RECORD |
| 28 |
Queue: List ; |
| 29 |
Out : CARDINAL ; |
| 30 |
END ; |
| 31 |
|
| 32 |
VAR |
| 33 |
const, |
| 34 |
subrange, |
| 35 |
enumeration, |
| 36 |
constructor: Fifo ; |
| 37 |
|
| 38 |
|
| 39 |
(* |
| 40 |
PutInto - places a CARDINAL number, c, into a fifo queue. |
| 41 |
*) |
| 42 |
|
| 43 |
PROCEDURE PutInto (VAR f: Fifo; c: CARDINAL) ; |
| 44 |
BEGIN |
| 45 |
WITH f DO |
| 46 |
PutItemIntoList(Queue, c) |
| 47 |
END |
| 48 |
END PutInto ; |
| 49 |
|
| 50 |
|
| 51 |
(* |
| 52 |
GetFrom - retrieves a CARDINAL number, c, from a fifo queue. |
| 53 |
*) |
| 54 |
|
| 55 |
PROCEDURE GetFrom (VAR f: Fifo; VAR c: CARDINAL) ; |
| 56 |
BEGIN |
| 57 |
WITH f DO |
| 58 |
INC(Out) ; |
| 59 |
c := GetItemFromList(Queue, Out) |
| 60 |
END |
| 61 |
END GetFrom ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
PutEnumerationIntoFifoQueue - places an enumeration symbol, c, |
| 66 |
into a fifo queue. |
| 67 |
*) |
| 68 |
|
| 69 |
PROCEDURE PutEnumerationIntoFifoQueue (c: CARDINAL) ; |
| 70 |
BEGIN |
| 71 |
PutInto(enumeration, c) |
| 72 |
END PutEnumerationIntoFifoQueue ; |
| 73 |
|
| 74 |
|
| 75 |
(* |
| 76 |
GetEnumerationFromFifoQueue - retrieves an enumeration symbol, |
| 77 |
c, from a fifo queue. |
| 78 |
*) |
| 79 |
|
| 80 |
PROCEDURE GetEnumerationFromFifoQueue (VAR c: CARDINAL) ; |
| 81 |
BEGIN |
| 82 |
GetFrom(enumeration, c) |
| 83 |
END GetEnumerationFromFifoQueue ; |
| 84 |
|
| 85 |
|
| 86 |
(* |
| 87 |
PutSubrangeIntoFifoQueue - places a subrange symbol into a fifo |
| 88 |
queue. |
| 89 |
*) |
| 90 |
|
| 91 |
PROCEDURE PutSubrangeIntoFifoQueue (c: CARDINAL) ; |
| 92 |
BEGIN |
| 93 |
PutInto(subrange, c) |
| 94 |
END PutSubrangeIntoFifoQueue ; |
| 95 |
|
| 96 |
|
| 97 |
(* |
| 98 |
GetSubrangeFromFifoQueue - retrieves a subrange symbol from a |
| 99 |
fifo queue. |
| 100 |
*) |
| 101 |
|
| 102 |
PROCEDURE GetSubrangeFromFifoQueue (VAR c: CARDINAL) ; |
| 103 |
BEGIN |
| 104 |
GetFrom(subrange, c) |
| 105 |
END GetSubrangeFromFifoQueue ; |
| 106 |
|
| 107 |
|
| 108 |
(* |
| 109 |
PutConstructorIntoFifoQueue - places a constructor symbol |
| 110 |
into a fifo queue. |
| 111 |
*) |
| 112 |
|
| 113 |
PROCEDURE PutConstructorIntoFifoQueue (c: CARDINAL) ; |
| 114 |
BEGIN |
| 115 |
PutInto(constructor, c) |
| 116 |
END PutConstructorIntoFifoQueue ; |
| 117 |
|
| 118 |
|
| 119 |
(* |
| 120 |
GetConstructorFromFifoQueue - retrieves a constructor symbol |
| 121 |
from a fifo queue. |
| 122 |
*) |
| 123 |
|
| 124 |
PROCEDURE GetConstructorFromFifoQueue (VAR c: CARDINAL) ; |
| 125 |
BEGIN |
| 126 |
GetFrom(constructor, c) |
| 127 |
END GetConstructorFromFifoQueue ; |
| 128 |
|
| 129 |
|
| 130 |
(* |
| 131 |
PutConstIntoFifoQueue - places a constant symbol |
| 132 |
into a fifo queue. |
| 133 |
*) |
| 134 |
|
| 135 |
PROCEDURE PutConstIntoFifoQueue (c: CARDINAL) ; |
| 136 |
BEGIN |
| 137 |
PutInto(const, c) |
| 138 |
END PutConstIntoFifoQueue ; |
| 139 |
|
| 140 |
|
| 141 |
(* |
| 142 |
GetConstFromFifoQueue - retrieves a const symbol |
| 143 |
from a fifo queue. |
| 144 |
*) |
| 145 |
|
| 146 |
PROCEDURE GetConstFromFifoQueue (VAR c: CARDINAL) ; |
| 147 |
BEGIN |
| 148 |
GetFrom(const, c) |
| 149 |
END GetConstFromFifoQueue ; |
| 150 |
|
| 151 |
|
| 152 |
(* |
| 153 |
Init - initialize the fifo queue. |
| 154 |
*) |
| 155 |
|
| 156 |
PROCEDURE Init (VAR f: Fifo) ; |
| 157 |
BEGIN |
| 158 |
WITH f DO |
| 159 |
InitList(Queue) ; |
| 160 |
Out := 0 |
| 161 |
END |
| 162 |
END Init ; |
| 163 |
|
| 164 |
|
| 165 |
BEGIN |
| 166 |
Init(const) ; |
| 167 |
Init(enumeration) ; |
| 168 |
Init(subrange) ; |
| 169 |
Init(constructor) |
| 170 |
END FifoQueue. |