Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Type Sample UINT

WiP.TypeSampleUINT History

Hide minor edits - Show changes to markup

2010-04-11 11:01 by benjk -
Changed lines 23-25 from:

CONST [CARDINAL] usesStdBinaryRepresentation = TRUE; (* experimental *)

to:
Changed lines 40-42 from:

PROCEDURE [::] fromCARD ( n : CARDINAL ) : Sample INT?;

PROCEDURE [::] fromINT ( n : INTEGER ) : Sample INT?;

to:

PROCEDURE [::] fromCARD ( n : CARDINAL ) : Sample UINT?;

PROCEDURE [::] fromINT ( n : INTEGER ) : Sample UINT?;

2010-04-11 10:56 by benjk -
Added lines 38-44:

(* experimental *)

PROCEDURE [::] fromCARD ( n : CARDINAL ) : Sample INT?;

PROCEDURE [::] fromINT ( n : INTEGER ) : Sample INT?;

2010-04-11 09:49 by benjk -
Changed line 23 from:

CONST [CARDINAL] cardinalRepresentation = TRUE; (* experimental *)

to:

CONST [CARDINAL] usesStdBinaryRepresentation = TRUE; (* experimental *)

2010-04-11 09:46 by benjk -
Changed line 23 from:

CONST [CARDINAL] cardinalCompatibility = TRUE; (* experimental *)

to:

CONST [CARDINAL] cardinalRepresentation = TRUE; (* experimental *)

2010-04-11 09:45 by benjk -
Changed lines 23-25 from:
to:

CONST [CARDINAL] cardinalCompatibility = TRUE; (* experimental *)

Changed line 71 from:

CONST stdCARD = TRUE; (* standard binary representation *)

to:

CONST stdCARD = TRUE; (* experimental *)

2010-04-11 09:30 by benjk -
Changed line 67 from:

(* scalar conversion *)

to:

(* scalar conversion primitives *)

2010-04-11 09:25 by benjk -
Changed line 69 from:

CONST usesSBR = TRUE; (* standard binary representation *)

to:

CONST stdCARD = TRUE; (* standard binary representation *)

2010-04-11 09:08 by benjk -
Changed line 69 from:

