From e694dde54a71cad3e2df5b28400aac8c7d564932 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 2 Jan 2016 09:37:27 -0800 Subject: Use last-form-evaled mechanism for pattern language. We need this now, since file system errors aren't handled in the pattern language any more, after the complex_open refactoring. * eval.c (set_last_form_evaled): New function. * eval.h (set_last_form_evaled): Declared. * match.c (do_match_line, match_files): Save, set up and restore last_form_evaled via set_last_form_evaled function. --- eval.c | 7 +++++++ eval.h | 1 + match.c | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/eval.c b/eval.c index c754136d..384408af 100644 --- a/eval.c +++ b/eval.c @@ -228,6 +228,13 @@ static val set_origin(val form, val origin) return form; } +val set_last_form_evaled(val form) +{ + val prev = last_form_evaled; + last_form_evaled = form; + return prev; +} + void error_trace(val exsym, val exvals, val out_stream, val prefix) { val last = last_form_evaled; diff --git a/eval.h b/eval.h index 7edb9eb2..d3e814ad 100644 --- a/eval.h +++ b/eval.h @@ -34,6 +34,7 @@ noreturn val eval_error(val ctx, val fmt, ...); val ctx_form(val obj); val ctx_name(val obj); val lookup_origin(val form); +val set_last_form_evaled(val form); void error_trace(val exsym, val exvals, val out_stream, val prefix); val make_env(val fbindings, val vbindings, val up_env); val copy_env(val oenv); diff --git a/match.c b/match.c index cd57e946..3c78e651 100644 --- a/match.c +++ b/match.c @@ -1229,21 +1229,20 @@ static val v_fun(match_files_ctx *c); static val do_match_line(match_line_ctx *c) { + val lfe_save = set_last_form_evaled(nil); + debug_enter; - for (;;) { - val elem; + while (c->specline) { + val elem = first(c->specline); - if (c->specline == nil) - break; + set_last_form_evaled(elem); if (c->pos == t) c->pos = length_str(c->dataline); consume_prefix(c); - elem = first(c->specline); - debug_check(c->specline, c->bindings, c->dataline, c->data_lineno, c->pos, c->base); @@ -1348,6 +1347,8 @@ static val do_match_line(match_line_ctx *c) debug_return (cons(c->bindings, plus(c->pos, c->base))); debug_leave; + + set_last_form_evaled(lfe_save); } static val match_line(match_line_ctx c) @@ -3882,6 +3883,7 @@ repeat_spec_same_data: debug_check(specline, c.bindings, c.data, c.data_lineno, nil, nil); if (consp(first_spec) && !rest(specline)) { + val lfe_save = set_last_form_evaled(first_spec); val sym = first(first_spec); val entry = gethash(v_directive_table, sym); @@ -3891,6 +3893,8 @@ repeat_spec_same_data: result = vmf(&c); + set_last_form_evaled(lfe_save); + if (result == next_spec_k) { if ((c.spec = rest(c.spec)) == nil) break; @@ -3903,6 +3907,8 @@ repeat_spec_same_data: } else { val result = v_fun(&c); + set_last_form_evaled(lfe_save); + if (result == next_spec_k) { if ((c.spec = rest(c.spec)) == nil) break; -- cgit v1.2.3