blob: 462c625c992abab4d524b09c21c0f54e38e5fc12 (
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
|
(.module:
[lux (#- Type type)
[target
[jvm
["_" bytecode (#+ Bytecode)]
["." type (#+ Type) ("#@." equivalence)
[category (#+ Primitive)]
["." box]]]]])
(def: #export field "value")
(template [<name> <boolean> <byte> <short> <int> <long> <float> <double> <char>]
[(def: (<name> type)
(-> (Type Primitive) Text)
(`` (cond (~~ (template [<type> <output>]
[(type@= <type> type) <output>]
[type.boolean <boolean>]
[type.byte <byte>]
[type.short <short>]
[type.int <int>]
[type.long <long>]
[type.float <float>]
[type.double <double>]
[type.char <char>]))
## else
(undefined))))]
[primitive-wrapper
box.boolean box.byte box.short box.int
box.long box.float box.double box.char]
[primitive-unwrap
"booleanValue" "byteValue" "shortValue" "intValue"
"longValue" "floatValue" "doubleValue" "charValue"]
)
(def: #export (wrap type)
(-> (Type Primitive) (Bytecode Any))
(let [wrapper (type.class (primitive-wrapper type) (list))]
(_.invokestatic wrapper "valueOf"
(type.method [(list type) wrapper (list)]))))
(def: #export (unwrap type)
(-> (Type Primitive) (Bytecode Any))
(let [wrapper (type.class (primitive-wrapper type) (list))]
($_ _.compose
(_.checkcast wrapper)
(_.invokevirtual wrapper (primitive-unwrap type) (type.method [(list) type (list)])))))
|