aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux
blob: 49fbd0385e8c0c5d40b64bab0cdfc4e4daa57987 (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
(.module:
  lux
  (lux (control monad)
       (data [text]
             text/format)
       [macro]
       [host #+ do-to])
  (luxc ["&" lang]
        (lang (host ["$" jvm]
                    (jvm ["$t" type]
                         ["$d" def]
                         ["_" inst]))
              ["la" analysis]
              ["ls" synthesis]))
  (// [".T" common]))

(host.import: java/lang/reflect/Field
  (get [Object] Object))

(host.import: (java/lang/Class a)
  (getField [String] Field))

(def: #export (eval valueI)
  (-> $.Inst (Meta Any))
  (do macro.Monad<Meta>
    [current-module macro.current-module-name
     class-name (:: @ map %code (macro.gensym (format current-module "/eval")))
     #let [store-name (text.replace-all "/" "." class-name)
           bytecode ($d.class #$.V1_6
                              #$.Public $.noneC
                              class-name
                              (list) ["java.lang.Object" (list)]
                              (list)
                              (|>> ($d.field #$.Public ($_ $.++F $.finalF $.staticF)
                                             commonT.value-field commonT.$Object)
                                   ($d.method #$.Public ($_ $.++M $.staticM $.strictM)
                                              "<clinit>"
                                              ($t.method (list) #.None (list))
                                              (|>> valueI
                                                   (_.PUTSTATIC store-name commonT.value-field commonT.$Object)
                                                   _.RETURN))))]
     _ (commonT.store-class store-name bytecode)
     class (commonT.load-class store-name)]
    (wrap (|> class
              (Class::getField [commonT.value-field])
              (Field::get (host.null))))))