diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-29 15:49:33 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-29 15:49:33 -0700 |
commit | adef4143af67eb8874e7013eb2c0b40da2099e5b (patch) | |
tree | f659e252eafbb0e6c074152c077e0c3f29491a57 /share | |
parent | 8f19618313f5e1342177b8580575df5690195e8c (diff) | |
download | txr-adef4143af67eb8874e7013eb2c0b40da2099e5b.tar.gz txr-adef4143af67eb8874e7013eb2c0b40da2099e5b.tar.bz2 txr-adef4143af67eb8874e7013eb2c0b40da2099e5b.zip |
Extend symbol-function accessor to methods.
* eval.c (looup_fun): Handle (meth ...) syntax.
* share/txr/stdlib/place.tl (sys:get-fb): Function
removed.
(sys:get-fun-getter-setter): New function.
(defplace symbol-function): Rework getter and
setter using new function which works for method
as well as regular function bindings.
* txr.1: Documentation updated in several places.
The mention of symbol-function in the list of place
forms altered so it doesn't insinuate that the argument
must be a symbol. Description of symbol-function
updated. Also under the trace and untrace macros,
a note added that tracing methods is possible.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/place.tl | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index c2421c3c..d5fdf778 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -754,16 +754,26 @@ ^(fmakunbound ',',sym))) ,body))) -(defun sys:get-fb (sym) - (or (gethash sys:top-fb sym) - (sys:eval-err "unbound function ~s" sym))) +(defun sys:get-fun-getter-setter (sym) + (tree-case sym + ((type struct slot) + (if (eq type 'meth) + (cons (op static-slot struct slot) + (op static-slot-set struct slot @1)) + :)) + (else + (let ((cell (gethash sys:top-fb sym))) + (unless cell + (sys:eval-err "unbound function ~s" sym)) + (cons (op cdr) + (op sys:rplacd cell @1)))))) (defplace (symbol-function sym-expr) body (getter setter - (with-gensyms (binding-sym) - ^(let ((,binding-sym (sys:get-fb ,sym-expr))) - (macrolet ((,getter () ^(cdr ,',binding-sym)) - (,setter (val) ^(sys:rplacd ,',binding-sym ,val))) + (with-gensyms (gs-sym) + ^(let ((,gs-sym (sys:get-fun-getter-setter ,sym-expr))) + (macrolet ((,getter () ^(call (car ,',gs-sym))) + (,setter (val) ^(call (cdr ,',gs-sym) ,val))) ,body)))) : (deleter |