aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/host/jvm.lux
blob: 46771939df377dc641a85d83ed119a10dbba4bed (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
(.using
  [library
   [lux {"-" Definition Type Label}
    [ffi {"+" import:}]
    [abstract
     monad]
    [control
     ["<>" parser
      ["<[0]>" code]]]
    [data
     [binary {"+" Binary}]
     [text
      ["%" format {"+" format}]]
     [collection
      ["[0]" list ("[1]#[0]" monad)]]]
    [macro
     ["[0]" code]
     [syntax {"+" syntax:}]]
    [target
     [jvm
      ["[0]" type {"+" Type}
       [category {"+" Class}]]]]
    [tool
     [compiler
      [reference
       [variable {"+" Register}]]
      [language
       [lux
        ["[0]" generation]]]
      [meta
       [archive {"+" Archive}]]]]]])

(import: org/objectweb/asm/MethodVisitor)

(import: org/objectweb/asm/ClassWriter)

(import: org/objectweb/asm/Label
  ["[1]::[0]"
   (new [])])

(type: .public Def
  (-> org/objectweb/asm/ClassWriter org/objectweb/asm/ClassWriter))

(type: .public Inst
  (-> org/objectweb/asm/MethodVisitor org/objectweb/asm/MethodVisitor))

(type: .public Label
  org/objectweb/asm/Label)

(type: .public Visibility
  (Variant
   {#Public}
   {#Protected}
   {#Private}
   {#Default}))

(type: .public Version
  (Variant
   {#V1_1}
   {#V1_2}
   {#V1_3}
   {#V1_4}
   {#V1_5}
   {#V1_6}
   {#V1_7}
   {#V1_8}))

(type: .public ByteCode
  Binary)

(type: .public Definition
  [Text ByteCode])

(type: .public Anchor
  [Label Register])

(type: .public Host
  (generation.Host Inst Definition))

(template [<name> <base>]
  [(type: .public <name>
     (<base> ..Anchor ..Inst ..Definition))]

  [State     generation.State]
  [Operation generation.Operation]
  [Phase     generation.Phase]
  [Handler   generation.Handler]
  [Bundle    generation.Bundle]
  [Extender  generation.Extender]
  )

(type: .public (Generator i)
  (-> Phase Archive i (Operation Inst)))

(syntax: (config: [type <code>.local_symbol
                   none <code>.local_symbol
                   ++ <code>.local_symbol
                   options (<code>.tuple (<>.many <code>.local_symbol))])
  (let [g!type (code.local_symbol type)
        g!none (code.local_symbol none)
        g!tags+ (list#each (|>> (format "#") code.local_symbol) options)
        g!_left (code.local_symbol "_left")
        g!_right (code.local_symbol "_right")
        g!options+ (list#each (function (_ option)
                                (` (def: .public (~ (code.local_symbol option))
                                     (~ g!type)
                                     (|> (~ g!none)
                                         (with@ (~ (code.local_symbol (format "#" option))) #1)))))
                              options)]
    (in (list& (` (type: .public (~ g!type)
                    (.Record
                     (~ (|> g!tags+
                            (list#each (function (_ tag)
                                         (list tag (` .Bit))))
                            list#conjoint
                            code.tuple)))))

               (` (def: .public (~ g!none)
                    (~ g!type)
                    (~ (|> g!tags+
                           (list#each (function (_ tag)
                                        (list tag (` #0))))
                           list#conjoint
                           code.tuple))))

               (` (def: .public ((~ (code.local_symbol ++)) (~ g!_left) (~ g!_right))
                    (-> (~ g!type) (~ g!type) (~ g!type))
                    (~ (|> g!tags+
                           (list#each (function (_ tag)
                                        (list tag (` (or (value@ (~ tag) (~ g!_left))
                                                         (value@ (~ tag) (~ g!_right)))))))
                           list#conjoint
                           code.tuple))))

               g!options+))))

(config: Class_Config  noneC ++C [finalC])
(config: Method_Config noneM ++M [finalM staticM synchronizedM strictM])
(config: Field_Config  noneF ++F [finalF staticF transientF volatileF])

(def: .public new_label
  (-> Any Label)
  (function (_ _)
    (org/objectweb/asm/Label::new)))

(def: .public (simple_class name)
  (-> Text (Type Class))
  (type.class name (list)))