aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/target/jvm/attribute.lux
blob: bcd3a373441aecf6921cd6a86a12747dcbeb20c7 (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
(.module:
  [lux (#- Info Code' Code)
   [abstract
    ["." equivalence (#+ Equivalence)]
    [monad (#+ do)]]
   [control
    ["." state (#+ State)]]
   [data
    [format
     ["." binary (#+ Format)]]
    [collection
     ["." row (#+ Row)]]]
   [world
    [binary (#+ Binary)]]]
  ["." // #_
   ["#." encoding (#+ U2 U4)]
   ["#." index (#+ Index)]
   ["#." constant (#+ UTF8 Class Value)
    ["#/." pool (#+ Pool)]]])

(type: #export (Info about)
  {#name (Index UTF8)
   #length U4
   #info about})

(def: #export (info-equivalence Equivalence<about>)
  (All [about]
    (-> (Equivalence about)
        (Equivalence (Info about))))
  ($_ equivalence.product
      //index.equivalence
      //encoding.u4-equivalence
      Equivalence<about>))

(def: (info-format about)
  (All [about]
    (-> (Format about)
        (Format (Info about))))
  ($_ binary.and
      //index.format
      //encoding.u4-format
      about))

(type: #export Constant
  (Info (Index (Value Any))))

(def: #export constant-equivalence
  (Equivalence Constant)
  (..info-equivalence //index.equivalence))

(def: constant-format
  (Format Constant)
  (..info-format //index.format))

(type: #export Label U2)

(type: #export Exception
  {#start-pc Label
   #end-pc Label
   #handler-pc Label
   #catch-type (Index Class)})

(type: #export (Code' Attribute)
  {#max-stack U2
   #max-locals U2
   #code Binary
   #exception-table (Row Exception)
   #attributes (Row Attribute)})

(with-expansions [<Code> (as-is (Info (Code' Attribute)))]
  (type: #export #rec Attribute
    (#Constant Constant)
    ## (#Code <Code>)
    )

  ## (type: #export Code
  ##   <Code>)
  )

(def: #export equivalence
  (Equivalence Attribute)
  ..constant-equivalence)

(def: #export (constant index)
  (-> (Index (Value Any))
      (State Pool Attribute))
  (do state.monad
    [@name (//constant/pool.utf8 "ConstantValue")]
    (wrap (#Constant {#name @name
                      #length (//encoding.to-u4 //encoding.u2-bytes)
                      #info index}))))

## (def: #export (code specification)
##   (-> Code' (State Pool Attribute))
##   (do state.monad
##     [@name (//constant/pool.utf8 "Code")]
##     (wrap (#Code {#name @name
##                   #length (undefined)
##                   #info specification}))))

(def: #export format
  (Format Attribute)
  ..constant-format)