diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-10-03 22:10:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-10-03 22:10:32 -0700 |
commit | 9c1e2974fad18576c0051d046f03d799d2879fdc (patch) | |
tree | f67f60de1965f70ec4c717486ef4b88871e61ad1 /tests/019 | |
parent | 502543ea94913ec4d4792dbd07151fba22220637 (diff) | |
download | txr-9c1e2974fad18576c0051d046f03d799d2879fdc.tar.gz txr-9c1e2974fad18576c0051d046f03d799d2879fdc.tar.bz2 txr-9c1e2974fad18576c0051d046f03d799d2879fdc.zip |
New: %fun% mechanism for current function name.
* eval.c (pct_fun_s): New symbol variable, holding
the usr:%fun% symbol.
(fun_macro_env): New static function.
(do_expand): For defun and defmacro, use fun_macro_env
to establish an environment binding the %fun% symbol
macro, and expand everything in that environment.
(eval_init): Intern the %fun% symbol, initializing
pct_fun_s, and also register a global symbol macro in
that name so that we can freely use %fun% everywhere
without worrying that the code will blow up.
E.g. a logging macro can use it to get the function name,
but still be useful in a top-level form outside of
a named function.
* stdlib/struct.tl (sys:meth-lambda): New macro.
(defstruct, defmeth): Use sys:meth-lambda as a replacement
for lambda to set up the %fun% symbol macro. In the :init
case which doesn't use a lambda, an open-coded symacrolet
does the job.
* tests/019/pct-fun.tl: New file.
* tests/019/pct-fun.expected: Likewise.
* txr.1: Documented.
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'tests/019')
-rw-r--r-- | tests/019/pct-fun.expected | 18 | ||||
-rw-r--r-- | tests/019/pct-fun.tl | 41 |
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/019/pct-fun.expected b/tests/019/pct-fun.expected new file mode 100644 index 00000000..d7da7ee4 --- /dev/null +++ b/tests/019/pct-fun.expected @@ -0,0 +1,18 @@ +(foo :init) +(foo :postinit) +(foo foo) +(foo bar) +(foo :fini) +(foo :postfini) +function +function2 +mac +(foo :init) +(foo :postinit) +(foo foo) +(foo bar) +(foo :fini) +(foo :postfini) +function +function2 +mac diff --git a/tests/019/pct-fun.tl b/tests/019/pct-fun.tl new file mode 100644 index 00000000..eae0d9bb --- /dev/null +++ b/tests/019/pct-fun.tl @@ -0,0 +1,41 @@ +(load "../common") + +(defstruct foo () + (:init (me) (prinl %fun%)) + (:fini (me) (prinl %fun%)) + (:postinit (me) (prinl %fun%)) + (:postfini (me) (prinl %fun%)) + (:method foo (me) (prinl %fun%))) + +(defmeth foo bar (me) + (prinl %fun%)) + +(defmeth foo pat (:match) + (prinl %fun%)) + +(defun function (: (optarg %fun%)) + (prinl %fun%)) + +(defun function2 (: (optarg %fun%)) + (prinl optarg)) + +(defmacro mac () + (prinl %fun%) + nil) + +(with-objects ((f (new foo))) + f.(foo) + f.(pat) + f.(bar)) + +(function) +(function2) + +(mac) + +(test %fun% nil) + +(compile-only + (eval-only + (compile-file (base-name *load-path*) "temp.tlo") + (remove-path "temp.tlo"))) |