Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Type Sample INTDEFINITION MODULE SampleINT; (* Sample definition of a signed integer type *) FROM FileIO IMPORT File; (* required for IO *) (* SampleINT type *) TYPE SampleINT = OPAQUE RECORD ("Z-Type") value : ARRAY 2 OF OCTET; (* 16 bits *) END; (* range *) CONST [TMIN] minValue = -32768; CONST [TMAX] maxValue = 32767; (* assignment *) PROCEDURE [:=] assign ( VAR assignTo : SampleINT; literal : ARRAY OF CHAR ); (* type conversions *) PROCEDURE [::] toCARD ( n : SampleINT ) : CARDINAL; PROCEDURE [::] toINT ( n : SampleINT ) : INTEGER; PROCEDURE [::] toREAL ( n : SampleINT ) : REAL; (* experimental *) PROCEDURE [::] fromCARD ( n : CARDINAL ) : SampleINT; PROCEDURE [::] fromINT ( n : INTEGER ) : SampleINT; (* monadic arithmetic operations *) PROCEDURE [ABS] abs ( n : SampleINT ) : SampleINT; PROCEDURE [NEG] neg ( n : SampleINT ) : BOOLEAN; PROCEDURE [ODD] odd ( n : SampleINT ) : BOOLEAN; (* dyadic arithmetic operations *) PROCEDURE [+] add ( n, m : SampleINT ) : SampleINT; PROCEDURE [-] sub ( n, m : SampleINT ) : SampleINT; PROCEDURE [*] multiply ( n, m : SampleINT ) : SampleINT; PROCEDURE [DIV] divide ( n, m : SampleINT ) : SampleINT; PROCEDURE [MOD] modulo ( n, m : SampleINT ) : SampleINT; (* relational operations *) PROCEDURE [=] isEqual ( n, m : SampleINT ) : BOOLEAN; PROCEDURE [<] isLess ( n, m : SampleINT ) : BOOLEAN; PROCEDURE [>] isGreater ( n, m : SampleINT ) : BOOLEAN; (* scalar conversion primitives *) CONST stdINT = TRUE; (* experimental *) CONST digitCapacity = 4; (* total digits in native radix *) PROCEDURE [TO] toSXF ( n : SampleINT; VAR s : ARRAY OF CHAR ); (* convert a SampleINT value to a string in scalar exchange format *) PROCEDURE [FROM] fromSXF ( VAR n : SampleINT; s : ARRAY OF CHAR ); (* convert a string in scalar exchange format to a SampleINT value *) (* IO operations, bound to READ, WRITE and WRITEF *) PROCEDURE Read( infile : File; VAR b : SampleINT ); (* Reads the textual representation of a SampleINT value in simple format from input stream infile - any leading whitespace is skipped - any remaining characters that are part of the numeral being read are removed from infile - the numeric value of the numeral string read is assigned to the variable passed in for b - the file status is set to any of success, outOfRange, wrongFormat, endOfLine, or endOfInput *) PROCEDURE Write( outfile : File; b : SampleINT ); (* Writes the textual representation of value b in simple format to output stream outfile *) PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR; items : CARDINAL; VARIADIC v[items] OF b : SampleINT ); (* Writes a formatted textual representation of one or more SampleINT values to output stream outfile. The value of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *) END SampleINT. |