John Reagan <john.reagan@[EMAIL PROTECTED]
> wrote:
> Waldek Hebisch wrote:
> > John Reagan <john.reagan@[EMAIL PROTECTED]
> wrote:
> >
> >>
> >>Why do you care about the type of C1 and C2?
> >>
> >
> >
> > I want to faithfully implement EP typechecking rules.
> >
>
> For schematic ordinals, should be pretty straight forward. The fact
> that assignment-compatability is pretty loose with ordinal values, there
> isn't much that can go wrong.
>
Well, the wording in the standard just enumerates bunch of cases where
the loose checking applies. Enumerations are _not_ in the list. It can
be argued that the cases included in the standard (subranges and sets)
are a practical necessity. OTOH for enumeration there is no such
necessity -- so IMHO overall harmony should be the main criterion.
> >
> >>You can't have more than one definition of C1 and C2 in any region,
can
> >>you? It should all just work out.
> >>
> >
> >
> > But I can have multiple types produced from the same schema in the
same
> > region. I can export renamed C1 and C2 from a module, and then import
> > different versions in a single region. I can pass C1 to a procedure
> > with schematic value parameter and inquire about it type. I can get
> > from C1 corresponding discriminat value. For example:
> >
> > procedure p;
> > var va2 : es(2);
> > procedure tc(par : es);
> > var va1 : type of par;
> > begin
> > va1 := c1;
> > writeln(va1.i);
> > va2 := va1;
> > end;
> > begin
> > va2 := c2;
> > tc(c1)
> > end;
>
> Have your read the NOTE in section 6.7.3.2? It doesn't explicitly
> mentioned enumerated-types, but since enumerated-types behave very much
> like subrange-types when it comes to doing assignment-compatability, I
> believe that the NOTE applies to them as well.
>
Well, I would like to see normative support for the note (to say the
truth I want to re-read ordinal rules, but ATM I did not have time).
> Here is what my compiler does for your above example:
>
> $ type es.pas
> program foo(input,output);
>
> type es(i:integer) = (c1,c2);
>
> procedure p;
> var va2 : es(2);
> procedure tc(par : es);
> var va1 : es(par.i);
> begin
> va1 := c1;
> writeln(va1.i);
> va2 := va1;
> end;
> begin
> va2 := c2;
> tc(c1);
> end;
>
> begin
> p;
> end.
>
>
> $ pascal/check es
>
> tc(c1);
> ....^
> %PASCAL-E-OPNDASSCOM, Operands are not assignment compatible
> -PASCAL-I-NOACTCOM, No actuals are compatible with schema formal
parameter
> at line number 16 in file HIYALL$:[REAGAN]ES.PAS;1
> %PASCAL-E-ENDDIAGS, PASCAL completed with 2 diagnostics
>
> (Personally, I don't like TYPE OF. It isn't needed since you can
> use the discriminant of PAR to define VA1. TYPE OF is only really
> useful when combined with unextended Pascal's conformant array
parameters.)
>
> >
> > All would be clear if the constants c1 and c2 are defined in the
process
> > of discriminating the schema. Then tc would print 2. However, if c1
and
> > c2 are defined by the schema definition (which is my literal reading
> > of the standard) then it is not clear what value tc should print (and
> > in particular if the above is legal).
> >
> > Or put it differently:
> >
> > var v2 : es(2);
> > v3 : es(3);
> > begin
> > v2 := c1;
> > v3 := c1;
> > end;
> >
> > Is the above legal?
>
> Yes it is.
>
> If c1 and c2 are defind by the schema definition
> > then nothing stops as from producing many different types from the
> > schema. On the other hand for the first assignment to be valid v2 and
c1
> > must be of the same type while for the second assignment to be valid
v3
> > and c1 must be of the same type. Since v2 and v3 have different types
> > so one of the assignment must be illegal.
>
> But remember that the ordinal expression on the right side gets promoted
> to the underlying base type.
>
> It isn't much different than:
>
> var v2 : 1..100;
> v3 : 5..75;
> begin
> v2 := 50;
> v3 := 50;
> end;
>
> The value 50 can be assigned to a variable of type "1..100" and also to
> a variable with type "5..75".
>
There is a difference here: enumeration is its own base type. For sets
the standard speaks about canonical-set-of-T. If one wants to use similar
rule for enumarations then one should have canonical enumeration for
given constant list and promote primaries to this type. So really that
would amend the standard.
--
Waldek Hebisch
hebisch@[EMAIL PROTECTED]


|