aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/spec/compositor/common.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-04-26 23:41:03 -0400
committerEduardo Julian2019-04-26 23:41:03 -0400
commit5b655f558a0cc78b44736eec8eabeed6216f883f (patch)
tree3281b361b8d363bf9cdb0e0fbc6853d547a0dc4b /stdlib/source/spec/compositor/common.lux
parentff384c379036d790e32f419da39b1d524a1d89fe (diff)
Refactored the spec a bit better.
Diffstat (limited to '')
-rw-r--r--stdlib/source/spec/compositor/common.lux72
1 files changed, 72 insertions, 0 deletions
diff --git a/stdlib/source/spec/compositor/common.lux b/stdlib/source/spec/compositor/common.lux
new file mode 100644
index 000000000..4967c0f8c
--- /dev/null
+++ b/stdlib/source/spec/compositor/common.lux
@@ -0,0 +1,72 @@
+(.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: (runner (^slots [#platform.runtime #platform.phase #platform.host]) state)
+ (Instancer Runner)
+ (function (_ evaluation-name expressionS)
+ (do error.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 error.monad
+ [definitionG (<| (phase.run state)
+ generation.with-buffer
+ (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)])))))