aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase/generation/common-lisp/structure.lux
blob: ef29d33dc708818f35f3ab8f1c9531065df70539 (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 #*
   [abstract
    ["." monad (#+ do)]]
   [target
    ["_" common-lisp (#+ Expression)]]]
  ["." // #_
   ["#." runtime (#+ Operation Phase)]
   ["#." primitive]
   ["//#" ///
    ["/#" // #_
     [analysis (#+ Variant Tuple)]
     ["#." synthesis (#+ Synthesis)]]]])

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

    (#.Cons singletonS #.Nil)
    (generate singletonS)

    _
    (|> elemsS+
        (monad.map ////.monad generate)
        (:: ////.monad map _.vector/*))))

(def: #export (variant generate [lefts right? valueS])
  (-> Phase (Variant Synthesis) (Operation (Expression Any)))
  (:: ////.monad map
      (//runtime.variant (if right?
                           (inc lefts)
                           lefts)
                         right?)
      (generate valueS)))