diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-09-26 06:54:56 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-09-26 06:54:56 -0700 |
commit | 77e596fe12ffd0b74159e7b9427108d0fc21300c (patch) | |
tree | 526ccfd51f3738277383228c88f2ef2eb90d62af /eval.c | |
parent | bdf889cb57c44254ea0f2d3b7a06aac3b77b5edb (diff) | |
download | txr-77e596fe12ffd0b74159e7b9427108d0fc21300c.tar.gz txr-77e596fe12ffd0b74159e7b9427108d0fc21300c.tar.bz2 txr-77e596fe12ffd0b74159e7b9427108d0fc21300c.zip |
lookup_fun: eliminate recursion.
* eval.c (lookup_fun); Use iteration to search the nested
environments. Put this code ahead of the global search
so we fall back on it. Also, let's check for a compound
function name first, so we don't search the environments for
this.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 48 |
1 files changed, 24 insertions, 24 deletions
@@ -533,40 +533,40 @@ val lookup_fun(val env, val sym) { uses_or2; - if (nilp(env)) { - if (consp(sym)) { - if (car(sym) == meth_s) { - val strct = cadr(sym); - val slot = caddr(sym); - val type = or2(find_struct_type(strct), - if2(lisplib_try_load(strct), - find_struct_type(strct))); - if (slot == init_k) { - return cons(sym, struct_get_initfun(type)); - } else if (slot == postinit_k) { - return cons(sym, struct_get_postinitfun(type)); - } else { - return if2(and2(type, static_slot_p(type, slot)), - cons(sym, static_slot(type, slot))); - } - } else if (car(sym) == macro_s) { - return lookup_mac(nil, cadr(sym)); + if (consp(sym)) { + if (car(sym) == meth_s) { + val strct = cadr(sym); + val slot = caddr(sym); + val type = or2(find_struct_type(strct), + if2(lisplib_try_load(strct), + find_struct_type(strct))); + if (slot == init_k) { + return cons(sym, struct_get_initfun(type)); + } else if (slot == postinit_k) { + return cons(sym, struct_get_postinitfun(type)); } else { - return nil; + return if2(and2(type, static_slot_p(type, slot)), + cons(sym, static_slot(type, slot))); } + } else if (car(sym) == macro_s) { + return lookup_mac(nil, cadr(sym)); + } else { + return nil; } - return or2(gethash(top_fb, sym), - if2(lisplib_try_load(sym), gethash(top_fb, sym))); - } else { + } + + if (env) { type_check(lit("function lookup"), env, ENV); - { + for (; env; env = env->e.up_env) { val binding = assoc(sym, env->e.fbindings); if (binding) return binding; - return lookup_fun(env->e.up_env, sym); } } + + return or2(gethash(top_fb, sym), + if2(lisplib_try_load(sym), gethash(top_fb, sym))); } val func_get_name(val fun, val env) |