summaryrefslogtreecommitdiffstats
path: root/tests/012/fini.tl
blob: 4036b5d459be8c5b9221ac32ee2683bf7ebb12a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(load "../common")

(defstruct base nil
  others
  id
  (:static counter 0)
  (:postinit (me) (set me.id (inc me.counter)))
  (:fini (me)
    (put-line `@(typeof me):@{me.id} finalized`)
    [mapdo call-finalizers me.others]))

(defstruct derived base
  (:fini (me)
    (put-line `@(typeof me):@{me.id} derived fini`))
  (:postfini (me)
    (put-line `@(typeof me):@{me.id} derived postfini`)))

(unwind-protect
  (with-objects ((b (new base others (mapcar (ret (new derived)) (range 1 20)))))
    (put-line "inside with-objects"))
  (put-line "after with-objects"))

(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))))