rev: 08a0786d94a50b3b229836c53a03976f10ab6bd7 scopes/lib/scopes/property.sc -rw-r--r-- 1.6 KiB View raw Log this file
08a0786d94a5Shawn Walker-Salas * drop number sections in menu due to readthedocs theme incompatibility 19 days ago
                                                                                
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#
    The Scopes Compiler Infrastructure
    This file is distributed under the MIT License.
    See LICENSE.md for details.

""""property
    ========

    Provides a property accessor for types.

typedef Property

@@ memo
inline property (getter setter)
    @@ memo
    inline property-type (T key)
        typedef (.. (tostring T) "." (tostring key)) < Property :: (storageof T)

            define value-type
                fn test-getter (value)
                    getter value
                let F = (static-typify test-getter T)
                unqualified (returnof (typeof F))

            inline get (self)
                getter (bitcast (view self) T)

            inline __imply (cls destT)
                static-if (destT == immutable) get
                elseif (imply? value-type destT)
                    inline (self)
                        imply (get self) destT

            inline __unpack (self)
                unpack (get self)

            inline __typecall (cls value)
                bitcast (view value) cls

            inline __getattr (self key)
                getattr (get self) key

            inline __toptr (self)
                & (get self)

            inline __toref (self)
                @ (get self)

            inline __methodcall (name self ...)
                name (get self) ...

            inline __= (cls destT)
                inline (self value)
                    setter (bitcast (view self) T) value

    Accessor
        inline "generate-property" (value key)
            (property-type (typeof value) key) value

do
    let property Property
    locals;