[Ooc-checkins] CVS: ooc2/src/Language Integer.Mod,1.4,1.5 IntegerType.Mod,1.2,NONE
Brought to you by:
mva
From: Stewart G. <sgr...@us...> - 2001-12-29 14:26:50
|
Update of /cvsroot/ooc/ooc2/src/Language In directory usw-pr-cvs1:/tmp/cvs-serv25015 Modified Files: Integer.Mod Removed Files: IntegerType.Mod Log Message: Reworked Language:Integer to use core Integers library for arbitrary precision integers. IntegerType has been removed. Note new constructors Integer.NewInt and Integer.NewLInt to construct integers INTEGER and LONGINT respectively. Index: Integer.Mod =================================================================== RCS file: /cvsroot/ooc/ooc2/src/Language/Integer.Mod,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Integer.Mod 2001/12/02 18:38:08 1.4 +++ Integer.Mod 2001/12/29 14:26:46 1.5 @@ -1,21 +1,86 @@ -MODULE Language:Integer; +MODULE Language:Integer [OOC_EXTENSIONS]; IMPORT - L := Language, - I := Language:IntegerType; + Integers, ADT:Object, ADT:String, ADT:StringBuffer, L := Language; TYPE - Type* = I.Type; - Value* = I.Value; - + Value* = POINTER TO ValueDesc; + ValueDesc* = RECORD (L.ValueDesc) + value- : Integers.Integer; + END; + + Type* = POINTER TO TypeDesc; + TypeDesc* = RECORD (L.TypeDesc) + END; + VAR type- : Type; + typeName : String.String; -PROCEDURE New*(value : INTEGER) : Value; +PROCEDURE New* (val : Integers.Integer) : Value; +(** Return a @otype{Value} for integer @oparam{val} with type @oparam{t}. *) +VAR + v : Value; BEGIN - RETURN type.Value(value) + NEW(v); + L.InitValue (v, type); + v.value := val; + RETURN v; END New; +PROCEDURE NewLInt* (l : LONGINT) : Value; +BEGIN + RETURN New(Integers.Long(l)); +END NewLInt; + +PROCEDURE NewInt* (i : INTEGER) : Value; +BEGIN + RETURN NewLInt(i); +END NewInt; + +PROCEDURE (v: Value) Equals* (y: Object.Object): BOOLEAN; + BEGIN + RETURN (y IS Value) & (Integers.Compare(y(Value).value, v.value) = 0); + END Equals; + +PROCEDURE (v: Value) HashCode* (): LONGINT; + BEGIN + RETURN Integers.Digits10Of(v.value); + END HashCode; + +PROCEDURE (v : Value) ToString* () : String.String; +VAR str: ARRAY 128 OF CHAR; (* FIXME! *) +BEGIN + Integers.ConvertToString(v.value, str); + RETURN String.New (str) +END ToString; + +PROCEDURE (t : Type) ValueLInt* (val : LONGINT) : Value; BEGIN - type := I.NewType(MIN(INTEGER), MAX(INTEGER)); + RETURN New(Integers.Long(val)); +END ValueLInt; + +PROCEDURE (t : Type) Value* (val : Integers.Integer) : Value; +BEGIN + RETURN New(val); +END Value; + +PROCEDURE (t : Type) ValueOf* (s : ARRAY OF CHAR) : Value; +VAR + val : Integers.Integer; +BEGIN + Integers.ConvertFromString(s, val); + RETURN New(val); +END ValueOf; + +PROCEDURE (t : Type) ToString* () : String.String; +BEGIN + RETURN typeName +END ToString; + +BEGIN + NEW(type); + L.InitType(type); + typeName := String.New("INTEGER"); END Language:Integer. + --- IntegerType.Mod DELETED --- |