From b43d605b8986b8ef2edd11abf7ed5b7e4313d318 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 11 Apr 2012 10:58:40 -0700 Subject: Provide access to line number info and source path. * eval.c (eval_init): New intrinsic functions source-loc and source-loc-str. New variable *self-path*. * txr.1: Stub doc sections. * txr.c (self_path): New variable. * txr.h (self_path): Declared. * txr.vim: Syntax highlighting for source-loc, source-loc-str and *self-path*. --- dep.mk | 2 +- eval.c | 6 ++++++ txr.1 | 4 ++++ txr.c | 4 ++++ txr.h | 1 + txr.vim | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dep.mk b/dep.mk index d8a3cfd0..e0ca3429 100644 --- a/dep.mk +++ b/dep.mk @@ -11,7 +11,7 @@ ./hash.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./unwind.h $(top_srcdir)/./stream.h $(top_srcdir)/./hash.h ./utf8.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./unwind.h $(top_srcdir)/./utf8.h ./filter.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./hash.h $(top_srcdir)/./unwind.h $(top_srcdir)/./match.h $(top_srcdir)/./filter.h $(top_srcdir)/./gc.h $(top_srcdir)/./stream.h -./eval.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./unwind.h $(top_srcdir)/./regex.h $(top_srcdir)/./stream.h $(top_srcdir)/./parser.h $(top_srcdir)/./hash.h $(top_srcdir)/./debug.h $(top_srcdir)/./match.h $(top_srcdir)/./rand.h $(top_srcdir)/./filter.h $(top_srcdir)/./eval.h +./eval.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./unwind.h $(top_srcdir)/./regex.h $(top_srcdir)/./stream.h $(top_srcdir)/./parser.h $(top_srcdir)/./hash.h $(top_srcdir)/./debug.h $(top_srcdir)/./match.h $(top_srcdir)/./rand.h $(top_srcdir)/./filter.h $(top_srcdir)/./txr.h $(top_srcdir)/./eval.h ./rand.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./unwind.h $(top_srcdir)/./gc.h $(top_srcdir)/./arith.h $(top_srcdir)/./rand.h mpi-1.8.6/mpi.o: $(top_srcdir)/mpi-1.8.6/../config.h $(top_srcdir)/mpi-1.8.6/mpi.h $(top_srcdir)/mpi-1.8.6/logtab.h mpi-1.8.6/mplogic.o: $(top_srcdir)/mpi-1.8.6/../config.h $(top_srcdir)/mpi-1.8.6/mplogic.h diff --git a/eval.c b/eval.c index 960ca4be..8133c6e5 100644 --- a/eval.c +++ b/eval.c @@ -44,6 +44,7 @@ #include "match.h" #include "rand.h" #include "filter.h" +#include "txr.h" #include "eval.h" typedef val (*opfun_t)(val, val); @@ -2411,6 +2412,11 @@ void eval_init(void) reg_fun(intern(lit("time"), user_package), func_n0(time_sec)); reg_fun(intern(lit("time-usec"), user_package), func_n0(time_sec_usec)); + reg_fun(intern(lit("source-loc"), user_package), func_n1(source_loc)); + reg_fun(intern(lit("source-loc-str"), user_package), func_n1(source_loc_str)); + + reg_var(intern(lit("*self-path*"), user_package), &self_path); + eval_error_s = intern(lit("eval-error"), user_package); uw_register_subtype(eval_error_s, error_s); } diff --git a/txr.1 b/txr.1 index 1507eada..a62a3d41 100644 --- a/txr.1 +++ b/txr.1 @@ -7562,6 +7562,10 @@ Examples: .SS Functions time and time-usec +.SS Functions source-loc and source-loc-str + +.SS Variable *self-path* + .SH DEBUGGER .B TXR diff --git a/txr.c b/txr.c index d07b98a6..80b93836 100644 --- a/txr.c +++ b/txr.c @@ -46,6 +46,7 @@ const wchli_t *version = wli("64"); const wchar_t *progname = L"txr"; const wchar_t *spec_file = L"stdin"; +val self_path; /* * Can implement an emergency allocator here from a fixed storage @@ -173,6 +174,7 @@ int txr_main(int argc, char **argv) int match_loglevel = opt_loglevel; prot1(&spec_file_str); + prot1(&self_path); yyin_stream = std_input; @@ -429,6 +431,8 @@ int txr_main(int argc, char **argv) format(std_error, lit("bindings:\n~s\n"), bindings, nao); } + self_path = spec_file_str; + { int retval; list_collect_decl(filenames, iter); diff --git a/txr.h b/txr.h index 8f6b7f91..669ceff3 100644 --- a/txr.h +++ b/txr.h @@ -35,3 +35,4 @@ extern int opt_vg_debug; extern int opt_derivative_regex; extern const wchli_t *version; extern const wchar_t *progname; +extern val self_path; diff --git a/txr.vim b/txr.vim index 67cde861..c53730b2 100644 --- a/txr.vim +++ b/txr.vim @@ -93,6 +93,7 @@ syn keyword txl_keyword contained random-fixnum random rand syn keyword txl_keyword contained range range* generate repeat force syn keyword txl_keyword contained throw throwf error match-fun url-encode url-decode syn keyword txl_keyword contained time time-usec +syn keyword txl_keyword contained source-loc source-loc-str syn match txr_error "@[\t ]*[*]\?[\t ]*." syn match txr_nested_error "[^\t `]\+" contained -- cgit v1.2.3