Low-level system interface module. Provides types and procedures that bypass normal Modula-2 type safety. Use with caution.
TYPE WORD; (* machine word, compatible with any single-word type *)
TYPE BYTE; (* single byte *)
TYPE ADDRESS; (* untyped pointer, compatible with any pointer type *)
PROCEDURE ADR(x): ADDRESS;
PROCEDURE TSIZE(T): CARDINAL;
The following bitwise operations are available as pervasive builtins
(no import required). They correspond to ISO SYSTEM.SHIFT /
SYSTEM.ROTATE and common compiler extensions.
PROCEDURE SHL(x, n: CARDINAL): CARDINAL; (* shift left *)
PROCEDURE SHR(x, n: CARDINAL): CARDINAL; (* shift right *)
PROCEDURE BAND(a, b: CARDINAL): CARDINAL; (* bitwise AND *)
PROCEDURE BOR(a, b: CARDINAL): CARDINAL; (* bitwise OR *)
PROCEDURE BXOR(a, b: CARDINAL): CARDINAL; (* bitwise XOR *)
PROCEDURE BNOT(x: CARDINAL): CARDINAL; (* bitwise NOT *)
PROCEDURE SHIFT(val: CARDINAL; n: INTEGER): CARDINAL; (* bidirectional shift *)
PROCEDURE ROTATE(val: CARDINAL; n: INTEGER): CARDINAL; (* bidirectional rotate *)
SHIFT and ROTATE accept a signed shift count: positive values
shift/rotate left, negative values shift/rotate right. SHIFT fills
vacated bits with zero; ROTATE wraps bits around.
See the individual builtin reference pages for details.
ADR(x)returns the memory address of variablex.TSIZE(T)returns the size in bytes of typeT.ADDRESSis assignment-compatible with all pointer types.- Importing from
SYSTEMbypasses normal type safety -- the compiler permits casts and operations that would otherwise be rejected.
MODULE SysDemo;
FROM SYSTEM IMPORT ADR, TSIZE, ADDRESS;
FROM InOut IMPORT WriteCard, WriteLn;
VAR
n: INTEGER;
a: ADDRESS;
BEGIN
a := ADR(n);
WriteCard(TSIZE(INTEGER), 0); WriteLn;
END SysDemo.