guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposal: stricter type-checking for macros


From: Han-Wen Nienhuys
Subject: proposal: stricter type-checking for macros
Date: Thu, 25 Mar 2004 13:23:01 +0100


Hi there,

after being bitten by a unnoticed type-error using SCM_CDRLOC, for the
umpteenth time, I submit a proposal that would make typechecking
macros stricter without the overhead of the union type
(SCM_DEBUG_TYPING_STRICTNESS == 2).

Here are a couple of tests. I'm not sure about the development
requirements for such code (one hack requires GCC, for instance), but
I think it should be switched on at all times. My preference is for

  /*
  works, but warning message sucks.
  */
  #define TYPECHECK(x)  (((x) - global_object) + global_object)

or

  /*
   works, GCC specific
  */
  #define TYPECHECK(x)  ({ SCM ___y = x; ___y; })

I am not sure of the performance penalties when compiling without -O2.
Maybe assembler gurus could comment?

It would also be nice if scm_unused_struct of the current code would
be changed in 

        struct scm_word {
          long car;
          long cdr; 
        };

or somesuch - it makes debugging a little easier.

****
struct scm_word {
  long car;
  long cdr; 
};

typedef struct scm_word * SCM;
SCM global_object;

inline SCM scm_identity (SCM x)
{
  return x;
}

/*
  ugh: evaluates X twice.
  */

// #define TYPECHECK(x)  (x == global_object) ? x : x;


/*
  works, but warning message sucks.
 */
#define TYPECHECK(x)  (((x) - global_object) + global_object)


/*
  works, performance hit (even with -O2) 
 */
// #define TYPECHECK(x)  (global_object = (x))

/*
  works, performance hit (without -O2)
 */
//#define TYPECHECK(x) scm_identity(x)

/*
  works, GCC specific
*/
//#define TYPECHECK(x)  ({ SCM ___y = x; ___y; })



SCM
f(SCM x, SCM y)
{
  SCM d = 0;
  d = TYPECHECK(x);
  d = TYPECHECK(&x);
  return d;
}



-- 

 Han-Wen Nienhuys   |   address@hidden   |   http://www.xs4all.nl/~hanwen 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]