summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-07 19:20:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-07 19:20:59 -0700
commitafdedf2289b5462b76d8a48e6c2d6f7c653f664d (patch)
tree487ca1e5892b4c0b87722aec35c69138bd90a149 /share
parent957f80f26807582927fa580c705e9aa59327771d (diff)
downloadtxr-afdedf2289b5462b76d8a48e6c2d6f7c653f664d.tar.gz
txr-afdedf2289b5462b76d8a48e6c2d6f7c653f664d.tar.bz2
txr-afdedf2289b5462b76d8a48e6c2d6f7c653f664d.zip
New rslot macro to suport upcoming awk macro.
This provides a way to create lexical macros denoting slots, such that method are invoked when they are updated. * lisplib.c (struct_set_entries): Add rslot to list of auto-load symbols for struct.tl module. * share/txr/stdlib/struct.tl (sys:rslotset): New function. (rslot, rslot): New macro and place macro. (sys:rslot): New place kind.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/struct.tl27
1 files changed, 27 insertions, 0 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl
index 2f9dcfb4..9b37ae0b 100644
--- a/share/txr/stdlib/struct.tl
+++ b/share/txr/stdlib/struct.tl
@@ -255,3 +255,30 @@
(ret ^(,@1 (slot ,obj-sym ',@1)))]
slot-specs))
,*body))))
+
+(macro-time
+ (defun sys:rslotset (struct sym meth-sym val)
+ (slotset struct sym val)
+ (call (umethod meth-sym) struct)))
+
+(defmacro rslot (struct sym meth-sym)
+ ^(slot ,struct ,sym))
+
+(define-place-macro rslot (struct sym meth-sym)
+ ^(sys:rslot ,struct ,sym ,meth-sym))
+
+(defplace (sys:rslot struct sym meth-sym) body
+ (getter setter
+ (with-gensyms (struct-sym slot-sym meth-sym)
+ ^(rlet ((,struct-sym ,struct)
+ (,slot-sym ,sym)
+ (,meth-sym ,meth-sym))
+ (macrolet ((,getter () ^(slot ,',struct-sym ,',slot-sym))
+ (,setter (val) ^(sys:rslotset ,',struct-sym
+ ,',slot-sym ,val)))
+ ,body))))
+ (ssetter
+ ^(macrolet ((,ssetter (val) ^(progn
+ (sys:rslotset ,',struct ,',sym
+ ,',meth-sym ,val))))
+ ,body)))