blob: 38315c3b42bfc27a88c3a90ef1a167c88d0e8219 (
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
(.module:
[lux #*
[abstract
[monoid (#+)]
["." equivalence (#+ Equivalence)]
["." monad (#+ do)]]
[control
["<>" parser
["<2>" binary (#+ Parser)]]
["." state (#+ State)]]
[data
[number (#+)
[i64 (#+)]]
[format
[".F" binary (#+ Writer Format) ("#@." monoid)]]
[collection
["." row (#+ Row)]]]
[type
[abstract (#+)]]]
["." // #_
["#." modifier (#+ Modifier modifiers:)]
["#." version (#+ Version Minor Major)]
["#." magic (#+ Magic)]
["#." index (#+ Index)]
["#." attribute (#+ Attribute)]
["#." field (#+ Field)]
["#." method (#+ Method)]
[encoding
["#." unsigned (#+)]
["#." name (#+ Internal)]]
["#." constant (#+ Constant)
["#/." pool (#+ Pool)]]])
(type: #export #rec Class
{#magic Magic
#minor-version Minor
#major-version Major
#constant-pool Pool
#modifier (Modifier Class)
#this (Index //constant.Class)
#super (Index //constant.Class)
#interfaces (Row (Index //constant.Class))
#fields (Row Field)
#methods (Row Method)
#attributes (Row Attribute)})
(modifiers: Class
["0001" public]
["0010" final]
["0020" super]
["0200" interface]
["0400" abstract]
["1000" synthetic]
["2000" annotation]
["4000" enum]
)
(def: #export equivalence
(Equivalence Class)
($_ equivalence.product
//unsigned.equivalence
//unsigned.equivalence
//unsigned.equivalence
//constant/pool.equivalence
//modifier.equivalence
//index.equivalence
//index.equivalence
(row.equivalence //index.equivalence)
(row.equivalence //field.equivalence)
(row.equivalence //method.equivalence)
(row.equivalence //attribute.equivalence)))
(def: default-minor-version Minor (//version.version 0))
(def: (install-classes this super interfaces)
(-> Internal Internal (List Internal)
(State Pool [(Index //constant.Class) (Index //constant.Class) (Row (Index //constant.Class))]))
(do state.monad
[@this (//constant/pool.class (//name.read this))
@super (//constant/pool.class (//name.read super))
@interfaces (: (State Pool (Row (Index //constant.Class)))
(monad.fold @ (function (_ interface @interfaces)
(do @
[@interface (//constant/pool.class (//name.read interface))]
(wrap (row.add @interface @interfaces))))
row.empty
interfaces))]
(wrap [@this @super @interfaces])))
(def: #export (class version modifier
this super interfaces
fields methods attributes)
(-> Major (Modifier Class)
Internal Internal (List Internal)
(List (State Pool Field))
(Row Method)
(Row Attribute)
Class)
(let [[pool [@this @super @interfaces] =fields]
(state.run //constant/pool.empty
(do state.monad
[classes (install-classes this super interfaces)
=fields (monad.seq state.monad fields)]
(wrap [classes =fields])))]
{#magic //magic.code
#minor-version ..default-minor-version
#major-version version
#constant-pool pool
#modifier modifier
#this @this
#super @super
#interfaces @interfaces
#fields (row.from-list =fields)
#methods methods
#attributes attributes}))
(def: #export parser
(Parser Class)
(do <>.monad
[magic (get@ #binaryF.reader //magic.format)
minor-version (get@ #binaryF.reader //version.format)
major-version (get@ #binaryF.reader //version.format)
constant-pool (get@ #binaryF.reader //constant/pool.format)
modifier (get@ #binaryF.reader //modifier.format)
this (get@ #binaryF.reader //index.format)
super (get@ #binaryF.reader //index.format)
interfaces (get@ #binaryF.reader (binaryF.row/16 //index.format))
fields (<2>.row/16 (//field.reader constant-pool))
methods (<2>.row/16 (//method.reader constant-pool))
attributes (<2>.row/16 (//attribute.reader constant-pool))]
(wrap {#magic magic
#minor-version minor-version
#major-version major-version
#constant-pool constant-pool
#modifier modifier
#this this
#super super
#interfaces interfaces
#fields fields
#methods methods
#attributes attributes})))
(def: #export (writer class)
(Writer Class)
(`` ($_ binaryF@compose
(~~ (template [<format> <slot>]
[((get@ #binaryF.writer <format>) (get@ <slot> class))]
[//magic.format #magic]
[//version.format #minor-version]
[//version.format #major-version]
[//constant/pool.format #constant-pool]
[//modifier.format #modifier]
[//index.format #this]
[//index.format #super]
[(binaryF.row/16 //index.format) #interfaces]))
(~~ (template [<type> <writer> <slot>]
[((get@ #binaryF.writer
(binaryF.row/16 (: (Format <type>)
{## TODO: Get rid of this dirty hack ASAP
#binaryF.reader (<>.fail "")
#binaryF.writer <writer>})))
(get@ <slot> class))]
[Field //field.writer #fields]
[Method //method.writer #methods]
[Attribute //attribute.writer #attributes]
))
)))
(def: #export format
(Format Class)
{#binaryF.reader ..parser
#binaryF.writer ..writer})
|