ported Scales

Former-commit-id: 8652805181
This commit is contained in:
Norayr Chilingarian 2013-10-29 18:43:31 +04:00
parent 8ec2f9c342
commit f1fd9d546c

View file

@ -36,10 +36,10 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
*) *)
MODULE Scales; MODULE ulmScales;
IMPORT Disciplines, Events, Objects, Operations, PersistentObjects, IMPORT Disciplines := ulmDisciplines, Events := ulmEvents, Objects := ulmObjects, Operations := ulmOperations, PersistentObjects := ulmPersistentObjects,
RelatedEvents, Services; RelatedEvents := ulmRelatedEvents, Services := ulmServices, SYS := SYSTEM;
TYPE TYPE
Scale* = POINTER TO ScaleRec; Scale* = POINTER TO ScaleRec;
@ -319,26 +319,27 @@ MODULE Scales;
PROCEDURE Assign(VAR target: Operations.Operand; source: Operations.Operand); PROCEDURE Assign(VAR target: Operations.Operand; source: Operations.Operand);
BEGIN BEGIN
WITH source: Measure DO WITH target: Measure DO (*WITH source: Measure DO WITH target: Measure DO*)
WITH source: Measure DO IF target IS Measure THEN (* WITH is replaced by IS -- noch *)
(* target is already initialized but possibly to a dummy operand (* target is already initialized but possibly to a dummy operand
by CreateOperand by CreateOperand
*) *)
IF target.type = undefined THEN IF target(Measure).type = undefined THEN (* type guard introduced *)
(* init target with the scale of source *) (* init target with the scale of source *)
CreateMeasure(source.scale, target, source.type); CreateMeasure(source.scale, SYS.VAL(Measure, target), source.type); (* need to cast *)
END; END;
IF target.scale # source.scale THEN IF target(Measure).scale # source.scale THEN
(* adapt scale type from source -- (* adapt scale type from source --
this could lead to a type guard failure if this could lead to a type guard failure if
target is not of the appropiate type target is not of the appropiate type
*) *)
CreateMeasure(source.scale, target, source.type); CreateMeasure(source.scale, SYS.VAL(Measure, target), source.type);
END; END;
IF target.type # source.type THEN IF target(Measure).type # source.type THEN
(* adapt measure type from source *) (* adapt measure type from source *)
CreateMeasure(target.scale, target, source.type); CreateMeasure(target(Measure).scale, SYS.VAL(Measure, target), source.type);
END; END;
source.scale.if.assign(target, source); source.scale.if.assign(SYS.VAL(Measure, target), source);
END; END; END; END;
END Assign; END Assign;
@ -380,12 +381,13 @@ MODULE Scales;
*) *)
VAR ok: BOOLEAN; VAR ok: BOOLEAN;
BEGIN BEGIN
WITH op1: Measure DO WITH op2: Measure DO (*WITH op1: Measure DO WITH op2: Measure DO*)
IF op1 IS Measure THEN IF op2 IS Measure THEN
CASE op OF CASE op OF
| Operations.add: (* only abs + abs is invalid *) | Operations.add: (* only abs + abs is invalid *)
ok := (op1.type = relative) OR ok := (op1(Measure).type = relative) OR
(op2.type = relative); (op2(Measure).type = relative);
IF op1.type = op2.type THEN IF op1(Measure).type = op2(Measure).type THEN
(* both are relative *) (* both are relative *)
restype := relative; restype := relative;
ELSE ELSE
@ -393,8 +395,8 @@ MODULE Scales;
restype := absolute; restype := absolute;
END; END;
| Operations.sub: (* only rel - abs is invalid *) | Operations.sub: (* only rel - abs is invalid *)
ok := op1.type <= op2.type; ok := op1(Measure).type <= op2(Measure).type;
IF op1.type # op2.type THEN IF op1(Measure).type # op2(Measure).type THEN
(* abs - rel *) (* abs - rel *)
restype := absolute; restype := absolute;
ELSE ELSE
@ -408,11 +410,11 @@ MODULE Scales;
BEGIN (* Op *) BEGIN (* Op *)
(* result is already of type Measure; this is guaranteed by Operations *) (* result is already of type Measure; this is guaranteed by Operations *)
WITH result: Measure DO IF result IS Measure THEN
CheckTypes(restype); CheckTypes(restype);
CheckCompatibility(op1, op2, m1, m2); CheckCompatibility(op1, op2, m1, m2);
CreateMeasure(m1.scale, result, restype); CreateMeasure(m1.scale, SYS.VAL(Measure, result), restype);
m1.scale.if.op(op, m1, m2, result); m1.scale.if.op(op, m1, m2, SYS.VAL(Measure, result));
END; END;
END Op; END Op;
@ -440,4 +442,4 @@ BEGIN
InitInterface; InitInterface;
PersistentObjects.RegisterType(measureType, PersistentObjects.RegisterType(measureType,
"Scales.Measure", "Operations.Operand", NIL); "Scales.Measure", "Operations.Operand", NIL);
END Scales. END ulmScales.