CONST usesTCR = TRUE; (* two's complement representation *)

to:

CONST usesSBR = TRUE; (* standard binary representation *)

2010-04-11 08:57 by benjk -
Deleted lines 37-43:

(* conversion primitives *)

PROCEDURE [TO] toSerialized ( value : Sample UINT?; VAR serialized : ARRAY OF CHAR );

PROCEDURE [FROM] fromSerialized ( VAR value : Sample UINT?; serialized : ARRAY OF CHAR );

Added lines 69-70:

CONST usesTCR = TRUE; (* two's complement representation *)

Deleted lines 71-72:

CONST usesTCR = TRUE; (* two's complement representation *)

2010-04-11 08:56 by benjk -
Added lines 77-78:

CONST usesTCR = TRUE; (* two's complement representation *)

2010-04-11 07:21 by benjk -
Added lines 72-82:

(* scalar conversion *)

CONST digitCapacity = 4; (* total digits in native radix *)

PROCEDURE [TO] toSXF ( n : Sample UINT?; VAR s : ARRAY OF CHAR ); (* convert a Sample UINT? value to a string in scalar exchange format *)

PROCEDURE [FROM] fromSXF ( VAR n : Sample UINT?; s : ARRAY OF CHAR ); (* convert a string in scalar exchange format to a Sample UINT? value *)

2010-04-10 15:57 by benjk -
Added line 43:
2010-04-10 15:57 by benjk -
Changed lines 41-44 from:

(* Converts <value> to its serialised scalar representation and passes the result back

   in <serialized>. The output is shortened if the size of the passed in character array
   is insufficient to represent all available digits. *)
to:
Deleted lines 42-43:

(* Converts the passed in serialised scalar to a value of type Sample UINT?

   and passes the result back in <value>. *)
2010-04-10 15:56 by benjk -
Changed lines 40-48 from:

PROCEDURE [TO] toASCII ( value : Sample UINT?;

                         VAR isDecimal : BOOLEAN;
                         VAR mantissa  : ARRAY OF CHAR;
                         VAR exponent  : ARRAY OF CHAR );

PROCEDURE [FROM] fromASCII ( isDecimal : BOOLEAN;

                             mantissa  : ARRAY OF CHAR;
                             exponent  : ARRAY OF CHAR ) : Sample UINT?;
to:

PROCEDURE [TO] toSerialized ( value : Sample UINT?; VAR serialized : ARRAY OF CHAR ); (* Converts <value> to its serialised scalar representation and passes the result back

   in <serialized>. The output is shortened if the size of the passed in character array
   is insufficient to represent all available digits. *)

PROCEDURE [FROM] fromSerialized ( VAR value : Sample UINT?; serialized : ARRAY OF CHAR ); (* Converts the passed in serialised scalar to a value of type Sample UINT?

   and passes the result back in <value>. *)
2010-04-06 17:17 by benjk -
Changed line 67 from:

PROCEDURE [MOD] divide ( a, b : Sample UINT? ) : Sample UINT?;

to:

PROCEDURE [MOD] modulo ( a, b : Sample UINT? ) : Sample UINT?;

2010-04-06 17:11 by benjk -
Deleted lines 16-20:

(* number type *)

CONST [TYPE] semanticModel = 'Z'; (* obsolete *)

Added lines 36-47:

(* conversion primitives *)

PROCEDURE [TO] toASCII ( value : Sample UINT?;

                         VAR isDecimal : BOOLEAN;
                         VAR mantissa  : ARRAY OF CHAR;
                         VAR exponent  : ARRAY OF CHAR );

PROCEDURE [FROM] fromASCII ( isDecimal : BOOLEAN;

                             mantissa  : ARRAY OF CHAR;
                             exponent  : ARRAY OF CHAR ) : Sample UINT?;
2010-04-05 12:21 by benjk -
Changed line 12 from:
    Sample UINT? = OPAQUE RECORD ['Z']
to:
    Sample UINT? = OPAQUE RECORD ("Z-Type")
Changed line 19 from:

CONST [TYPE] semanticModel = 'Z';

to:

CONST [TYPE] semanticModel = 'Z'; (* obsolete *)

2010-04-05 10:45 by benjk -
Changed line 12 from:
    Sample UINT? = OPAQUE RECORD
to:
    Sample UINT? = OPAQUE RECORD ['Z']
2010-04-04 09:42 by benjk -
Added lines 1-89:
DEFINITION MODULE SampleUINT;

(* Sample definition of an unsigned integer type *) 


FROM FileIO IMPORT File; (* required for IO *)


(* SampleUINT type *)

TYPE
    SampleUINT = OPAQUE RECORD
        value : ARRAY 2 OF OCTET; (* 16 bits *)
    END; 


(* number type *)

CONST [TYPE] semanticModel = 'Z';


(* range *) 

CONST [TMIN] minValue = 0; 

CONST [TMAX] maxValue = 65535;


(* assignment *)

PROCEDURE [:=] assign ( VAR assignTo : SampleUINT; literal : ARRAY OF CHAR ); 


(* type conversions *)

PROCEDURE [::] toCARD  ( a : SampleUINT ) : CARDINAL; 

PROCEDURE [::] toINT ( a : SampleUINT ) : INTEGER; 

PROCEDURE [::] toREAL ( a : SampleUINT ) : REAL;


(* monadic arithmetic operations *) 

PROCEDURE [ABS] abs ( a : SampleUINT ) : SampleUINT; 

PROCEDURE [ODD] odd ( a : SampleUINT ) : BOOLEAN; 


(* dyadic arithmetic operations *) 

PROCEDURE [+] add ( a, b : SampleUINT ) : SampleUINT; 

PROCEDURE [-] sub ( a, b : SampleUINT ) : SampleUINT; 

PROCEDURE [*] multiply ( a, b : SampleUINT ) : SampleUINT; 

PROCEDURE [DIV] divide ( a, b : SampleUINT ) : SampleUINT; 

PROCEDURE [MOD] divide ( a, b : SampleUINT ) : SampleUINT; 


(* relational operations *) 

PROCEDURE [=] isEqual ( a, b : SampleUINT ) : BOOLEAN; 

PROCEDURE [<] isLess ( a, b : SampleUINT ) : BOOLEAN; 

PROCEDURE [>] isGreater ( a, b : SampleUINT ) : BOOLEAN; 


(* IO operations, bound to READ, WRITE and WRITEF *)

PROCEDURE Read( infile : File; VAR b : SampleUINT );
(* Reads the textual representation of a SampleUINT 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 : SampleUINT );
(* 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 : SampleUINT );
(* Writes a formatted textual representation of one or more SampleUINT values to output stream outfile. The
   value of parameter items is calculated and inserted automatically. The output format is determined by fmtStr. *)

END SampleUINT.