This is the mail archive of the mailing list for the Guile project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: So far, so good.

> > To solve the 'SCM value as case label' problem, it would be necessary to
> > provide a corresponding raw (i. e. unpacked) value for each SCM
> > value.  This could look as follows:
> > 
> > #define SCM_BOOL_T_WORD		SCM_MAKIFLAG (17)
> > #define SCM_BOOL_T 		SCM_PACK (SCM_MAKIFLAG (17))
> > 
> > In case labels, the SCM_BOOL_T_WORD macro would have to be used.  I don't
> > know if we want to go that way, or simply accept that we can not actually
> > produce an executable with strict typing enabled.
> What about using SCM_UNPACK (or some shorter form specially dedicated
> for this use) both in the switch expression and in each label?  (Am I
> being stupid now?)

The reason is, that, say, SCM_BOOL_T already is a packed value.  Packing
is done via a function call, as can be seen from the following
definitions, which are used when compiling with strict typing:

    typedef union { struct { scm_bits_t n; } n; } SCM;
    static SCM scm_pack(scm_bits_t b) { SCM s; s.n.n = b; return s; }
    #define SCM_UNPACK(x) ((x).n.n)
    #define SCM_PACK(x) (scm_pack ((scm_bits_t) (x)))

Thus, SCM_BOOL_T is a result of a call to scm_pack.  The compiler will not
accept the result of a function call as a case label or as an
initializer.  Simply doing an unpack is from the compilers point of view
no help, since the compiler will still not be able to determine the
corresponding constant value:  The compiler does not 'inline' and resolve
the code for scm_pack.

Maybe somebody can think of a way to change the definitions for SCM_PACK
and SCM_UNPACK, which will keep the same degree of type safety, but I
doubt it:  As long as we use a union or a struct for SCM values, the
compiler would at least have to accept an expression like
  case (s.n.n = <some constant>, s.n.n):
as a valid case label.  I just checked:  gcc does not accept it.

Although I think it would be nice if guile could be compiled with strict
typing, I am not so sure if the introduction of the whole set of
SCM_BOOL_T_WORD style macros (or whatever they would be named) would be
worth it.  However, if  people think that there is a use for an executable
that was compiled with strict typing, we can do it anyway.

Best regards,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]