From e0bede31f0094f6e2b4893a9db726fa67ca84ad4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 18 Jun 2015 06:35:09 -0700 Subject: Library .txr files become .tl and are autoloaded. * lisplib.c (ver_set_entries, ver_instantiate, txr_case_set_entries, txr_case_instantiate): New static functions. (lisplib_init): Register new functions. * share/txr/stdlib/txr-case.txr: Reduced to a load for the corresponding .tl file, retained for backward compatibility. * share/txr/stdlib/ver.txr: Likewise. * share/txr/stdlib/txr-case.tl: New file, based on previous contents of corresponding .txr file. * share/txr/stdlib/ver.tl: Likewise. --- ChangeLog | 19 +++++++++++++++++++ lisplib.c | 30 ++++++++++++++++++++++++++++++ share/txr/stdlib/txr-case.tl | 41 +++++++++++++++++++++++++++++++++++++++++ share/txr/stdlib/txr-case.txr | 43 +------------------------------------------ share/txr/stdlib/ver.tl | 1 + share/txr/stdlib/ver.txr | 2 +- 6 files changed, 93 insertions(+), 43 deletions(-) create mode 100644 share/txr/stdlib/txr-case.tl create mode 100644 share/txr/stdlib/ver.tl diff --git a/ChangeLog b/ChangeLog index 92fa7aaa..a499a76a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2015-06-18 Kaz Kylheku + + Library .txr files become .tl and are autoloaded. + + * lisplib.c (ver_set_entries, ver_instantiate, + txr_case_set_entries, txr_case_instantiate): New + static functions. + (lisplib_init): Register new functions. + + * share/txr/stdlib/txr-case.txr: Reduced to a load for the + corresponding .tl file, retained for backward compatibility. + + * share/txr/stdlib/ver.txr: Likewise. + + * share/txr/stdlib/txr-case.tl: New file, based on previous + contents of corresponding .txr file. + + * share/txr/stdlib/ver.tl: Likewise. + 2015-06-17 Kaz Kylheku Adding anaphoric ifa macro. diff --git a/lisplib.c b/lisplib.c index b6a15203..f84b47b6 100644 --- a/lisplib.c +++ b/lisplib.c @@ -83,6 +83,20 @@ static val place_instantiate(val set_fun) colon_k, lit("place.tl")), nil); } +static val ver_set_entries(val dlt, val fun) +{ + val name[] = { lit("*lib-version*"), nil }; + set_dlt_entries(dlt, name, fun); + return nil; +} + +static val ver_instantiate(val set_fun) +{ + funcall1(set_fun, nil); + load(format(nil, lit("~a/ver.tl"), stdlib_path, nao)); + return nil; +} + static val ifa_set_entries(val dlt, val fun) { val name[] = { lit("ifa"), nil }; @@ -97,6 +111,20 @@ static val ifa_instantiate(val set_fun) return nil; } +static val txr_case_set_entries(val dlt, val fun) +{ + val name[] = { lit("txr-if"), lit("txr-when"), lit("txr-case"), nil }; + set_dlt_entries(dlt, name, fun); + return nil; +} + +static val txr_case_instantiate(val set_fun) +{ + funcall1(set_fun, nil); + load(format(nil, lit("~a/txr-case.tl"), stdlib_path, nao)); + return nil; +} + static val dlt_register(val dlt, val (*instantiate)(val), val (*set_entries)(val, val)) @@ -109,7 +137,9 @@ void lisplib_init(void) prot1(&dl_table); dl_table = make_hash(nil, nil, nil); dlt_register(dl_table, place_instantiate, place_set_entries); + dlt_register(dl_table, ver_instantiate, ver_set_entries); dlt_register(dl_table, ifa_instantiate, ifa_set_entries); + dlt_register(dl_table, txr_case_instantiate, txr_case_set_entries); } val lisplib_try_load(val sym) diff --git a/share/txr/stdlib/txr-case.tl b/share/txr/stdlib/txr-case.tl new file mode 100644 index 00000000..2e0c5979 --- /dev/null +++ b/share/txr/stdlib/txr-case.tl @@ -0,0 +1,41 @@ +(defmacro txr-if (name args input : then else) + (let ((syms (keep-if [andf true symbolp [notf keywordp] [notf (op eq t)]] + args)) + (arg-exprs [mapcar [iffi symbolp (ret ^',@1)] args]) + (result (gensym "res-")) + (bindings (gensym "bindings-")) + (insym (gensym "input-"))) + ^(let* ((,insym ,input) + (,result (match-fun ',name (list ,*arg-exprs) + (if (stringp ,insym) (list ,insym) ,insym) + nil))) + (if ,result + (let ((,bindings (car ,result))) + (let (,*[mapcar (ret ^(,@1 (cdr (assoc ',@1 ,bindings)))) + syms]) + ,then)) + ,else)))) + +(defmacro txr-when (name args input . body) + ^(txr-if ,name ,args ,input (progn ,*body))) + +(defmacro txr-case-impl (sym . clauses) + (tree-case clauses + (((name args . body) . other-clauses) + (if (eq name t) : + ^(txr-if ,name ,args ,sym + (progn ,*body) + (txr-case-impl ,sym ,*other-clauses)))) + (((sym . rest) . other-clauses) + (if (eq sym t) + (if other-clauses + (error "txr-case: clauses after (t ...) clause ignored") + ^(progn ,*rest)) + (error "txr-case: bad syntax: ~s" (car clauses)))) + (atom + (error "txr-case: unexpected atom in syntax: ~s" atom)))) + +(defmacro txr-case (input-expr . clauses) + (let ((input (gensym "input-"))) + ^(let ((,input ,input-expr)) + (txr-case-impl ,input ,*clauses)))) diff --git a/share/txr/stdlib/txr-case.txr b/share/txr/stdlib/txr-case.txr index 12321a31..9b65d1bc 100644 --- a/share/txr/stdlib/txr-case.txr +++ b/share/txr/stdlib/txr-case.txr @@ -1,42 +1 @@ -@(do - (defmacro txr-if (name args input : then else) - (let ((syms (keep-if [andf true symbolp [notf keywordp] [notf (op eq t)]] - args)) - (arg-exprs [mapcar [iffi symbolp (ret ^',@1)] args]) - (result (gensym "res-")) - (bindings (gensym "bindings-")) - (insym (gensym "input-"))) - ^(let* ((,insym ,input) - (,result (match-fun ',name (list ,*arg-exprs) - (if (stringp ,insym) (list ,insym) ,insym) - nil))) - (if ,result - (let ((,bindings (car ,result))) - (let (,*[mapcar (ret ^(,@1 (cdr (assoc ',@1 ,bindings)))) - syms]) - ,then)) - ,else)))) - - (defmacro txr-when (name args input . body) - ^(txr-if ,name ,args ,input (progn ,*body))) - - (defmacro txr-case-impl (sym . clauses) - (tree-case clauses - (((name args . body) . other-clauses) - (if (eq name t) : - ^(txr-if ,name ,args ,sym - (progn ,*body) - (txr-case-impl ,sym ,*other-clauses)))) - (((sym . rest) . other-clauses) - (if (eq sym t) - (if other-clauses - (error "txr-case: clauses after (t ...) clause ignored") - ^(progn ,*rest)) - (error "txr-case: bad syntax: ~s" (car clauses)))) - (atom - (error "txr-case: unexpected atom in syntax: ~s" atom)))) - - (defmacro txr-case (input-expr . clauses) - (let ((input (gensym "input-"))) - ^(let ((,input ,input-expr)) - (txr-case-impl ,input ,*clauses))))) +@(load "txr-case.tl") diff --git a/share/txr/stdlib/ver.tl b/share/txr/stdlib/ver.tl new file mode 100644 index 00000000..85221ca0 --- /dev/null +++ b/share/txr/stdlib/ver.tl @@ -0,0 +1 @@ +(defvar *lib-version* 108) diff --git a/share/txr/stdlib/ver.txr b/share/txr/stdlib/ver.txr index 18a987e7..2339bda7 100644 --- a/share/txr/stdlib/ver.txr +++ b/share/txr/stdlib/ver.txr @@ -1 +1 @@ -@(do (defvar *lib-version* 108)) +@(load "ver.tl") -- cgit v1.2.3