aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/spec/compositor/common.lux
blob: 05fbe7fc209ab8f1ba1275f0bcb449f7e8049a3f (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
(.module:
  [lux #*
   [abstract
    [monad (#+ do)]]
   [control
    ["." io (#+ IO)]
    ["." try (#+ Try)]]
   [tool
    [compiler
     ["." reference]
     ["." synthesis (#+ Synthesis)]
     ["." directive]
     ["." phase
      ["." macro (#+ Expander)]
      ["." generation (#+ Operation Bundle)]
      [extension
       ["." bundle]]]
     [default
      ["." platform (#+ Platform)]]]]])

(type: #export Runner (-> Text Synthesis (Try Any)))
(type: #export Definer (-> Name Synthesis (Try Any)))

(type: #export (Instancer what)
  (All [anchor expression directive]
    (-> (Platform IO anchor expression directive)
        (generation.State+ anchor expression directive)
        what)))

(def: (runner (^slots [#platform.runtime #platform.phase #platform.host]) state)
  (Instancer Runner)
  (function (_ evaluation-name expressionS)
    (do try.monad
      [expressionG (<| (phase.run state)
                       generation.with-buffer
                       (do phase.monad
                         [_ runtime]
                         (phase expressionS)))]
      (:: host evaluate! evaluation-name expressionG))))

(def: (definer (^slots [#platform.runtime #platform.phase #platform.host])
               state)
  (Instancer Definer)
  (function (_ lux-name expressionS)
    (do try.monad
      [definitionG (<| (phase.run state)
                       generation.with-buffer
                       (do phase.monad
                         [_ runtime
                          expressionG (phase expressionS)
                          [host-name host-value host-directive] (generation.define! lux-name expressionG)
                          _ (generation.learn lux-name host-name)]
                         (phase (synthesis.constant lux-name))))]
      (:: host evaluate! "definer" definitionG))))

(def: #export (executors platform bundle expander program)
  (All [anchor expression directive]
    (-> (Platform IO anchor expression directive)
        (Bundle anchor expression directive)
        Expander
        (-> expression directive)
        (IO (Try [(directive.State+ anchor expression directive)
                  Runner
                  Definer]))))
  (do io.monad
    [?state (platform.initialize expander platform bundle program)]
    (wrap (do try.monad
            [[directive-bundle directive-state] ?state
             #let [generation-state (get@ [#directive.generation
                                           #directive.state]
                                          directive-state)]]
            (wrap [[directive-bundle directive-state]
                   (..runner platform generation-state)
                   (..definer platform generation-state)])))))