aboutsummaryrefslogtreecommitdiff
path: root/lux-r/source/luxc/lang/translation/r/structure.jvm.lux
blob: cea8fcd59f60c5928c31735ac3576be2cafb66a6 (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
(.module:
  lux
  (lux (control [monad #+ do])
       (data [text]
             text/format)
       [macro])
  (luxc ["&" lang]
        (lang [synthesis #+ Synthesis]
              (host [r #+ Expression])))
  [//]
  (// [".T" runtime]))

(def: #export (translate-tuple translate elemsS+)
  (-> (-> Synthesis (Meta Expression)) (List Synthesis) (Meta Expression))
  (case elemsS+
    #.Nil
    (:: macro.Monad<Meta> wrap runtimeT.unit)

    (#.Cons singletonS #.Nil)
    (translate singletonS)

    _
    (do {@ macro.Monad<Meta>}
      [elemsT+ (monad.map @ translate elemsS+)]
      (wrap (r.list elemsT+)))))

(def: #export (translate-variant translate tag tail? valueS)
  (-> (-> Synthesis (Meta Expression)) Nat Bit Synthesis (Meta Expression))
  (do macro.Monad<Meta>
    [valueT (translate valueS)]
    (wrap (runtimeT.variant tag tail? valueT))))