aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase/translation/js/structure.lux
blob: 732f48bb9dc39110cbca85f309f0320329b2bcd8 (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
(.module:
  [lux #*
   [control
    ["." monad (#+ do)]]
   [host
    ["_" js (#+ Expression)]]]
  [//
   ["//." runtime (#+ Operation Phase)]
   ["//." primitive]
   ["/." ///
    [//
     [analysis (#+ Variant Tuple)]
     ["." synthesis (#+ Synthesis)]]]])

(def: #export (tuple translate elemsS+)
  (-> Phase (Tuple Synthesis) (Operation Expression))
  (case elemsS+
    #.Nil
    (:: ////.monad wrap (//primitive.text synthesis.unit))

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

    _
    (do ////.monad
      [elemsT+ (monad.map @ translate elemsS+)]
      (wrap (_.array elemsT+)))))

(def: #export (variant translate [lefts right? valueS])
  (-> Phase (Variant Synthesis) (Operation Expression))
  (:: ////.monad map
      (//runtime.variant (_.i32 (.int (if right?
                                        (inc lefts)
                                        lefts)))
                         (//runtime.flag right?))
      (translate valueS)))