Oberon || Library || Module Index || Search Engine || Definition || Module
CONST add = 0; sub = 1; mul = 2; div = 3; cmp = 4; TYPE Operation = SHORTINT; (* [add..div] *) TYPE Operand = POINTER TO OperandRec; TYPE OperandRec = RECORD (PersistentDisciplines.ObjectRec) END; TYPE CapabilitySet = SET; (* SET OF [add..cmp] *) TYPE CreateProc = PROCEDURE (VAR op: Operand); TYPE OperatorProc = PROCEDURE (op: Operation; op1, op2: Operand; VAR result: Operand); TYPE AssignProc = PROCEDURE (VAR target: Operand; source: Operand); TYPE CompareProc = PROCEDURE (op1, op2: Operand) : INTEGER; TYPE Interface = POINTER TO InterfaceRec; TYPE InterfaceRec = RECORD (Objects.ObjectRec) create: CreateProc; assign: AssignProc; op: OperatorProc; compare: CompareProc; END;
PROCEDURE Init(op: Operand; if: Interface; caps: CapabilitySet); PROCEDURE Capabilities(op: Operand) : CapabilitySet; PROCEDURE Compatible(op1, op2: Operand) : BOOLEAN; PROCEDURE Add(op1, op2: Operand) : Operand; PROCEDURE Add2(VAR op1: Operand; op2: Operand); PROCEDURE Add3(VAR result: Operand; op1, op2: Operand); PROCEDURE Sub(op1, op2: Operand) : Operand; PROCEDURE Sub2(VAR op1: Operand; op2: Operand); PROCEDURE Sub3(VAR result: Operand; op1, op2: Operand); PROCEDURE Mul(op1, op2: Operand) : Operand; PROCEDURE Mul2(VAR op1: Operand; op2: Operand); PROCEDURE Mul3(VAR result: Operand; op1, op2: Operand); PROCEDURE Div(op1, op2: Operand) : Operand; PROCEDURE Div2(VAR op1: Operand; op2: Operand); PROCEDURE Div3(VAR result: Operand; op1, op2: Operand); PROCEDURE Compare(op1, op2: Operand) : INTEGER; PROCEDURE Assign(VAR target: Operand; source: Operand); PROCEDURE Copy(source, target: Operand);
The interface describes the set of available operations and contains the necessary procedures. The interface procedures should meet the specifications following:
Init is typically called by modules which implement an arithmetic data type to connect the interface if to the operand op. Capabilities returns the set of capabilities of op. Compatible checks op1 and op2 for being compatible, i.e. they share the same interface.
Arithmetic operations are implemented in three forms:
This procedures are provided for XXX equal to Add, Sub, Mul or Div. XXX2 and XXX3 allow result to be equal to op1 or op2.
Compare compares the given operands and returns an integer value which corresponds to the comparison (see interface description of compare).
Assign copies the value of source to target. Remember, that operands are pointers and a pointer-assignment (i.e. target := source) does not copy the value of an operand. target is newly created unless it is not equal to NIL and its type is identical to that of source.
The VAR parameters of the operation procedures are always newly created.
Copy copies the value of source to target without recreating target. target must be of the appropriate type and already initialized. This is useful if old references to target should reference the new value.
Oberon || Library || Module Index || Search Engine || Definition || Module