blob: ad90c3db50ef0dc6c966b026025969227635211d (
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
|
(.module:
[lux #*
[abstract
[equivalence (#+ Equivalence)]
["." monad (#+ do)]]
[control
["." state]
["." try (#+ Try)]]
[data
["." product]
[format
[".F" binary (#+ Writer) ("#\." monoid)]]
[collection
["." row (#+ Row)]]]]
["." // #_
["#." 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 Resource)]]])
(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)
($_ product.equivalence
//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: (install_classes this super interfaces)
(-> Internal Internal (List Internal)
(Resource [(Index //constant.Class) (Index //constant.Class) (Row (Index //constant.Class))]))
(do {! //constant/pool.monad}
[@this (//constant/pool.class this)
@super (//constant/pool.class super)
@interfaces (: (Resource (Row (Index //constant.Class)))
(monad.fold ! (function (_ interface @interfaces)
(do !
[@interface (//constant/pool.class 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 (Resource Field))
(List (Resource Method))
(Row Attribute)
(Try Class))
(do try.monad
[[pool [@this @super @interfaces] =fields =methods]
(<| (state.run' //constant/pool.empty)
(do //constant/pool.monad
[classes (install_classes this super interfaces)
=fields (monad.seq //constant/pool.monad fields)
=methods (monad.seq //constant/pool.monad methods)]
(wrap [classes =fields =methods])))]
(wrap {#magic //magic.code
#minor_version //version.default_minor
#major_version version
#constant_pool pool
#modifier modifier
#this @this
#super @super
#interfaces @interfaces
#fields (row.from_list =fields)
#methods (row.from_list =methods)
#attributes attributes})))
(def: #export (writer class)
(Writer Class)
(`` ($_ binaryF\compose
(~~ (template [<writer> <slot>]
[(<writer> (get@ <slot> class))]
[//magic.writer #magic]
[//version.writer #minor_version]
[//version.writer #major_version]
[//constant/pool.writer #constant_pool]
[//modifier.writer #modifier]
[//index.writer #this]
[//index.writer #super]))
(~~ (template [<writer> <slot>]
[((binaryF.row/16 <writer>) (get@ <slot> class))]
[//index.writer #interfaces]
[//field.writer #fields]
[//method.writer #methods]
[//attribute.writer #attributes]
))
)))
|