Allow the static allocation of all types of subrs.
[bpt/guile.git] / libguile / procs.h
index e2dec99..18857c6 100644 (file)
 #define SCM_SET_SUBR_GENERIC(x, g) (*((SCM *) SCM_CELL_WORD_2 (x)) = (g))
 #define SCM_SET_SUBR_GENERIC_LOC(x, g) (SCM_SET_CELL_WORD_2 (x, (scm_t_bits) g))
 
-/* Return the subr type corresponding to the given arity.  If the arity
-   doesn't match that of a subr (e.g., too many arguments), then -1 is
-   returned.  This has to be in sync with `create_gsubr ()'.  */
-#define SCM_SUBR_ARITY_TO_TYPE(req, opt, rest) \
-  ((rest) == 0                                 \
-   ? ((opt) == 0                               \
-      ? ((req) == 0                            \
-        ? scm_tc7_subr_0                       \
-        : ((req) == 1                          \
-           ? scm_tc7_subr_1                    \
-           : ((req) == 2                       \
-              ? scm_tc7_subr_2                 \
-              : ((req) == 3                    \
-                 ? scm_tc7_subr_3              \
-                 : -1))))                      \
-      : ((opt) == 1                            \
-        ? ((req) == 0                          \
-           ? scm_tc7_subr_1o                   \
-           : ((req) == 1                       \
-              ? scm_tc7_subr_2o                \
-              : -1))                           \
-        : -1))                                 \
-   : ((rest) == 1                              \
-      ? ((opt) == 0                            \
-        ? ((req) == 0                          \
-           ? scm_tc7_lsubr                     \
-           : ((req) == 2                       \
-              ? scm_tc7_lsubr_2                \
-              : -1))                           \
-        : -1)                                  \
-      : -1))
+/* Return the most suitable subr type for a subr with REQ required arguments,
+   OPT optional arguments, and REST (0 or 1) arguments.  This has to be in
+   sync with `create_gsubr ()'.  */
+#define SCM_SUBR_ARITY_TO_TYPE(req, opt, rest)                         \
+  ((rest) == 0                                                         \
+   ? ((opt) == 0                                                       \
+      ? ((req) == 0                                                    \
+        ? scm_tc7_subr_0                                               \
+        : ((req) == 1                                                  \
+           ? scm_tc7_subr_1                                            \
+           : ((req) == 2                                               \
+              ? scm_tc7_subr_2                                         \
+              : ((req) == 3                                            \
+                 ? scm_tc7_subr_3                                      \
+                 : scm_tc7_gsubr                                       \
+                   | (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U)))))    \
+      : ((opt) == 1                                                    \
+        ? ((req) == 0                                                  \
+           ? scm_tc7_subr_1o                                           \
+           : ((req) == 1                                               \
+              ? scm_tc7_subr_2o                                        \
+              : scm_tc7_gsubr |                                        \
+                (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U)))           \
+        : scm_tc7_gsubr |                                              \
+          (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U)))                 \
+   : ((rest) == 1                                                      \
+      ? ((opt) == 0                                                    \
+        ? ((req) == 0                                                  \
+           ? scm_tc7_lsubr                                             \
+           : ((req) == 2                                               \
+              ? scm_tc7_lsubr_2                                        \
+              : scm_tc7_gsubr                                          \
+                | (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U)))         \
+        : scm_tc7_gsubr                                                \
+          | (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U))                \
+      : scm_tc7_gsubr                                                  \
+        | (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U)))
 
 
 \f