diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-11-10 15:54:11 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-11-10 15:54:11 -0800 |
commit | b41bdc04f6ce6a595fb17e6de39c82770384cb55 (patch) | |
tree | 22e4d59eaaf4a88e72924af30adeb2310c9d2f6f /match.c | |
parent | f9d713f3fc2fbd1c3ead07121b3bc39f5088a7d7 (diff) | |
download | txr-b41bdc04f6ce6a595fb17e6de39c82770384cb55.tar.gz txr-b41bdc04f6ce6a595fb17e6de39c82770384cb55.tar.bz2 txr-b41bdc04f6ce6a595fb17e6de39c82770384cb55.zip |
Task #11583
More generic approach.
* match.c (h_bind): Function removed.
(hv_trampoline): New function.
(dir_tables_init): hv_trampoline installed in
h_directive_table instead of h_bind.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -2423,16 +2423,25 @@ static val v_bind(match_files_ctx *c) return next_spec_k; } -static val h_bind(match_line_ctx c, match_line_ctx *cout) +static val hv_trampoline(match_line_ctx c, match_line_ctx *cout) { val ret; match_files_ctx mf = mf_from_ml(c); - ret = v_bind(&mf); - if (ret == next_spec_k) { - c.bindings = mf.bindings; - *cout = c; + val sym = first(first(c.specline)); + val entry = gethash(v_directive_table, sym); + + if (!entry) + internal_error("hv_trampoline: missing dispatch table entry"); + + { + v_match_func vmf = (v_match_func) cptr_get(entry); + ret = vmf(&mf); + if (ret == next_spec_k) { + c.bindings = mf.bindings; + *cout = c; + } + return ret; } - return ret; } static val v_set(match_files_ctx *c) @@ -3163,7 +3172,7 @@ static void dir_tables_init(void) sethash(h_directive_table, var_s, cptr((mem_t *) h_var)); sethash(h_directive_table, skip_s, cptr((mem_t *) h_skip)); sethash(h_directive_table, coll_s, cptr((mem_t *) h_coll)); - sethash(h_directive_table, bind_s, cptr((mem_t *) h_bind)); + sethash(h_directive_table, bind_s, cptr((mem_t *) hv_trampoline)); sethash(h_directive_table, some_s, cptr((mem_t *) h_parallel)); sethash(h_directive_table, all_s, cptr((mem_t *) h_parallel)); sethash(h_directive_table, none_s, cptr((mem_t *) h_parallel)); |