summaryrefslogtreecommitdiffstats
path: root/tests/012
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-10-04 22:30:36 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-10-04 22:30:36 -0700
commitbf35c239b435fa34bf3e5b1b286d66ecfbd7ca0a (patch)
treee24e8b3ad308a1822c1c0b2d29ccd59255f80b5f /tests/012
parent9c1e2974fad18576c0051d046f03d799d2879fdc (diff)
downloadtxr-bf35c239b435fa34bf3e5b1b286d66ecfbd7ca0a.tar.gz
txr-bf35c239b435fa34bf3e5b1b286d66ecfbd7ca0a.tar.bz2
txr-bf35c239b435fa34bf3e5b1b286d66ecfbd7ca0a.zip
oop: allow multiple :init, :fini, etc.
The motivation is that struct clause macros defined using define-struct-clause may want to introduce their own initializers and finalizers for the specific stuff they add to the struct. The uniqueness restrictions on these initializing and finalizing clauses makes it impossible to use two clause macros which both want to inject a definition of the same initializer or finalizer type. * stdlib/struct.tl (defstruct): Don't enforce that there be at most one clause in the category of :init, :postinit, :fini or :postini. Multiple are allowed. They all execute left-to-right except for :fini. * tests/012/fini.tl: New tests. * tests/012/fini.expected: Updated. * txr.1: Documented.
Diffstat (limited to 'tests/012')
-rw-r--r--tests/012/fini.expected8
-rw-r--r--tests/012/fini.tl20
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/012/fini.expected b/tests/012/fini.expected
index a733802b..72fdc948 100644
--- a/tests/012/fini.expected
+++ b/tests/012/fini.expected
@@ -121,3 +121,11 @@ derived:38 derived postfini
derived:39 derived postfini
derived:40 derived postfini
derived:41 derived postfini
+multi :init: 1
+multi :init: 2
+multi :postinit: 1
+multi :postinit: 2
+multi :fini: 2
+multi :fini: 1
+multi :postfini: 1
+multi :postfini: 2
diff --git a/tests/012/fini.tl b/tests/012/fini.tl
index 775f210f..4036b5d4 100644
--- a/tests/012/fini.tl
+++ b/tests/012/fini.tl
@@ -22,3 +22,23 @@
(mapcar (ret (new derived)) (range 1 20))
(sys:gc)
+
+(defstruct multi ()
+ (:init (me)
+ (put-line `@{%fun%}: 1`))
+ (:init (me)
+ (put-line `@{%fun%}: 2`))
+ (:postinit (me)
+ (put-line `@{%fun%}: 1`))
+ (:postinit (me)
+ (put-line `@{%fun%}: 2`))
+ (:fini (me)
+ (put-line `@{%fun%}: 1`))
+ (:fini (me)
+ (put-line `@{%fun%}: 2`))
+ (:postfini (me)
+ (put-line `@{%fun%}: 1`))
+ (:postfini (me)
+ (put-line `@{%fun%}: 2`)))
+
+(with-objects ((m (new multi))))