blob: 8c0b294c1363e080e3867ee0e95c8dd6da29d182 (
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
|
(;module:
lux
(lux (control monad)
(data ["R" result]
text/format)
[macro #+ Monad<Lux> "Lux/" Monad<Lux>]
[host #+ jvm-import do-to])
(luxc ["&" base]
(lang ["la" analysis]
["ls" synthesis])
["&;" analyser]
["&;" synthesizer]
(generator ["&;" common]
(host ["$" jvm]
(jvm ["$t" type]
["$d" def]
["$i" inst])))))
(jvm-import java.lang.Object)
(jvm-import java.lang.String)
(jvm-import java.lang.reflect.Field
(get [Object] #try Object))
(jvm-import (java.lang.Class a)
(getField [String] Field))
(jvm-import org.objectweb.asm.Opcodes
(#static ACC_PUBLIC int)
(#static ACC_SUPER int)
(#static ACC_FINAL int)
(#static ACC_STATIC int)
(#static V1_6 int))
(jvm-import org.objectweb.asm.ClassWriter
(#static COMPUTE_MAXS int)
(new [int])
(visit [int int String String String (Array String)] void)
(visitEnd [] void)
(toByteArray [] Byte-Array))
(def: #export runtime-name Text "LuxRT")
(def: #export function-name Text "LuxFunction")
(def: #export unit Text "\u0000")
(def: $Object $;Type ($t;class "java.lang.Object" (list)))
(def: add-adt-methods
$;Def
(let [store-tag (|>. $i;DUP ($i;int 0) ($i;ILOAD +0) $i;wrap-int $i;AASTORE)
store-flag (|>. $i;DUP ($i;int 1) ($i;ALOAD +1) $i;AASTORE)
store-value (|>. $i;DUP ($i;int 2) ($i;ALOAD +2) $i;AASTORE)]
(|>. ($d;method #$;Public
{#$;staticM true #$;finalM false #$;synchronizedM false}
"sum_make"
($t;method (list $t;int $Object $Object)
(#;Some ($t;array +1 $Object))
(list))
(|>. ($i;array $Object +3)
store-tag
store-flag
store-value
$i;ARETURN)))))
(def: #export generate
(Lux &common;Bytecode)
(do Monad<Lux>
[_ (wrap [])
#let [writer (|> (do-to (ClassWriter.new ClassWriter.COMPUTE_MAXS)
(ClassWriter.visit [&common;bytecode-version
($_ i.+ Opcodes.ACC_PUBLIC Opcodes.ACC_FINAL Opcodes.ACC_SUPER)
runtime-name (host;null)
"java/lang/Object" (host;null)]))
add-adt-methods)
bytecode (ClassWriter.toByteArray [] (do-to writer (ClassWriter.visitEnd [])))]
_ (&common;store-class runtime-name bytecode)]
(wrap bytecode)))
|