aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby.lux
blob: 4e5581db5ffe14ed867a2495749fdba0853031ed (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" exception]]
   [meta
    [macro
     ["^" pattern]]
    [compiler
     [target
      ["_" ruby]]]]]]
 ["[0]" /
  [runtime (.only Phase Phase!)]
  ["[1][0]" primitive]
  ["[1][0]" structure]
  ["[1][0]" reference]
  ["[1][0]" function]
  ["[1][0]" when]
  ["[1][0]" loop]
  ["/[1]" //
   ["[1][0]" reference]
   ["/[1]" //
    ["[1][0]" extension (.only)
     [translation
      [ruby
       ["[1]/[0]" common]]]]
    ["/[1]" //
     [analysis (.only)]
     ["[0]" phase (.use "[1]#[0]" monad)]
     ["[1][0]" synthesis]
     ["//[1]" ///
      [reference (.only)
       [variable (.only)]]]]]]])

(exception.def .public cannot_recur_as_an_expression)

(def .public (expression extender lux)
  (-> ///extension.Extender Lux
      Phase)
  (function (expression archive synthesis)
    (when synthesis
      (^.with_template [<tag> <translator>]
        [(<tag> @ value)
         (phase#in (<translator> value))])
      ([////synthesis.bit  /primitive.bit]
       [////synthesis.i64  /primitive.i64]
       [////synthesis.f64  /primitive.f64]
       [////synthesis.text /primitive.text])

      (^.with_template [<tag> <translator>]
        [(<tag> @ value)
         (<translator> expression archive value)])
      ([////synthesis.variant /structure.variant]
       [////synthesis.tuple /structure.tuple]
       
       [////synthesis.branch/exec /when.exec]
       [////synthesis.branch/let /when.let]
       [////synthesis.branch/if /when.if]
       [////synthesis.branch/get /when.get]
       
       [////synthesis.function/apply /function.apply])

      (^.with_template [<tag> <translator>]
        [(<tag> @ value)
         (<translator> ///extension/common.statement expression archive value)])
      ([////synthesis.branch/when /when.when]
       [////synthesis.loop/scope /loop.scope]
       [////synthesis.function/abstraction /function.function])

      (////synthesis.loop/again @ _)
      (phase.except ..cannot_recur_as_an_expression [])

      [@ {////synthesis.#Reference value}]
      (//reference.reference /reference.system archive value)

      [@ {////synthesis.#Extension [name parameters]}]
      (///extension.application extender lux expression archive .Translation false name parameters
                                (|>>)
                                (function (_ _) {.#None})))))