| 1 |
(* Library module defined by the International Standard |
| 2 |
Information technology - programming languages |
| 3 |
BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language. |
| 4 |
|
| 5 |
Copyright ISO/IEC (International Organization for Standardization |
| 6 |
and International Electrotechnical Commission) 1996-2021. |
| 7 |
|
| 8 |
It may be freely copied for the purpose of implementation (see page |
| 9 |
707 of the Information technology - Programming languages Part 1: |
| 10 |
Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *) |
| 11 |
|
| 12 |
DEFINITION MODULE SYSTEM; |
| 13 |
|
| 14 |
(* Gives access to system programming facilities that are probably |
| 15 |
non portable. *) |
| 16 |
|
| 17 |
(* The constants and types define underlying properties of storage *) |
| 18 |
|
| 19 |
EXPORT QUALIFIED BITSPERLOC, LOCSPERWORD, |
| 20 |
LOC, BYTE, WORD, ADDRESS, CSIZE_T, CSSIZE_T, COFF_T, (* @SYSTEM_DATATYPES@ *) |
| 21 |
ADDADR, SUBADR, DIFADR, MAKEADR, ADR, ROTATE, |
| 22 |
SHIFT, CAST, TSIZE, |
| 23 |
|
| 24 |
(* Internal GM2 compiler functions *) |
| 25 |
ShiftVal, ShiftLeft, ShiftRight, |
| 26 |
RotateVal, RotateLeft, RotateRight, |
| 27 |
THROW, TBITSIZE ; |
| 28 |
|
| 29 |
CONST |
| 30 |
(* <implementation-defined constant> ; *) |
| 31 |
BITSPERLOC = __ATTRIBUTE__ __BUILTIN__ ((BITS_PER_UNIT)) ; |
| 32 |
(* <implementation-defined constant> ; *) |
| 33 |
LOCSPERWORD = __ATTRIBUTE__ __BUILTIN__ ((UNITS_PER_WORD)) ; |
| 34 |
(* <implementation-defined constant> ; *) |
| 35 |
LOCSPERBYTE = 8 DIV BITSPERLOC ; |
| 36 |
|
| 37 |
(* Note that the full list of system and sized datatypes include: |
| 38 |
LOC, WORD, BYTE, ADDRESS, |
| 39 |
|
| 40 |
(and the non language standard target types) |
| 41 |
|
| 42 |
INTEGER8, INTEGER16, INTEGER32, INTEGER64, |
| 43 |
CARDINAL8, CARDINAL16, CARDINAL32, CARDINAL64, |
| 44 |
WORD16, WORD32, WORD64, BITSET8, BITSET16, |
| 45 |
BITSET32, REAL32, REAL64, REAL128, COMPLEX32, |
| 46 |
COMPLEX64, COMPLEX128, CSIZE_T, CSSIZE_T. |
| 47 |
|
| 48 |
Also note that the non-standard data types will |
| 49 |
move into another module in the future. *) |
| 50 |
|
| 51 |
(* |
| 52 |
All the data types and procedures below are declared internally. |
| 53 |
=============================================================== |
| 54 |
|
| 55 |
TYPE |
| 56 |
@SYSTEM_TYPES@ |
| 57 |
|
| 58 |
TYPE |
| 59 |
LOC; (* A system basic type. Values are the uninterpreted |
| 60 |
contents of the smallest addressable unit of storage *) |
| 61 |
ADDRESS = POINTER TO LOC; |
| 62 |
WORD = ARRAY [0 .. LOCSPERWORD-1] OF LOC; |
| 63 |
|
| 64 |
(* BYTE and LOCSPERBYTE are provided if appropriate for machine *) |
| 65 |
|
| 66 |
TYPE |
| 67 |
BYTE = ARRAY [0 .. LOCSPERBYTE-1] OF LOC; |
| 68 |
|
| 69 |
PROCEDURE ADDADR (addr: ADDRESS; offset: CARDINAL): ADDRESS; |
| 70 |
(* Returns address given by (addr + offset), or may raise |
| 71 |
an exception if this address is not valid. |
| 72 |
*) |
| 73 |
|
| 74 |
PROCEDURE SUBADR (addr: ADDRESS; offset: CARDINAL): ADDRESS; |
| 75 |
(* Returns address given by (addr - offset), or may raise an |
| 76 |
exception if this address is not valid. |
| 77 |
*) |
| 78 |
|
| 79 |
PROCEDURE DIFADR (addr1, addr2: ADDRESS): INTEGER; |
| 80 |
(* Returns the difference between addresses (addr1 - addr2), |
| 81 |
or may raise an exception if the arguments are invalid |
| 82 |
or address space is non-contiguous. |
| 83 |
*) |
| 84 |
|
| 85 |
PROCEDURE MAKEADR (high: <some type>; ...): ADDRESS; |
| 86 |
(* Returns an address constructed from a list of values whose |
| 87 |
types are implementation-defined, or may raise an |
| 88 |
exception if this address is not valid. |
| 89 |
|
| 90 |
In GNU Modula-2, MAKEADR can take any number of arguments |
| 91 |
which are mapped onto the type ADDRESS. The first parameter |
| 92 |
maps onto the high address bits and subsequent parameters map |
| 93 |
onto lower address bits. For example: |
| 94 |
|
| 95 |
a := MAKEADR(BYTE(0FEH), BYTE(0DCH), BYTE(0BAH), BYTE(098H), |
| 96 |
BYTE(076H), BYTE(054H), BYTE(032H), BYTE(010H)) ; |
| 97 |
|
| 98 |
then the value of, a, on a 64 bit machine is: 0FEDCBA9876543210H |
| 99 |
|
| 100 |
The parameters do not have to be the same type, but constants |
| 101 |
_must_ be typed. |
| 102 |
*) |
| 103 |
|
| 104 |
PROCEDURE ADR (VAR v: <anytype>): ADDRESS; |
| 105 |
(* Returns the address of variable v. *) |
| 106 |
|
| 107 |
PROCEDURE ROTATE (val: <a packedset type>; |
| 108 |
num: INTEGER): <type of first parameter>; |
| 109 |
(* Returns a bit sequence obtained from val by rotating up/right |
| 110 |
or down/right by the absolute value of num. The direction is |
| 111 |
down/right if the sign of num is negative, otherwise the direction |
| 112 |
is up/left. |
| 113 |
*) |
| 114 |
|
| 115 |
PROCEDURE SHIFT (val: <a packedset type>; |
| 116 |
num: INTEGER): <type of first parameter>; |
| 117 |
(* Returns a bit sequence obtained from val by shifting up/left |
| 118 |
or down/right by the absolute value of num, introducing |
| 119 |
zeros as necessary. The direction is down/right if the sign of |
| 120 |
num is negative, otherwise the direction is up/left. |
| 121 |
*) |
| 122 |
|
| 123 |
PROCEDURE CAST (<targettype>; val: <anytype>): <targettype>; |
| 124 |
(* CAST is a type transfer function. Given the expression |
| 125 |
denoted by val, it returns a value of the type <targettype>. |
| 126 |
An invalid value for the target value or a |
| 127 |
physical address alignment problem may raise an exception. |
| 128 |
*) |
| 129 |
|
| 130 |
PROCEDURE TSIZE (<type>; ... ): CARDINAL; |
| 131 |
(* Returns the number of LOCS used to store a value of the |
| 132 |
specified <type>. The extra parameters, if present, |
| 133 |
are used to distinguish variants in a variant record. |
| 134 |
*) |
| 135 |
|
| 136 |
PROCEDURE THROW (i: INTEGER) <* noreturn *> ; |
| 137 |
(* |
| 138 |
THROW is a GNU extension and was not part of the PIM or ISO |
| 139 |
standards. It throws an exception which will be caught by the |
| 140 |
EXCEPT block (assuming it exists). This is a compiler builtin |
| 141 |
function which interfaces to the GCC exception handling runtime |
| 142 |
system. |
| 143 |
GCC uses the term throw, hence the naming distinction between |
| 144 |
the GCC builtin and the Modula-2 runtime library procedure Raise. |
| 145 |
The later library procedure Raise will call SYSTEM.THROW after |
| 146 |
performing various housekeeping activities. |
| 147 |
*) |
| 148 |
|
| 149 |
PROCEDURE TBITSIZE (<type>) : CARDINAL ; |
| 150 |
(* Returns the minimum number of bits necessary to represent |
| 151 |
<type>. This procedure function is only useful for determining |
| 152 |
the number of bits used for any type field within a packed RECORD. |
| 153 |
It is not particularly useful elsewhere since <type> might be |
| 154 |
optimized for speed, for example a BOOLEAN could occupy a WORD. |
| 155 |
*) |
| 156 |
*) |
| 157 |
|
| 158 |
|
| 159 |
(* The following procedures are invoked by GNU Modula-2 to |
| 160 |
shift non word set types. They are not part of ISO Modula-2 |
| 161 |
but are used to implement the SHIFT procedure defined above. *) |
| 162 |
|
| 163 |
(* |
| 164 |
ShiftVal - is a runtime procedure whose job is to implement |
| 165 |
the SHIFT procedure of ISO SYSTEM. GNU Modula-2 will |
| 166 |
inline a SHIFT of a single WORD sized set and will only |
| 167 |
call this routine for larger sets. |
| 168 |
*) |
| 169 |
|
| 170 |
PROCEDURE ShiftVal (VAR s, d: ARRAY OF BITSET; |
| 171 |
SetSizeInBits: CARDINAL; |
| 172 |
ShiftCount: INTEGER) ; |
| 173 |
|
| 174 |
|
| 175 |
(* |
| 176 |
ShiftLeft - performs the shift left for a multi word set. |
| 177 |
This procedure might be called by the back end of |
| 178 |
GNU Modula-2 depending whether amount is known at |
| 179 |
compile time. |
| 180 |
*) |
| 181 |
|
| 182 |
PROCEDURE ShiftLeft (VAR s, d: ARRAY OF BITSET; |
| 183 |
SetSizeInBits: CARDINAL; |
| 184 |
ShiftCount: CARDINAL) ; |
| 185 |
|
| 186 |
(* |
| 187 |
ShiftRight - performs the shift left for a multi word set. |
| 188 |
This procedure might be called by the back end of |
| 189 |
GNU Modula-2 depending whether amount is known at |
| 190 |
compile time. |
| 191 |
*) |
| 192 |
|
| 193 |
PROCEDURE ShiftRight (VAR s, d: ARRAY OF BITSET; |
| 194 |
SetSizeInBits: CARDINAL; |
| 195 |
ShiftCount: CARDINAL) ; |
| 196 |
|
| 197 |
|
| 198 |
(* |
| 199 |
RotateVal - is a runtime procedure whose job is to implement |
| 200 |
the ROTATE procedure of ISO SYSTEM. GNU Modula-2 will |
| 201 |
inline a ROTATE of a single WORD (or less) |
| 202 |
sized set and will only call this routine for larger |
| 203 |
sets. |
| 204 |
*) |
| 205 |
|
| 206 |
PROCEDURE RotateVal (VAR s, d: ARRAY OF BITSET; |
| 207 |
SetSizeInBits: CARDINAL; |
| 208 |
RotateCount: INTEGER) ; |
| 209 |
|
| 210 |
|
| 211 |
(* |
| 212 |
RotateLeft - performs the rotate left for a multi word set. |
| 213 |
This procedure might be called by the back end of |
| 214 |
GNU Modula-2 depending whether amount is known at |
| 215 |
compile time. |
| 216 |
*) |
| 217 |
|
| 218 |
PROCEDURE RotateLeft (VAR s, d: ARRAY OF BITSET; |
| 219 |
SetSizeInBits: CARDINAL; |
| 220 |
RotateCount: CARDINAL) ; |
| 221 |
|
| 222 |
|
| 223 |
(* |
| 224 |
RotateRight - performs the rotate right for a multi word set. |
| 225 |
This procedure might be called by the back end of |
| 226 |
GNU Modula-2 depending whether amount is known at |
| 227 |
compile time. |
| 228 |
*) |
| 229 |
|
| 230 |
PROCEDURE RotateRight (VAR s, d: ARRAY OF BITSET; |
| 231 |
SetSizeInBits: CARDINAL; |
| 232 |
RotateCount: CARDINAL) ; |
| 233 |
|
| 234 |
|
| 235 |
END SYSTEM. |