summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-02-20 18:52:14 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-02-20 18:52:14 -0800
commit0a5a7ea1469d2a3677349017e09ee52d8f70dc29 (patch)
tree09273a086b38fe5849081ff9d6cba78898dc5e86
parent633d1a10a7509e052571ea3db6f44157e6620326 (diff)
downloadtxr-0a5a7ea1469d2a3677349017e09ee52d8f70dc29.tar.gz
txr-0a5a7ea1469d2a3677349017e09ee52d8f70dc29.tar.bz2
txr-0a5a7ea1469d2a3677349017e09ee52d8f70dc29.zip
Eliminate common code: pattern fun binding resolution.
* match.c (fun_resolve_bindings): New static function. (h_fun, v_fun): Replace common code with a call to fun_resolve_binding.
-rw-r--r--match.c73
1 files changed, 37 insertions, 36 deletions
diff --git a/match.c b/match.c
index b8e1f1b4..6dada049 100644
--- a/match.c
+++ b/match.c
@@ -1232,6 +1232,33 @@ static val h_trailer(match_line_ctx *c)
return ret;
}
+static val fun_resolve_bindings(val bindings, val ub_p_a_pairs,
+ val new_bindings, val sym, val elem)
+{
+ val piter;
+
+ for (piter = ub_p_a_pairs; piter; piter = cdr(piter))
+ {
+ cons_bind (param, arg, car(piter));
+
+ if (symbolp(arg)) {
+ val newbind = tx_lookup_var(param, new_bindings);
+ if (newbind) {
+ bindings = dest_bind(elem, bindings, arg, cdr(newbind), equal_f);
+ if (bindings == t) {
+ debuglf(elem,
+ lit("binding mismatch on ~a "
+ "when returning from ~a"), arg, sym, nao);
+ break;
+ }
+ }
+ }
+ }
+
+ return bindings;
+}
+
+
static val h_fun(match_line_ctx *c)
{
val elem = first(c->specline);
@@ -1290,24 +1317,11 @@ static val h_fun(match_line_ctx *c)
{
cons_bind (new_bindings, success, result);
- for (piter = ub_p_a_pairs; piter; piter = cdr(piter))
- {
- cons_bind (param, arg, car(piter));
-
- if (symbolp(arg)) {
- val newbind = tx_lookup_var(param, new_bindings);
- if (newbind) {
- c->bindings = dest_bind(elem, c->bindings,
- arg, cdr(newbind), equal_f);
- if (c->bindings == t) {
- debuglf(elem,
- lit("binding mismatch on ~a "
- "when returning from ~a"), arg, sym, nao);
- return nil;
- }
- }
- }
- }
+ c->bindings = fun_resolve_bindings(c->bindings, ub_p_a_pairs,
+ new_bindings, sym, elem);
+
+ if (c->bindings == t)
+ return nil;
c->pos = minus(success, c->base);
}
@@ -3961,24 +3975,11 @@ static val v_fun(match_files_ctx *c)
{
cons_bind (new_bindings, success, result);
- for (piter = ub_p_a_pairs; piter; piter = cdr(piter))
- {
- cons_bind (param, arg, car(piter));
-
- if (symbolp(arg)) {
- val newbind = tx_lookup_var(param, new_bindings);
- if (newbind) {
- c->bindings = dest_bind(specline, c->bindings,
- arg, cdr(newbind), equal_f);
- if (c->bindings == t) {
- debuglf(specline,
- lit("binding mismatch on ~a "
- "when returning from ~a"), arg, sym, nao);
- return nil;
- }
- }
- }
- }
+ c->bindings = fun_resolve_bindings(c->bindings, ub_p_a_pairs,
+ new_bindings, sym, specline);
+
+ if (c->bindings == t)
+ return nil;
if (consp(success)) {
debuglf(specline,