aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/spec/compositor.lux
blob: a62d2efa948006ed519c8059bf89ccc33acb1311 (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
85
86
87
88
89
90
91
92
93
94
(.module:
  [lux #*
   [abstract
    [monad (#+ do)]]
   [control
    ["." io (#+ IO)]]
   [data
    ["." error (#+ Error)]]
   [tool
    [compiler
     ["." reference]
     ["." synthesis (#+ Synthesis)]
     ["." statement]
     ["." phase
      ["." macro (#+ Expander)]
      ["." generation (#+ Operation Bundle)]
      [extension
       ["." bundle]]]
     [default
      ["." platform (#+ Platform)]]]]])

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

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

## (def: #export (runner generate-runtime translate bundle state)
##   (-> (Operation Any) Phase Bundle (IO State)
##       Runner)
##   (function (_ valueS)
##     (|> (do phase.Monad<Operation>
##           [_ generate-runtime
##            program (translate valueS)]
##           (translation.evaluate! "runner" program))
##         translation.with-buffer
##         (phase.run [bundle (io.run state)]))))

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

## (def: #export (definer generate-runtime translate bundle state)
##   (-> (Operation Any) Phase Bundle (IO State) Definer)
##   (function (_ lux-name valueS)
##     (|> (do phase.Monad<Operation>
##           [_ generate-runtime
##            valueH (translate valueS)
##            [host-name host-value] (translation.define! lux-name valueH)
##            _ (translation.learn lux-name host-name)
##            program (translate (synthesis.constant lux-name))]
##           (translation.evaluate! "definer" program))
##         translation.with-buffer
##         (phase.run [bundle (io.run state)]))))

(def: (definer (^slots [#platform.runtime #platform.phase #platform.host])
               state)
  (Instancer Definer)
  (function (_ lux-name expressionS)
    (do error.monad
      [definitionG (<| (phase.run state)
                       (do phase.monad
                         [_ runtime
                          expressionG (phase expressionS)
                          [host-name host-value host-statement] (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 statement]
    (-> (Platform IO anchor expression statement)
        (Bundle anchor expression statement)
        Expander
        (-> expression statement)
        (IO (Error [Runner Definer]))))
  (do io.monad
    [?state (platform.initialize expander platform bundle program)]
    (wrap (do error.monad
            [[bundle' state] ?state
             #let [state (get@ [#statement.generation
                                #statement.state]
                               state)]]
            (wrap [(..runner platform state)
                   (..definer platform state)])))))