aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/host/jvm/access.lux
blob: f0d088a9753c4a4a32c2cdfe8267604222051a6e (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
(.module:
  [lux #*
   [control
    [monoid (#+ Monoid)]
    [parser ("parser/." Functor<Parser>)]]
   [data
    [number (#+ hex)
     ["." i64]]
    [format
     ["." binary (#+ Format)]]]
   [type
    abstract]]
  [//
   ["//." encoding (#+ U2)]])

(abstract: #export Access
  {}

  U2

  (def: #export code
    (-> Access U2)
    (|>> :representation))

  (def: #export (combine parameter subject)
    (-> Access Access Access)
    (let [parameter' (//encoding.from-u2 (:representation parameter))
          subject' (//encoding.from-u2 (:representation subject))]
      (:abstraction (//encoding.to-u2 (i64.and parameter'
                                               subject')))))

  (do-template [<name> <code>]
    [(def: #export <name>
       Access
       (|> (hex <code>) //encoding.to-u2 :abstraction))]

    [empty      "0000"]
    [public     "0001"]
    [final      "0010"]
    [super      "0020"]
    [interface  "0200"]
    [abstract   "0400"]
    [synthetic  "1000"]
    [annotation "2000"]
    [enum       "4000"]
    )

  (def: #export format
    (Format Access)
    (let [(^open "_/.") //encoding.u2-format]
      {#binary.reader (|> _/reader (parser/map (|>> :abstraction)))
       #binary.writer (|>> :representation _/writer)}))
  )

(structure: #export _ (Monoid Access)
  (def: identity ..empty)
  (def: compose ..combine))