aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/target/jvm/class.lux
blob: cd459643a1f7c7f7559f896e582291123a9acdd5 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(.using
 [library
  [lux {"-" Type public private}
   [abstract
    [equivalence {"+" Equivalence}]
    ["[0]" monad {"+" do}]]
   [control
    ["[0]" state]
    ["[0]" try {"+" Try}]]
   [data
    ["[0]" product]
    [format
     ["[0]F" binary {"+" Writer} ("[1]#[0]" monoid)]]
    [collection
     ["[0]" sequence {"+" Sequence}]]]]]
 ["[0]" // "_"
  ["[1][0]" modifier {"+" Modifier modifiers:}]
  ["[1][0]" version {"+" Version Minor Major}]
  ["[1][0]" magic {"+" Magic}]
  ["[1][0]" index {"+" Index}]
  ["[1][0]" attribute {"+" Attribute}]
  ["[1][0]" field {"+" Field}]
  ["[1][0]" method {"+" Method}]
  [encoding
   ["[1][0]" unsigned]
   ["[1][0]" name {"+" Internal}]]
  ["[1][0]" type {"+" Type}
   [category {"+" Inheritance}]
   ["[2][0]" signature {"+" Signature}]]
  ["[1][0]" constant {"+" Constant}
   ["[2][0]" pool {"+" Pool Resource}]]])

(type: .public Class
  (Rec Class
    (Record
     [#magic Magic
      #minor_version Minor
      #major_version Major
      #constant_pool Pool
      #modifier (Modifier Class)
      #this (Index //constant.Class)
      #super (Index //constant.Class)
      #interfaces (Sequence (Index //constant.Class))
      #fields (Sequence Field)
      #methods (Sequence Method)
      #attributes (Sequence Attribute)])))

(modifiers: Class
  ["0001" public]
  ["0010" final]
  ["0020" super]
  ["0200" interface]
  ["0400" abstract]
  ["1000" synthetic]
  ["2000" annotation]
  ["4000" enum]
  )

(def: .public equivalence
  (Equivalence Class)
  (all product.equivalence
       //unsigned.equivalence
       //unsigned.equivalence
       //unsigned.equivalence
       //pool.equivalence
       //modifier.equivalence
       //index.equivalence
       //index.equivalence
       (sequence.equivalence //index.equivalence)
       (sequence.equivalence //field.equivalence)
       (sequence.equivalence //method.equivalence)
       (sequence.equivalence //attribute.equivalence)))

(def: (install_classes this super interfaces)
  (-> Internal Internal (List Internal)
      (Resource [(Index //constant.Class) (Index //constant.Class) (Sequence (Index //constant.Class))]))
  (do [! //pool.monad]
    [@this (//pool.class this)
     @super (//pool.class super)
     @interfaces (is (Resource (Sequence (Index //constant.Class)))
                     (monad.mix ! (function (_ interface @interfaces)
                                    (do !
                                      [@interface (//pool.class interface)]
                                      (in (sequence.suffix @interface @interfaces))))
                                sequence.empty
                                interfaces))]
    (in [@this @super @interfaces])))

(def: .public (class version modifier
                     this signature super interfaces
                     fields methods attributes)
  (-> Major (Modifier Class)
      Internal (Maybe (Signature Inheritance)) Internal (List Internal)
      (List (Resource Field))
      (List (Resource Method))
      (Sequence Attribute)
      (Try Class))
  (do try.monad
    [[pool [@this @super @interfaces] =fields =methods @signature]
     (<| (state.result' //pool.empty)
         (do [! //pool.monad]
           [classes (install_classes this super interfaces)
            =fields (monad.all ! fields)
            =methods (monad.all ! methods)
            @signature (case signature
                         {.#Some signature}
                         (# ! each (|>> {.#Some}) (//attribute.signature signature))

                         {.#None}
                         (in {.#None}))]
           (in [classes =fields =methods @signature])))]
    (in [#magic //magic.code
         #minor_version //version.default_minor
         #major_version version
         #constant_pool pool
         #modifier modifier
         #this @this
         #super @super
         #interfaces @interfaces
         #fields (sequence.of_list =fields)
         #methods (sequence.of_list =methods)
         #attributes (case @signature
                       {.#Some @signature}
                       (sequence.suffix @signature attributes)

                       {.#None}
                       attributes)])))

(def: .public (writer class)
  (Writer Class)
  (`` (all binaryF#composite
           (~~ (template [<writer> <slot>]
                 [(<writer> (the <slot> class))]

                 [//magic.writer #magic]
                 [//version.writer #minor_version]
                 [//version.writer #major_version]
                 [//pool.writer #constant_pool]
                 [//modifier.writer #modifier]
                 [//index.writer #this]
                 [//index.writer #super]))
           (~~ (template [<writer> <slot>]
                 [((binaryF.sequence_16 <writer>) (the <slot> class))]

                 [//index.writer #interfaces]
                 [//field.writer #fields]
                 [//method.writer #methods]
                 [//attribute.writer #attributes]
                 ))
           )))