diff --git a/libguile/ChangeLog b/libguile/ChangeLog index d7f416bf3..a155e3f38 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,7 @@ +2003-04-27 Dirk Herrmann + + * eval.c (scm_ilookup): Rewritten to improve readability. + 2003-04-27 Dirk Herrmann * eval.c (scm_i_call_closure_0, call_closure_1, call_closure_2): diff --git a/libguile/eval.c b/libguile/eval.c index e7ebaa13b..a4905dbc8 100644 --- a/libguile/eval.c +++ b/libguile/eval.c @@ -132,21 +132,35 @@ char *alloca (); SCM_REC_MUTEX (source_mutex); + +/* Lookup a given local variable in an environment. The local variable is + * given as an iloc, that is a triple , where frame + * indicates the relative number of the environment frame (counting upwards + * from the innermost environment frame), binding indicates the number of the + * binding within the frame, and last? (which is extracted from the iloc using + * the macro SCM_ICDRP) indicates whether the binding forms the binding at the + * very end of the improper list of bindings. */ SCM * scm_ilookup (SCM iloc, SCM env) { - register long ir = SCM_IFRAME (iloc); - register SCM er = env; - for (; 0 != ir; --ir) - er = SCM_CDR (er); - er = SCM_CAR (er); - for (ir = SCM_IDIST (iloc); 0 != ir; --ir) - er = SCM_CDR (er); + unsigned int frame_nr = SCM_IFRAME (iloc); + unsigned int binding_nr = SCM_IDIST (iloc); + SCM frames = env; + SCM bindings; + + for (; 0 != frame_nr; --frame_nr) + frames = SCM_CDR (frames); + + bindings = SCM_CAR (frames); + for (; 0 != binding_nr; --binding_nr) + bindings = SCM_CDR (bindings); + if (SCM_ICDRP (iloc)) - return SCM_CDRLOC (er); - return SCM_CARLOC (SCM_CDR (er)); + return SCM_CDRLOC (bindings); + return SCM_CARLOC (SCM_CDR (bindings)); } + /* The Lookup Car Race - by Eva Luator