INTERFACEModula-3 target descriptionTInt ;
This interface provides simulations of the target machine's signed integer operations.
Unless otherwise specified, the arithmetic operations defined below return TRUE if they succeed in producing a new target value, otherwise they return FALSE.
FROM Target IMPORT Int, IBytes; CONST Zero = Int{NUMBER (IBytes), IBytes{16_00,16_00,..}}; One = Int{NUMBER (IBytes), IBytes{16_01,16_00,..}}; MOne = Int{NUMBER (IBytes), IBytes{16_ff,16_ff,..}}; PROCEDURE FromInt (x: INTEGER; n: CARDINAL; VAR i: Int): BOOLEAN;
converts a host integer 'x' to a target integer 'i'
PROCEDURE IntI (READONLY x: Int; n: CARDINAL; VAR i: Int): BOOLEAN;
converts a target integer 'x' to a target integer 'i'
PROCEDURE ToInt (READONLY i: Int; VAR x: INTEGER): BOOLEAN;
converts a target integer 'i' to a host integer 'x'
PROCEDURE New (READONLY chars: ARRAY OF CHAR; n: CARDINAL; VAR i: Int): BOOLEAN;
converts the string of decimal characters in 'chars' to an integer value in 'i'
PROCEDURE Add (READONLY a, b: Int; VAR i: Int): BOOLEAN;
returns 'a + b' unless there's an overflow
PROCEDURE Subtract (READONLY a, b: Int; VAR i: Int): BOOLEAN;
returns 'a - b' unless there's an overflow
PROCEDURE Multiply (READONLY a, b: Int; VAR i: Int): BOOLEAN;
returns 'a * b' unless there's an overflow
PROCEDURE Div (READONLY a, b: Int; VAR i: Int): BOOLEAN;
returns 'a DIV b' unless there's an overflow
PROCEDURE Mod (READONLY a, b: Int; VAR i: Int): BOOLEAN;
returns 'a MOD b' unless there's an overflow
PROCEDURE EQ (READONLY a, b: Int): BOOLEAN;
returns 'a = b'
PROCEDURE LT (READONLY a, b: Int): BOOLEAN;
returns 'a < b'
PROCEDURE LE (READONLY a, b: Int): BOOLEAN;
returns 'a <= b'
PROCEDURE ToChars (READONLY i: Int; VAR buf: ARRAY OF CHAR): INTEGER;
converts 'i' to a printable string in 'buf'. Returns the number of characters in the string. Returns -1 if 'buf' is too short.
PROCEDURE ToBytes (READONLY i: Int; VAR buf: ARRAY OF [0..255]): INTEGER;
converts 'i' to the shortest sequence of bytes in little-endian order which when sign-extended equal 'i'. Returns the number of significant bytes in the result. Returns -1 if 'buf' is too short.
END TInt.