aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/jvm/reference.jvm.lux
blob: ba606a437185b7ae096c2f8a9bd64b4e4424f39a (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
(.module:
  [lux #*
   [control
    [monad (#+ do)]]
   [data
    [text ("text/." Hash<Text>)
     format]]
   [compiler
    [default
     ["." name]
     ["." reference (#+ Register Variable)]
     ["." phase ("operation/." Monad<Operation>)
      ["." translation]]]]]
  [luxc
   [lang
    [host
     [jvm (#+ Inst Operation)
      ["$t" type]
      ["_" inst]]]]]
  ["." //])

(do-template [<name> <prefix>]
  [(def: #export (<name> idx)
     (-> Nat Text)
     (|> idx .int %i (format <prefix>)))]

  [foreign-name "f"]
  [partial-name "p"]
  )

(def: (foreign variable)
  (-> Register (Operation Inst))
  (do phase.Monad<Operation>
    [function-class translation.context]
    (wrap (|>> (_.ALOAD +0)
               (_.GETFIELD function-class
                           (|> variable .nat foreign-name)
                           //.$Object)))))

(def: local
  (-> Register (Operation Inst))
  (|>> _.ALOAD operation/wrap))

(def: #export (variable variable)
  (-> Variable (Operation Inst))
  (case variable
    (#reference.Local variable)
    (local variable)
    
    (#reference.Foreign variable)
    (foreign variable)))

(def: #export (constant [module short])
  (-> Name (Operation Inst))
  (let [bytecode-name (format module "/" (name.normalize short) (%n (text/hash short)))]
    (operation/wrap (_.GETSTATIC bytecode-name //.value-field //.$Object))))