From 9b64a129d691fa3e4a08dacbd6e2c697bb4a857f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 13 Jun 2017 21:03:44 -0700 Subject: bugfix: autoload syntactic places. TXR Lisp doesn't autoload the definition of places. For instance if a (set (foo x) y) appears out of the blue and foo is keyed for autoload, it doesn't happen. The right place to fix this is to do the autload check in the place macro expander, since every place form is tried as a macro. We need to expose the lisplib_try_load function as a Lisp intrinsic. * lisplib.c (lisplib_init): Register sys:try-load intrinsic, mapped to lisplib_try_load. * share/txr/stdlib/place.tl (sys:get-place-macro): New function. (sys:pl-expand): Use sys:get-place-macro instead of direct lookup in *place-macro* hash. The new function tries to autoload the symbol if it finds no place macro for it. --- lisplib.c | 1 + share/txr/stdlib/place.tl | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lisplib.c b/lisplib.c index f8ce2f47..2b57c578 100644 --- a/lisplib.c +++ b/lisplib.c @@ -580,6 +580,7 @@ void lisplib_init(void) dlt_register(dl_table, error_instantiate, error_set_entries); dlt_register(dl_table, keyparams_instantiate, keyparams_set_entries); dlt_register(dl_table, ffi_instantiate, ffi_set_entries); + reg_fun(intern(lit("try-load"), system_package), func_n1(lisplib_try_load)); } val lisplib_try_load(val sym) diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index 1ea1b95c..2e15118b 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -81,11 +81,15 @@ (makunbound ',',place-expr)))) ,*op-body)) + (defun sys:get-place-macro (sym) + (or [*place-macro* sym] + (progn (sys:try-load sym) [*place-macro* sym]))) + (defun sys:pl-expand (unex-place env) (while t (let ((place unex-place)) - (let ((pm-expander [*place-macro* (if (consp unex-place) - (car unex-place))])) + (let ((pm-expander (sys:get-place-macro (if (consp unex-place) + (car unex-place))))) (when pm-expander (sys:setq place (sys:set-macro-ancestor [pm-expander unex-place] -- cgit v1.2.3