aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/target/jvm/method.lux
blob: d081d1c81e0e5bf15601274d66e975fdbaf6e31f (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
(.module:
  [lux (#- static)
   [abstract
    [monoid (#+)]
    ["." equivalence (#+ Equivalence)]
    ["." monad (#+ do)]]
   [control
    ["." state (#+ State)]
    ["<>" parser
     ["<2>" binary (#+ Parser)]]]
   [data
    [number (#+)
     [i64 (#+)]]
    [format
     [".F" binary (#+ Writer) ("#@." monoid)]]
    [collection
     ["." row (#+ Row)]]]
   [type
    [abstract (#+)]]]
  ["." // #_
   ["#." modifier (#+ Modifier modifiers:)]
   ["#." index (#+ Index)]
   ["#." attribute (#+ Attribute)]
   ["#." descriptor (#+ Descriptor)]
   ["#." constant (#+ UTF8)
    ["#/." pool (#+ Pool)]]])

(type: #export #rec Method
  {#modifier (Modifier Method)
   #name (Index UTF8)
   #descriptor (Index (Descriptor //descriptor.Method))
   #attributes (Row Attribute)})

(modifiers: Method
  ["0001" public]
  ["0002" private]
  ["0004" protected]
  ["0008" static]
  ["0010" final]
  ["0020" synchronized]
  ["0040" bridge]
  ["0080" var-args]
  ["0100" native]
  ["0400" abstract]
  ["0800" strict]
  ["1000" synthetic]
  )

(def: #export (method modifier name descriptor attributes)
  (-> (Modifier Method) UTF8 (Descriptor //descriptor.Method) (List (State Pool Attribute))
      (State Pool Method))
  (do state.monad
    [@name (//constant/pool.utf8 name)
     @descriptor (//constant/pool.descriptor descriptor)
     attributes (monad.seq @ attributes)]
    (wrap {#modifier modifier
           #name @name
           #descriptor @descriptor
           #attributes (row.from-list attributes)})))

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

(def: #export (parser pool)
  (-> Pool (Parser Method))
  ($_ <>.and
      //modifier.parser
      //index.parser
      //index.parser
      (<2>.row/16 (//attribute.parser pool))))

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

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