aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/jvm/reference.lux
blob: 77e98b73bef7745003b73b49e688e89ad5568a99 (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
(.module:
  [lux #*
   [abstract
    [monad (#+ do)]]
   [data
    [text
     ["%" format (#+ format)]]]
   [target
    [jvm
     ["." type]]]
   [tool
    [compiler
     ["." name]
     ["." reference (#+ Register Variable)]
     ["." phase ("operation@." monad)
      ["." generation]]]]]
  [luxc
   [lang
    [host
     [jvm (#+ Inst Operation)
      ["_" inst]]]]]
  ["." //])

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

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

(def: (foreign variable)
  (-> Register (Operation Inst))
  (do phase.monad
    [function-class generation.context]
    (wrap (|>> (_.ALOAD 0)
               (_.GETFIELD (type.class function-class (list))
                           (|> variable .nat foreign-name)
                           //.$Value)))))

(def: local
  (-> Register Inst)
  (|>> _.ALOAD))

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

(def: #export (constant name)
  (-> Name (Operation Inst))
  (do phase.monad
    [bytecode-name (generation.remember name)]
    (wrap (_.GETSTATIC (type.class bytecode-name (list)) //.value-field //.$Value))))