aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/common-lisp/reference.jvm.lux
blob: def77fc35b3fa4bfdf49f6165a2020eb34281e34 (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
(.module:
  lux
  (lux [macro]
       (data [text]
             text/format))
  (luxc ["&" lang]
        (lang [".L" variable #+ Variable Register]
              (host ["_" common-lisp #+ Expression SVar @@])))
  [//]
  (// [".T" runtime]))

(template [<register> <translation> <prefix>]
  [(def: #export (<register> register)
     (-> Register SVar)
     (_.var (format <prefix> (%i (.int register)))))
   
   (def: #export (<translation> register)
     (-> Register (Meta Expression))
     (:: macro.Monad<Meta> wrap (@@ (<register> register))))]

  [closure  translate-captured "c"]
  [variable translate-local    "v"])

(def: #export (local var)
  (-> Variable SVar)
  (if (variableL.captured? var)
    (closure (variableL.captured-register var))
    (variable (.nat var))))

(def: #export (translate-variable var)
  (-> Variable (Meta Expression))
  (if (variableL.captured? var)
    (translate-captured (variableL.captured-register var))
    (translate-local (.nat var))))

(def: #export global
  (-> Name SVar)
  (|>> //.definition-name _.var))

(def: #export (translate-definition name)
  (-> Name (Meta Expression))
  (:: macro.Monad<Meta> wrap (@@ (global name))))