aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/target/jvm/field.lux
blob: aa71794a5c12eda066f2e6bff8480040c197cebd (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
(.module:
  [library
   [lux (#- Type static)
    [abstract
     [equivalence (#+ Equivalence)]
     ["." monad (#+ do)]]
    [data
     ["." product]
     [format
      [".F" binary (#+ Writer) ("#\." monoid)]]
     [collection
      ["." row (#+ Row)]]]]]
  ["." // #_
   ["." modifier (#+ Modifier modifiers:)]
   ["#." constant (#+ UTF8)
    ["#/." pool (#+ Pool Resource)]]
   ["#." index (#+ Index)]
   ["#." attribute (#+ Attribute)]
   ["#." type (#+ Type)
    [category (#+ Value)]
    [descriptor (#+ Descriptor)]]])

(type: #export #rec Field
  {#modifier (Modifier Field)
   #name (Index UTF8)
   #descriptor (Index (Descriptor Value))
   #attributes (Row Attribute)})

(modifiers: Field
  ["0001" public]
  ["0002" private]
  ["0004" protected]
  ["0008" static]
  ["0010" final]
  ["0040" volatile]
  ["0080" transient]
  ["1000" synthetic]
  ["4000" enum]
  )

(def: #export equivalence
  (Equivalence Field)
  ($_ product.equivalence
      modifier.equivalence
      //index.equivalence
      //index.equivalence
      (row.equivalence //attribute.equivalence)))

(def: #export (writer field)
  (Writer Field)
  (`` ($_ binaryF\compose
          (~~ (template [<writer> <slot>]
                [(<writer> (get@ <slot> field))]

                [modifier.writer #modifier]
                [//index.writer #name]
                [//index.writer #descriptor]
                [(binaryF.row/16 //attribute.writer) #attributes]))
          )))

(def: #export (field modifier name type attributes)
  (-> (Modifier Field) UTF8 (Type Value) (Row Attribute)
      (Resource Field))
  (do //constant/pool.monad
    [@name (//constant/pool.utf8 name)
     @descriptor (//constant/pool.descriptor (//type.descriptor type))]
    (wrap {#modifier modifier
           #name @name
           #descriptor @descriptor
           #attributes attributes})))