1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-28 16:00:22 +02:00

Allow the static allocation of all types of subrs.

This is a follow-up to 46f9baf49a ("Allow
the static initialization of subrs.") and
e20d7001c3 ("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.
This commit is contained in:
Ludovic Courtès 2009-03-16 19:13:41 +01:00
parent a4167c920a
commit f0eb5ae6c1
4 changed files with 43 additions and 82 deletions

1
.gitignore vendored
View file

@ -74,5 +74,4 @@ libguile/stack-limit-calibration.scm
cscope.out cscope.out
cscope.files cscope.files
*.log *.log
/libguile/snarf-gsubr.h
INSTALL INSTALL

View file

@ -77,21 +77,6 @@ scmconfig.h: ${top_builddir}/config.h gen-scmconfig$(EXEEXT)
rm -f scmconfig.h rm -f scmconfig.h
mv scmconfig.h.tmp 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 guile_filter_doc_snarfage_SOURCES = c-tokenize.c
## Override default rule; this should be compiled for BUILD host. ## 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@ EXTRA_DOT_DOC_FILES = @EXTRA_DOT_DOC_FILES@
BUILT_SOURCES = cpp_err_symbols.c cpp_sig_symbols.c libpath.h \ BUILT_SOURCES = cpp_err_symbols.c cpp_sig_symbols.c libpath.h \
version.h scmconfig.h snarf-gsubr.h \ version.h scmconfig.h \
$(DOT_X_FILES) $(EXTRA_DOT_X_FILES) $(DOT_X_FILES) $(EXTRA_DOT_X_FILES)
EXTRA_libguile_la_SOURCES = _scm.h \ 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 \ pthread-threads.h null-threads.h throw.h unif.h values.h \
variable.h vectors.h vports.h weaks.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 bin_SCRIPTS = guile-snarf
@ -424,8 +409,7 @@ MOSTLYCLEANFILES = \
cpp_err_symbols_here cpp_err_symbols_diff cpp_err_symbols_new \ cpp_err_symbols_here cpp_err_symbols_diff cpp_err_symbols_new \
cpp_sig_symbols_here cpp_sig_symbols_diff cpp_sig_symbols_new \ cpp_sig_symbols_here cpp_sig_symbols_diff cpp_sig_symbols_new \
version.h version.h.tmp \ version.h version.h.tmp \
scmconfig.h scmconfig.h.tmp snarf-gsubr.h snarf-gsubr.h.tmp \ scmconfig.h scmconfig.h.tmp stack-limit-calibration.scm
stack-limit-calibration.scm
CLEANFILES = libpath.h *.x *.doc guile-procedures.txt guile-procedures.texi guile.texi CLEANFILES = libpath.h *.x *.doc guile-procedures.txt guile-procedures.texi guile.texi

View file

@ -39,37 +39,43 @@
#define SCM_SET_SUBR_GENERIC(x, g) (*((SCM *) SCM_CELL_WORD_2 (x)) = (g)) #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)) #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 /* Return the most suitable subr type for a subr with REQ required arguments,
doesn't match that of a subr (e.g., too many arguments), then -1 is OPT optional arguments, and REST (0 or 1) arguments. This has to be in
returned. This has to be in sync with `create_gsubr ()'. */ sync with `create_gsubr ()'. */
#define SCM_SUBR_ARITY_TO_TYPE(req, opt, rest) \ #define SCM_SUBR_ARITY_TO_TYPE(req, opt, rest) \
((rest) == 0 \ ((rest) == 0 \
? ((opt) == 0 \ ? ((opt) == 0 \
? ((req) == 0 \ ? ((req) == 0 \
? scm_tc7_subr_0 \ ? scm_tc7_subr_0 \
: ((req) == 1 \ : ((req) == 1 \
? scm_tc7_subr_1 \ ? scm_tc7_subr_1 \
: ((req) == 2 \ : ((req) == 2 \
? scm_tc7_subr_2 \ ? scm_tc7_subr_2 \
: ((req) == 3 \ : ((req) == 3 \
? scm_tc7_subr_3 \ ? scm_tc7_subr_3 \
: -1)))) \ : scm_tc7_gsubr \
: ((opt) == 1 \ | (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U))))) \
? ((req) == 0 \ : ((opt) == 1 \
? scm_tc7_subr_1o \ ? ((req) == 0 \
: ((req) == 1 \ ? scm_tc7_subr_1o \
? scm_tc7_subr_2o \ : ((req) == 1 \
: -1)) \ ? scm_tc7_subr_2o \
: -1)) \ : scm_tc7_gsubr | \
: ((rest) == 1 \ (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U))) \
? ((opt) == 0 \ : scm_tc7_gsubr | \
? ((req) == 0 \ (SCM_GSUBR_MAKTYPE (req, opt, rest) << 8U))) \
? scm_tc7_lsubr \ : ((rest) == 1 \
: ((req) == 2 \ ? ((opt) == 0 \
? scm_tc7_lsubr_2 \ ? ((req) == 0 \
: -1)) \ ? scm_tc7_lsubr \
: -1) \ : ((req) == 2 \
: -1)) ? 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)))

View file

@ -97,8 +97,8 @@ SCM_SNARF_DOCS(primitive, FNAME, PRIMNAME, ARGLIST, REQ, OPT, VAR, DOCSTRING)
#ifdef SCM_SUPPORT_STATIC_ALLOCATION #ifdef SCM_SUPPORT_STATIC_ALLOCATION
/* Regular "subrs", i.e., few arguments. */ /* Static subr allocation. */
#define SCM_DEFINE_SUBR(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \ #define SCM_DEFINE(FNAME, PRIMNAME, REQ, OPT, VAR, ARGLIST, DOCSTRING) \
SCM_SYMBOL (scm_i_paste (FNAME, __name), PRIMNAME); \ SCM_SYMBOL (scm_i_paste (FNAME, __name), PRIMNAME); \
SCM_SNARF_HERE( \ SCM_SNARF_HERE( \
static const char scm_i_paste (s_, FNAME) [] = PRIMNAME; \ 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) 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 */ #else /* !SCM_SUPPORT_STATIC_ALLOCATION */
/* Always use the generic subr case. */ /* Always use the generic subr case. */