summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2009-03-16 19:13:41 +0100
committerLudovic Courtès <ludo@gnu.org>2009-03-16 19:13:41 +0100
commitf0eb5ae6c173aed35965b0561897fda1d8ff0db1 (patch)
treead1b050db1e97d9bd2556e1a7d15652a55432ece
parenta4167c920a88ceb02ce201a6cd03b60204657ddd (diff)
downloadguile-f0eb5ae6c173aed35965b0561897fda1d8ff0db1.tar.gz
Allow the static allocation of all types of subrs.
This is a follow-up to 46f9baf49a8ea4461e8494c75a88b87d0f5c5195 ("Allow the static initialization of subrs.") and e20d7001c3f7150400169fecb0bf0eefdf122fe2 ("Remove "compiled closures" ("cclos") in favor of a simpler mechanism."). * libguile/procs.h (SCM_SUBR_ARITY_TO_TYPE): Return the appropriate type for gsubrs instead of returning -1. * libguile/Makefile.am (snarf-gsubr.h): Remove target. (BUILT_SOURCES, nodist_modinclude_HEADERS, MOSTLYCLEANFILES): Remove `snarf-gsubr.h'. * libguile/snarf.h (SCM_DEFINE)[SCM_SUPPORT_STATIC_ALLOCATION]: Don't include "libguile/snarf-gsubr.h". (SCM_DEFINE_SUBR_reqX_optY_rstZ): Remove.
-rw-r--r--.gitignore1
-rw-r--r--libguile/Makefile.am24
-rw-r--r--libguile/procs.h68
-rw-r--r--libguile/snarf.h32
4 files changed, 43 insertions, 82 deletions
diff --git a/.gitignore b/.gitignore
index 43545aedb..7644deacd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,5 +74,4 @@ libguile/stack-limit-calibration.scm
cscope.out
cscope.files
*.log
-/libguile/snarf-gsubr.h
INSTALL
diff --git a/libguile/Makefile.am b/libguile/Makefile.am
index 885de72c4..9b05f01be 100644
--- a/libguile/Makefile.am
+++ b/libguile/Makefile.am
@@ -77,21 +77,6 @@ scmconfig.h: ${top_builddir}/config.h gen-scmconfig$(EXEEXT)
rm -f scmconfig.h
mv scmconfig.h.tmp scmconfig.h
-# Generate aliases for `SCM_DEFINE_GSUBR'. Since there's a lot of
-# them, it's an efficient compression method.
-snarf-gsubr.h:
- ( echo "/* Automatically generated, do not edit. */" ; \
- for req in `seq 0 16`; do \
- for opt in `seq 0 16`; do \
- for rst in 0 1; do \
- echo "#ifndef SCM_DEFINE_SUBR_req$${req}_opt$${opt}_rst$${rst}" ; \
- echo "# define SCM_DEFINE_SUBR_req$${req}_opt$${opt}_rst$${rst} SCM_DEFINE_GSUBR" ; \
- echo "#endif" ; \
- done ; \
- done ; \
- done ) > "$@.tmp"
- mv "$@.tmp" "$@"
-
guile_filter_doc_snarfage_SOURCES = c-tokenize.c
## Override default rule; this should be compiled for BUILD host.
@@ -181,8 +166,8 @@ DOT_DOC_FILES = alist.doc arbiters.doc async.doc backtrace.doc \
EXTRA_DOT_DOC_FILES = @EXTRA_DOT_DOC_FILES@
-BUILT_SOURCES = cpp_err_symbols.c cpp_sig_symbols.c libpath.h \
- version.h scmconfig.h snarf-gsubr.h \
+BUILT_SOURCES = cpp_err_symbols.c cpp_sig_symbols.c libpath.h \
+ version.h scmconfig.h \
$(DOT_X_FILES) $(EXTRA_DOT_X_FILES)
EXTRA_libguile_la_SOURCES = _scm.h \
@@ -239,7 +224,7 @@ modinclude_HEADERS = __scm.h alist.h arbiters.h async.h backtrace.h \
pthread-threads.h null-threads.h throw.h unif.h values.h \
variable.h vectors.h vports.h weaks.h
-nodist_modinclude_HEADERS = version.h scmconfig.h snarf-gsubr.h
+nodist_modinclude_HEADERS = version.h scmconfig.h
bin_SCRIPTS = guile-snarf
@@ -424,8 +409,7 @@ MOSTLYCLEANFILES = \
cpp_err_symbols_here cpp_err_symbols_diff cpp_err_symbols_new \
cpp_sig_symbols_here cpp_sig_symbols_diff cpp_sig_symbols_new \
version.h version.h.tmp \
- scmconfig.h scmconfig.h.tmp snarf-gsubr.h snarf-gsubr.h.tmp \
- stack-limit-calibration.scm
+ scmconfig.h scmconfig.h.tmp stack-limit-calibration.scm
CLEANFILES = libpath.h *.x *.doc guile-procedures.txt guile-procedures.texi guile.texi
diff --git a/libguile/procs.h b/libguile/procs.h
index e2dec99d0..18857c62e 100644
--- a/libguile/procs.h
+++ b/libguile/procs.h
@@ -39,37 +39,43 @@
#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)))
diff --git a/libguile/snarf.h b/libguile/snarf.h
index 451323c1b..c3113e1a7 100644
--- a/libguile/snarf.h
+++ b/libguile/snarf.h
@@ -97,8 +97,8 @@ SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
#ifdef SCM_SUPPORT_STATIC_ALLOCATION
-/* Regular "subrs", i.e., few arguments. */
-#define SCM_DEFINE_SUBR(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
+/* Static subr allocation. */
+#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
SCM_SYMBOL (scm_i_paste (FNAME, __name), PRIMNAME); \
SCM_SNARF_HERE( \
static const char scm_i_paste (s_, FNAME) [] = PRIMNAME; \
@@ -116,34 +116,6 @@ SCM_SNARF_INIT( \
) \
SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
-/* XXX: Eventually, we could statically allocate gsubrs as well. */
-
-/* These are the subrs whose arity makes it possible to define them as "raw
- subrs" (as opposed to "gsubrs"). This has to be consistent with
- `SCM_SUBR_ARITY_TO_TYPE ()' and `create_gsubr ()'. */
-#define SCM_DEFINE_SUBR_req0_opt0_rst0 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req1_opt0_rst0 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req0_opt1_rst0 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req1_opt1_rst0 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req2_opt0_rst0 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req3_opt0_rst0 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req0_opt0_rst1 SCM_DEFINE_SUBR
-#define SCM_DEFINE_SUBR_req2_opt0_rst1 SCM_DEFINE_SUBR
-
-/* For any other combination of required/optional/rest arguments, use
- `SCM_DEFINE_GSUBR (). */
-#include "libguile/snarf-gsubr.h"
-
-/* The generic subr definition macro. This macro dispatches to either
- `SCM_DEFINE_SUBR ()' or `SCM_DEFINE_GSUBR ()' depending on the arity of
- the subr being defined. */
-#define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
- SCM_DEFINE_SUBR_req ## REQ ## _opt ## OPT ## _rst ## VAR \
- (FNAME, PRIMNAME, \
- REQ, OPT, VAR, \
- ARGLIST, DOCSTRING)
-
-
#else /* !SCM_SUPPORT_STATIC_ALLOCATION */
/* Always use the generic subr case. */