Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Synthesis Of Non Scalar Type ConversionObjectiveThe objective of the facility described here is to facilitate synthesis of type conversion between non-scalar types even if no direct conversion path exists between them or their component types. Given TYPE V = OPAQUE RECORD ("V-Type") v1, v2, v3 : T1 END; W = OPAQUE RECORD ("V-Type") v1, v2, v3 : T2 END; VAR v : V; w : W; the conversion from
should be synthesised by the compiler in the event that no direct conversion path exists from type ApproachThe key to synthesising such a conversion is to decompose To facilitate this, the non-scalar types must provide
The component type can be deduced form the return type of the accessor function. This could be done using the following bindings: PROCEDURE [HIGH] highestComponentIndex ( v : VECTOR ) : CARDINAL; PROCEDURE [.] componentN ( n : CARDINAL; v : VECTOR ) : ComponentType; PROCEDURE [!] setComponentN ( n : CARDINAL; VAR v : VECTOR; c : ComponentType ); An example is given in TypeSampleVector The generalised synthesis algorithm is: VAR v : V; w : W; w := v :: W; synthesises to => VAR v : V; w : W; index : CARDINAL; significand, exponent : ARRAY %MAX_LITERAL_LENGTH% OF CHAR; IF HIGH(v) = HIGH(w) THEN FOR index := 0 TO HIGH(v) DO V.toASCII( %ACCESSOR%(index, v), %decOrHexT1%, significand, exponent ); %MUTATOR%(index, w, W.fromASCII( %decOrHexT2%, significand, exponent )); END; (* FOR *) END; (* IF *) where NB: For the compiler to save stack space for the intermediate strings |