diff options
author | Andy Wingo <wingo@pobox.com> | 2011-11-15 23:36:07 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-11-15 23:36:07 +0100 |
commit | f3cf9421cb319e2cb9ffde4ec41cad7fdcafcebc (patch) | |
tree | 57bf3d168cfa8280a727faa2c073bbf2d9fb02e2 /libguile/procprop.c | |
parent | 020602791b3f929e2d65ffdd8d67977763d6883e (diff) | |
download | guile-f3cf9421cb319e2cb9ffde4ec41cad7fdcafcebc.tar.gz |
better debuggability for interpreted procedures
* libguile/procprop.c (scm_set_procedure_minimum_arity_x): New
function, allows a user to override a function's arity.
(scm_i_procedure_arity): Look up in the overrides table first.
* libguile/procprop.h: Add scm_set_procedure_minimum_arity_x.
* module/ice-9/eval.scm (primitive-eval): Override arity of "general
closures".
* test-suite/tests/procprop.test ("procedure-arity"): Add tests.
Based on a patch from Stefan Israelsson Tampe. Test based on work by
Patrick Bernaud.
Diffstat (limited to 'libguile/procprop.c')
-rw-r--r-- | libguile/procprop.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libguile/procprop.c b/libguile/procprop.c index c3fb90e37..8e2cd6a5f 100644 --- a/libguile/procprop.c +++ b/libguile/procprop.c @@ -51,9 +51,25 @@ SCM_GLOBAL_SYMBOL (scm_sym_name, "name"); static SCM overrides; static scm_i_pthread_mutex_t overrides_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER; +static SCM arity_overrides; + int scm_i_procedure_arity (SCM proc, int *req, int *opt, int *rest) { + SCM o; + + scm_i_pthread_mutex_lock (&overrides_lock); + o = scm_hashq_ref (arity_overrides, proc, SCM_BOOL_F); + scm_i_pthread_mutex_unlock (&overrides_lock); + + if (scm_is_true (o)) + { + *req = scm_to_int (scm_car (o)); + *opt = scm_to_int (scm_cadr (o)); + *rest = scm_is_true (scm_caddr (o)); + return 1; + } + while (!SCM_PROGRAM_P (proc)) { if (SCM_IMP (proc)) @@ -74,9 +90,29 @@ scm_i_procedure_arity (SCM proc, int *req, int *opt, int *rest) return 0; } } + return scm_i_program_arity (proc, req, opt, rest); } +SCM_DEFINE (scm_set_procedure_minimum_arity_x, "set-procedure-minimum-arity!", + 4, 0, 0, (SCM proc, SCM req, SCM opt, SCM rest), + "") +#define FUNC_NAME s_scm_set_procedure_minimum_arity_x +{ + int t SCM_UNUSED; + + SCM_VALIDATE_PROC (1, proc); + SCM_VALIDATE_INT_COPY (2, req, t); + SCM_VALIDATE_INT_COPY (3, opt, t); + SCM_VALIDATE_BOOL (4, rest); + + scm_i_pthread_mutex_lock (&overrides_lock); + scm_hashq_set_x (arity_overrides, proc, scm_list_3 (req, opt, rest)); + scm_i_pthread_mutex_unlock (&overrides_lock); + return SCM_UNDEFINED; +} +#undef FUNC_NAME + SCM_DEFINE (scm_procedure_minimum_arity, "procedure-minimum-arity", 1, 0, 0, (SCM proc), "Return the \"minimum arity\" of a procedure.\n\n" @@ -207,6 +243,7 @@ void scm_init_procprop () { overrides = scm_make_weak_key_hash_table (SCM_UNDEFINED); + arity_overrides = scm_make_weak_key_hash_table (SCM_UNDEFINED); #include "libguile/procprop.x" } |