guile-devel
[Top][All Lists]
Advanced

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

Re: SCM_ASSYNT


From: Dirk Herrmann
Subject: Re: SCM_ASSYNT
Date: Mon, 5 Mar 2001 10:28:19 +0100 (MET)

On 5 Mar 2001, Mikael Djurfeldt wrote:

> Dirk Herrmann <address@hidden> writes:
> 
> > currently I am trying to get rid of the function scm_wta, which is a
> > strange entry point for a couple of error signalling functions.  Doing
> > that, I stumbled across the macro SCM_ASSYNT, which is defined exactly
> > as SCM_ASSERT is.
> 
> There is the point that we, in the future, might want to treat
> (report) errors in primitive macros differently than other errors.
> (Might want to say "syntax error" or something like that, maybe
> another tag.)
> 
> Replacing SCM_ASSYNT with SCM_ASSERT throughout the code removes
> information from the source...

I see.  The strange point at the moment is, that SCM_ASSYNT will most of
the time result in a misc-error, but not always.  My preferred solution
when keeping SCM_ASSYNT would be to define SCM_ASSYNT as:

#define SCM_ASSYNT(cond, arg, msg, subr) \
  if (!(cond)) scm_misc_error (subr, msg, SCM_EOL)

It is then easy to replace scm_misc_error with scm_syntax_error.  Note
that the arg argument is not used.  In the current situation it is not
used either, since the message strings that are used don't hold a ~A or ~S
placeholder.  Probably it would be better to leave out the arg argument
anyway, since in the case of syntax errors there is no argument that it
makes sense to pass.

There is one thing about the above change, though:  In goops.c there are
some calls to SCM_ASSYNT that will result in a wrong-type-arg error. To
apply the above change, those calls would need to be replaced.  Could you
please take a look at the patch below and tell me, whether you think it is
OK?  Further, do you agree with the above change or even with the above
change with the arg argument left out?

Best regards,
Dirk



Index: goops.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/goops.c,v
retrieving revision 1.22
diff -u -r1.22 goops.c
--- goops.c     2001/03/04 20:46:04     1.22
+++ goops.c     2001/03/05 09:04:58
@@ -1866,23 +1866,29 @@
 
 SCM
 scm_m_atslot_ref (SCM xorig, SCM env)
+#define FUNC_NAME s_atslot_ref
 {
   SCM x = SCM_CDR (xorig);
-  SCM_ASSYNT (scm_ilength (x) == 2, xorig, scm_s_expression, s_atslot_ref);
-  SCM_ASSYNT (SCM_INUMP (SCM_CADR (x)), SCM_CADR (x), SCM_ARG2, s_atslot_ref);
+  SCM_ASSYNT (scm_ilength (x) == 2, xorig, scm_s_expression, FUNC_NAME);
+  SCM_VALIDATE_INUM (SCM_ARG2, SCM_CADR (x));
   return scm_cons (SCM_IM_SLOT_REF, x);
 }
+#undef FUNC_NAME
 
+
 SCM_SYNTAX (s_atslot_set_x, "@slot-set!", scm_makmmacro, scm_m_atslot_set_x);
 
 SCM
 scm_m_atslot_set_x (SCM xorig, SCM env)
+#define FUNC_NAME s_atslot_set_x
 {
   SCM x = SCM_CDR (xorig);
-  SCM_ASSYNT (scm_ilength (x) == 3, xorig, scm_s_expression, s_atslot_set_x);
-  SCM_ASSYNT (SCM_INUMP (SCM_CADR (x)), SCM_CADR (x), SCM_ARG2, 
s_atslot_set_x);
+  SCM_ASSYNT (scm_ilength (x) == 3, xorig, scm_s_expression, FUNC_NAME);
+  SCM_VALIDATE_INUM (SCM_ARG2, SCM_CADR (x));
   return scm_cons (SCM_IM_SLOT_SET_X, x);
 }
+#undef FUNC_NAME
+
 
 SCM_SYNTAX (s_atdispatch, "@dispatch", scm_makmmacro, scm_m_atdispatch);
 
@@ -1893,20 +1899,20 @@
 #define FUNC_NAME s_atdispatch
 {
   SCM args, n, v, gf, x = SCM_CDR (xorig);
-  SCM_ASSYNT (scm_ilength (x) == 4, xorig, scm_s_expression, s_atdispatch);
+  SCM_ASSYNT (scm_ilength (x) == 4, xorig, scm_s_expression, FUNC_NAME);
   args = SCM_CAR (x);
-  SCM_ASSYNT (SCM_CONSP (args) || SCM_SYMBOLP (args),
-             args, SCM_ARG1, s_atdispatch);
+  if (!SCM_CONSP (args) && !SCM_SYMBOLP (args))
+    SCM_WRONG_TYPE_ARG (SCM_ARG1, args);
   x = SCM_CDR (x);
   n = SCM_XEVALCAR (x, env);
-  SCM_ASSYNT (SCM_INUMP (n), n, SCM_ARG2, s_atdispatch);
+  SCM_VALIDATE_INUM (SCM_ARG2, n);
   SCM_ASSERT_RANGE (0, n, SCM_INUM (n) >= 1);
   x = SCM_CDR (x);
   v = SCM_XEVALCAR (x, env);
-  SCM_ASSYNT (SCM_VECTORP (v), v, SCM_ARG3, s_atdispatch);
+  SCM_VALIDATE_VECTOR (SCM_ARG3, v);
   x = SCM_CDR (x);
   gf = SCM_XEVALCAR (x, env);
-  SCM_ASSYNT (SCM_PUREGENERICP (gf), gf, SCM_ARG4, s_atdispatch);
+  SCM_VALIDATE_PUREGENERIC (SCM_ARG4, gf);
   return SCM_LIST5 (SCM_IM_DISPATCH, args, n, v, gf);
 }
 #undef FUNC_NAME




reply via email to

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