diff options
Diffstat (limited to 'stdlib/source/library/lux/control/concurrency/actor.lux')
-rw-r--r-- | stdlib/source/library/lux/control/concurrency/actor.lux | 109 |
1 files changed, 56 insertions, 53 deletions
diff --git a/stdlib/source/library/lux/control/concurrency/actor.lux b/stdlib/source/library/lux/control/concurrency/actor.lux index c4dd58b5e..b1eb1775d 100644 --- a/stdlib/source/library/lux/control/concurrency/actor.lux +++ b/stdlib/source/library/lux/control/concurrency/actor.lux @@ -21,7 +21,7 @@ ["[0]" list (.open: "[1]#[0]" monoid monad)]]] ["[0]" macro (.only with_symbols) ["[0]" code] - [syntax (.only syntax:) + [syntax (.only syntax) ["|[0]|" input] ["|[0]|" export]]] [math @@ -259,32 +259,34 @@ <code>.any behavior^))) -(syntax: .public (actor: [[export_policy [name vars] state_type [?on_mail messages]] ..actorP]) - (with_symbols [g!_] - (do meta.monad - [g!type (macro.symbol (format name "_primitive_type")) - .let [g!actor (code.local name) - g!vars (list#each code.local vars)]] - (in (list (` ((~! primitive:) (~ export_policy) ((~ g!type) (~+ g!vars)) - (~ state_type) - - (def: (~ export_policy) (~ g!actor) - (All ((~ g!_) (~+ g!vars)) - (..Behavior (~ state_type) ((~ g!type) (~+ g!vars)))) - [..#on_init (|>> ((~! primitive.abstraction) (~ g!type))) - ..#on_mail (~ (..on_mail g!_ ?on_mail))]) - - (~+ messages)))))))) - -(syntax: .public (actor [[state_type init] (<code>.tuple (<>.and <code>.any <code>.any)) - ?on_mail on_mail^]) - (with_symbols [g!_] - (in (list (` (is ((~! io.IO) (..Actor (~ state_type))) - (..spawn! (is (..Behavior (~ state_type) (~ state_type)) - [..#on_init (|>>) - ..#on_mail (~ (..on_mail g!_ ?on_mail))]) - (is (~ state_type) - (~ init))))))))) +(def: .public actor: + (syntax (_ [[export_policy [name vars] state_type [?on_mail messages]] ..actorP]) + (with_symbols [g!_] + (do meta.monad + [g!type (macro.symbol (format name "_primitive_type")) + .let [g!actor (code.local name) + g!vars (list#each code.local vars)]] + (in (list (` ((~! primitive:) (~ export_policy) ((~ g!type) (~+ g!vars)) + (~ state_type) + + (def: (~ export_policy) (~ g!actor) + (All ((~ g!_) (~+ g!vars)) + (..Behavior (~ state_type) ((~ g!type) (~+ g!vars)))) + [..#on_init (|>> ((~! primitive.abstraction) (~ g!type))) + ..#on_mail (~ (..on_mail g!_ ?on_mail))]) + + (~+ messages))))))))) + +(def: .public actor + (syntax (_ [[state_type init] (<code>.tuple (<>.and <code>.any <code>.any)) + ?on_mail on_mail^]) + (with_symbols [g!_] + (in (list (` (is ((~! io.IO) (..Actor (~ state_type))) + (..spawn! (is (..Behavior (~ state_type) (~ state_type)) + [..#on_init (|>>) + ..#on_mail (~ (..on_mail g!_ ?on_mail))]) + (is (~ state_type) + (~ init)))))))))) (type: Signature (Record @@ -316,32 +318,33 @@ <code>.any <code>.any))) -(syntax: .public (message: [[export_policy signature output_type body] ..messageP]) - (with_symbols [g!_ g!return] - (do meta.monad - [actor_scope primitive.current - .let [g!type (code.local (the primitive.#name actor_scope)) - g!message (code.local (the #name signature)) - g!actor_vars (the primitive.#type_vars actor_scope) - g!all_vars (|> signature (the #vars) (list#each code.local) (list#composite g!actor_vars)) - g!inputsC (|> signature (the #inputs) (list#each product.left)) - g!inputsT (|> signature (the #inputs) (list#each product.right)) - g!state (|> signature (the #state) code.local) - g!self (|> signature (the #self) code.local)]] - (in (list (` (def: (~ export_policy) ((~ g!message) (~+ g!inputsC)) - (All ((~ g!_) (~+ g!all_vars)) - (-> (~+ g!inputsT) - (..Message (~ (the primitive.#abstraction actor_scope)) - (~ output_type)))) - (function ((~ g!_) (~ g!state) (~ g!self)) - (let [(~ g!state) (as (~ (the primitive.#representation actor_scope)) - (~ g!state))] - (|> (~ body) - (is ((~! async.Async) ((~! try.Try) [(~ (the primitive.#representation actor_scope)) - (~ output_type)]))) - (as ((~! async.Async) ((~! try.Try) [(~ (the primitive.#abstraction actor_scope)) - (~ output_type)])))))))) - ))))) +(def: .public message: + (syntax (_ [[export_policy signature output_type body] ..messageP]) + (with_symbols [g!_ g!return] + (do meta.monad + [actor_scope primitive.current + .let [g!type (code.local (the primitive.#name actor_scope)) + g!message (code.local (the #name signature)) + g!actor_vars (the primitive.#type_vars actor_scope) + g!all_vars (|> signature (the #vars) (list#each code.local) (list#composite g!actor_vars)) + g!inputsC (|> signature (the #inputs) (list#each product.left)) + g!inputsT (|> signature (the #inputs) (list#each product.right)) + g!state (|> signature (the #state) code.local) + g!self (|> signature (the #self) code.local)]] + (in (list (` (def: (~ export_policy) ((~ g!message) (~+ g!inputsC)) + (All ((~ g!_) (~+ g!all_vars)) + (-> (~+ g!inputsT) + (..Message (~ (the primitive.#abstraction actor_scope)) + (~ output_type)))) + (function ((~ g!_) (~ g!state) (~ g!self)) + (let [(~ g!state) (as (~ (the primitive.#representation actor_scope)) + (~ g!state))] + (|> (~ body) + (is ((~! async.Async) ((~! try.Try) [(~ (the primitive.#representation actor_scope)) + (~ output_type)]))) + (as ((~! async.Async) ((~! try.Try) [(~ (the primitive.#abstraction actor_scope)) + (~ output_type)])))))))) + )))))) (type: .public Stop (IO Any)) |