aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/reference.lux
blob: 88b2af2edd607d4ebd1dbabcea79ebfcace34b12 (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
(.using
  [library
   [lux {"-" local}
    [abstract
     [monad {"+" do}]]
    [data
     [text
      ["%" format {"+" format}]]]
    [target
     [jvm
      ["[0]" type]]]
    [tool
     [compiler
      [reference
       ["[0]" variable {"+" Register Variable}]]
      ["[0]" phase ("operation@[0]" monad)]
      [meta
       [archive {"+" Archive}]]
      [language
       [lux
        ["[0]" generation]]]]]]]
  [luxc
   [lang
    [host
     [jvm {"+" Inst Operation}
      ["_" inst]]]]]
  ["[0]" //
   ["[1][0]" runtime]])

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

  [foreign_name "f"]
  [partial_name "p"]
  )

(def: (foreign archive variable)
  (-> Archive Register (Operation Inst))
  (do [@ phase.monad]
    [class_name (# @ each //.class_name
                   (generation.context archive))]
    (in (|>> (_.ALOAD 0)
             (_.GETFIELD (type.class class_name (list))
                         (|> variable .nat foreign_name)
                         //.$Value)))))

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

(def: .public (variable archive variable)
  (-> Archive Variable (Operation Inst))
  (case variable
    {variable.#Local variable}
    (operation@in (local variable))
    
    {variable.#Foreign variable}
    (foreign archive variable)))

(def: .public (constant archive name)
  (-> Archive Symbol (Operation Inst))
  (do [@ phase.monad]
    [class_name (# @ each //.class_name
                   (generation.remember archive name))]
    (in (_.GETSTATIC (type.class class_name (list)) //.value_field //.$Value))))