aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/structure.lux
blob: 8d9334dca1c7272f3c2243551674171672d12481 (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:
  [library
   [lux #*
    [abstract
     ["." monad (#+ do)]]
    [data
     [collection
      ["." list]]]
    [target
     ["_" php (#+ Expression)]]]]
  ["." // #_
   ["#." runtime (#+ Operation Phase Generator)]
   ["#." primitive]
   ["///#" //// #_
    [analysis (#+ Variant Tuple)]
    ["#." synthesis (#+ Synthesis)]
    ["//#" /// #_
     ["#." phase ("#\." monad)]]]])

(def: #export (tuple expression archive elemsS+)
  (Generator (Tuple Synthesis))
  (case elemsS+
    #.Nil
    (///////phase\wrap (//primitive.text /////synthesis.unit))

    (#.Cons singletonS #.Nil)
    (expression archive singletonS)

    _
    (let [size (_.int (.int (list.size elemsS+)))]
      (|> elemsS+
          (monad.map ///////phase.monad (expression archive))
          (///////phase\map (|>> _.array/*
                                 (//runtime.tuple//make size)))))))

(def: #export (variant expression archive [lefts right? valueS])
  (Generator (Variant Synthesis))
  (let [tag (if right?
              (inc lefts)
              lefts)]
    (///////phase\map (//runtime.variant tag right?)
                      (expression archive valueS))))