blob: 0de84d65b53142d0406426f8a31b436285bf5585 (
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
(.module:
[lux (#- Definition)
[abstract
["." monad (#+ do)]]
[control
["<>" parser
["<c>" code (#+ Parser)]]]
[data
["." product]
[text
format]
[collection
["." list ("#@." functor fold)]
["." dictionary]]]
[type
["." check (#+ Check)]]
[target
[jvm
["." type (#+ Var Parameter Class Argument Typed Return)
[".T" lux]]]]
[tool
[compiler
["." statement (#+ Handler Bundle)]
["." phase
["." generation]
[analysis
[".A" type]]
["." extension
["." bundle]
[analysis
["." jvm]]
[statement
["/" lux]]]]]]]
[luxc
[lang
[host
["$" jvm (#+ Anchor Inst Definition Operation Phase)
["_" inst]
["_." def]]]]])
(type: Declaration
[Text (List Text)])
(def: declaration
(Parser Declaration)
(<c>.form (<>.and <c>.text (<>.some <c>.text))))
(type: Inheritance
#FinalI
#AbstractI
#DefaultI)
(def: inheritance
(Parser Inheritance)
($_ <>.or
(<c>.text! "final")
(<c>.text! "abstract")
(<c>.text! "default")))
(type: State
#VolatileS
#FinalS
#DefaultS)
(def: state
(Parser State)
($_ <>.or
(<c>.text! "volatile")
(<c>.text! "final")
(<c>.text! "default")))
(type: Annotation Any)
(def: annotation
(Parser Annotation)
<c>.any)
(type: Constant
[Text (List Annotation) type.Type Code])
(def: constant
(Parser Constant)
(<| <c>.form
(<>.after (<c>.text! "constant"))
($_ <>.and
<c>.text
(<c>.tuple (<>.some ..annotation))
jvm.type
<c>.any
)))
(type: Variable
[Text jvm.Visibility State (List Annotation) type.Type])
(def: variable
(Parser Variable)
(<| <c>.form
(<>.after (<c>.text! "variable"))
($_ <>.and
<c>.text
jvm.visibility
..state
(<c>.tuple (<>.some ..annotation))
jvm.type
)))
(type: Field
(#Constant Constant)
(#Variable Variable))
(def: field
(Parser Field)
($_ <>.or
..constant
..variable
))
(type: Method-Definition
(#Constructor (jvm.Constructor Code))
(#Virtual-Method (jvm.Virtual-Method Code))
(#Static-Method (jvm.Static-Method Code))
(#Overriden-Method (jvm.Overriden-Method Code)))
(def: method
(Parser Method-Definition)
($_ <>.or
jvm.constructor-definition
jvm.virtual-method-definition
jvm.static-method-definition
jvm.overriden-method-definition
))
(def: (parameter name)
(-> Text Parameter)
[name [type.object-class (list)] (list)])
(def: string-descriptor (type.descriptor (type.class "java.lang.String" (list))))
(def: jvm::class
(Handler Anchor Inst Definition)
(/.custom
[($_ <>.and
..declaration
jvm.class
(<c>.tuple (<>.some jvm.class))
..inheritance
(<c>.tuple (<>.some ..annotation))
(<c>.tuple (<>.some ..field))
(<c>.tuple (<>.some ..method)))
(function (_ extension phase
[[name parameters]
super-class
super-interfaces
inheritance
## TODO: Handle annotations.
annotations
fields
methods])
(do phase.monad
[parameters (statement.lift-analysis
(typeA.with-env
(jvm.parameter-types parameters)))
#let [mapping (list@fold (function (_ [parameterJ parameterT] mapping)
(dictionary.put parameterJ parameterT mapping))
luxT.fresh
parameters)
field-definitions (|> fields
(list@map (function (_ field)
(case field
## TODO: Handle annotations.
(#Constant [name annotations type value])
(case [(type.descriptor type) value]
(^template [<descriptor> <tag> <field>]
(^ [(static <descriptor>) [_ (<tag> value)]])
(<field> #$.Public ($.++F $.staticF $.finalF) name value))
([type.boolean-descriptor #.Bit _def.boolean-field]
[type.byte-descriptor #.Int _def.byte-field]
[type.short-descriptor #.Int _def.short-field]
[type.int-descriptor #.Int _def.int-field]
[type.long-descriptor #.Int _def.long-field]
[type.float-descriptor #.Frac _def.float-field]
[type.double-descriptor #.Frac _def.double-field]
[type.char-descriptor #.Nat _def.char-field]
[string-descriptor #.Text _def.string-field])
## TODO: Handle constants better.
_
(undefined))
## TODO: Handle annotations.
(#Variable [name visibility state annotations type])
(_def.field visibility
(case state
## TODO: Handle transient & static.
#VolatileS $.volatileF
#FinalS $.finalF
#DefaultS $.noneF)
name
type))))
_def.fuse)]
super-classT (statement.lift-analysis
(typeA.with-env
(luxT.class mapping super-class)))
super-interfaceT+ (statement.lift-analysis
(typeA.with-env
(monad.map check.monad
(luxT.class mapping)
super-interfaces)))
#let [selfT (jvm.inheritance-relationship-type (#.Primitive name (list@map product.right parameters))
super-classT
super-interfaceT+)]
state (extension.lift phase.get-state)
#let [analyse (get@ [#statement.analysis #statement.phase] state)
synthesize (get@ [#statement.synthesis #statement.phase] state)
generate (get@ [#statement.generation #statement.phase] state)]
methods (monad.map @ (function (_ methodC)
(do @
[methodA (statement.lift-analysis
(case methodC
(#Constructor method)
(jvm.analyse-constructor-method analyse selfT mapping method)
(#Virtual-Method method)
(jvm.analyse-virtual-method analyse selfT mapping method)
(#Static-Method method)
(jvm.analyse-static-method analyse mapping method)
(#Overriden-Method method)
(jvm.analyse-overriden-method analyse selfT mapping method)))]
(statement.lift-synthesis
(synthesize methodA))))
methods)
_ (statement.lift-generation
(generation.save! true ["" name]
[name
(_def.class #$.V1_6 #$.Public
(case inheritance
#FinalI $.finalC
## TODO: Handle abstract classes.
#AbstractI (undefined)
#DefaultI $.noneC)
name (list@map (|>> product.left ..parameter) parameters)
super-class super-interfaces
(|>> field-definitions))]))
#let [_ (log! (format "Class " name))]]
(wrap statement.no-requirements)))]))
(def: #export bundle
(Bundle Anchor Inst Definition)
(<| (bundle.prefix "jvm")
(|> bundle.empty
(dictionary.put "class" jvm::class)
)))
|