What follows is not a strong opinion. It is only my initial reaction.
If a field is being used as a discriminator tag, it seems to me that it
is (in human terms) a distinct logical unit of the structure, and it
should have a name. If it has a name, then it seems to me that it should
have ONE name.
If this rule is followed, then your first example:
> (defrepr repr
> (C1 i: (bitfield uint32 2)
> j: (bitfield uint32 30) (where (i 0))
> (C1 k: (bitfield uint32 2)
> l: (bitfield uint32 20)
> m: (bitfield uint32 20) (where (k 1))
> )
should be rejected.
Now, consider a *variant* of your second example:
> (defrepr repr
> (C1 i: (bitfield uint32 2)
> j: (bitfield uint32 30) (where (i 0))
> (C1 i: (bitfield uint32 2)
> l: (bitfield uint32 30) (where (i 1))
> )
The tag field "i" has the same name everywhere, which seems sensible.
The question we must consider is whether "j" and "l" must agree about
their names. I think that the answer should be *no*. My reasoning is as
follows:
If a field has sufficiently common purpose to have the same name
in multiple legs, then it should have the same location(s). This
is simply the rule we have discussed before, but note that it is
consistent with the tag name rule above.
However, two fields in two separate legs do not have any shared
meaning simply because they occupy the same position. Therefore,
non-tag field names should not be required to match merely because
they shared position. [So: no change compared to current behavior.]
> In either case, I don't think the following should be legal:
>
> (defrepr repr
> (C1 (reserved (bitfield uint32 30) 0)
> j: (bitfield uint32 30))
> (C1 k: (bitfield uint32 2)
> l: (bitfield uint32 20)
> m: (bitfield uint32 20) (where (k 1))
> )
I agree. What is happening here is that there are two tag fields that
are being collapsed in the first leg. It does not seem to me that there
is any loss of expressiveness if it is required to make this split
explicit, but now that I have said that let me give a counter-example:
(defrepr (tagged-ptr 'a)
(C1 ptr : (ref 'a))
(C2 tag : (bitfield word 1)
rest: (bitfield word 31)))
This is very close to an example that we already permit with DEFUNION:
(defunion Integer
(declare (tag-type (bitfield word 1)))
(fixnum small:(bitfield word -1))\
(bignum large:long-number-rep))
So I am not sure that my instincts here are correct. I think that for
now we should adopt your rule, but keep in mind that we may want to
relax it later.
shap
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev