summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-10-05 01:47:39 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-10-05 01:47:39 -0700
commit5c50205c0f025bae07e813f8374649759b2e825a (patch)
tree380d0b2e3c26040486da76c819656a998fd8c283
parent8ec4ac6b8a529489158a9a8346c1bb0f33ea2b8a (diff)
downloadtxr-5c50205c0f025bae07e813f8374649759b2e825a.tar.gz
txr-5c50205c0f025bae07e813f8374649759b2e825a.tar.bz2
txr-5c50205c0f025bae07e813f8374649759b2e825a.zip
defstruct: refactor elimination of empty :init/:fini.
* stdlib/struct.tl (defstruct): When an :init, :fini, :postinit or :postfini has an empty body, do not push it onto its corresponding list. Then later we don't have to check for empty items when generating the code; we know only non-empty items are on the lists.
-rw-r--r--stdlib/struct.tl36
1 files changed, 18 insertions, 18 deletions
diff --git a/stdlib/struct.tl b/stdlib/struct.tl
index 2955af7c..6fc4a35f 100644
--- a/stdlib/struct.tl
+++ b/stdlib/struct.tl
@@ -83,22 +83,26 @@
(:init
(unless (bindable arg)
(sys:bad-slot-syntax form slot))
- (push (cons arg body) instance-init-forms)
+ (if body
+ (push (cons arg body) instance-init-forms))
^((,word nil nil)))
(:postinit
(unless (bindable arg)
(sys:bad-slot-syntax form slot))
- (push (cons arg body) instance-postinit-forms)
+ (if body
+ (push (cons arg body) instance-postinit-forms))
^((,word nil nil)))
(:fini
(unless (bindable arg)
(sys:bad-slot-syntax form slot))
- (push (cons arg body) instance-fini-forms)
+ (if body
+ (push (cons arg body) instance-fini-forms))
^((,word nil nil)))
(:postfini
(unless (bindable arg)
(sys:bad-slot-syntax form slot))
- (push (cons arg body) instance-postfini-forms)
+ (if body
+ (push (cons arg body) instance-postfini-forms))
^((,word nil nil)))
(t (when body
(sys:bad-slot-syntax form slot))
@@ -160,24 +164,21 @@
instance-fini-forms instance-postfini-forms)
^(lambda (,arg-sym)
,*(append-each ((iff (nreverse instance-fini-forms)))
- (if (cdr iff)
- ^((finalize ,arg-sym (sys:meth-lambda ,name :fini (,(car iff))
- ,*(cdr iff))
- t))))
+ ^((finalize ,arg-sym (sys:meth-lambda ,name :fini (,(car iff))
+ ,*(cdr iff))
+ t)))
,*(append-each ((ipf (nreverse instance-postfini-forms)))
- (if (cdr ipf)
- ^((finalize ,arg-sym (sys:meth-lambda ,name :postfini (,(car ipf))
- ,*(cdr ipf))))))
+ ^((finalize ,arg-sym (sys:meth-lambda ,name :postfini (,(car ipf))
+ ,*(cdr ipf)))))
,*(if inst-si-forms
^((let ((,type-sym (struct-type ,arg-sym)))
,*(mapcar (aret ^(unless (static-slot-p ,type-sym ',@2)
(slotset ,arg-sym ',@2 ,@3)))
inst-si-forms))))
,*(append-each ((iif (nreverse instance-init-forms)))
- (if (cdr iif)
- ^((symacrolet ((%fun% '(,name :init)))
- (let ((,(car iif) ,arg-sym))
- ,*(cdr iif))))))))
+ ^((symacrolet ((%fun% '(,name :init)))
+ (let ((,(car iif) ,arg-sym))
+ ,*(cdr iif)))))))
,(when args
(when (> (countql : args) 1)
(compile-error form
@@ -201,9 +202,8 @@
,(if instance-postinit-forms
^(sys:meth-lambda ,name :postinit (,arg-sym)
,*(append-each ((ipf (nreverse instance-postinit-forms)))
- (if (cdr ipf)
- ^((let ((,(car ipf) ,arg-sym))
- ,*(cdr ipf))))))))))))))
+ ^((let ((,(car ipf) ,arg-sym))
+ ,*(cdr ipf)))))))))))))
(defmacro sys:struct-lit (name . plist)
^(sys:make-struct-lit ',name ',plist))