diff options
author | Eduardo Julian | 2017-08-19 15:14:41 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-08-19 15:14:41 -0400 |
commit | 60cf511d714adb311176be6ad375ff57a373dc7a (patch) | |
tree | 6a92a369032e07451672dbc8dbc5c67d8443cc11 /stdlib/source/lux/concurrency/actor.lux | |
parent | 3f1baf2747993fec57b3d441c0e9264184f4e4e7 (diff) |
- "program:" now evaluates its body within an implicit IO monad.
- Fixed a bug with the types of actors and messages.
- Added Functor for queues.
- Small refactorings and fixes.
Diffstat (limited to 'stdlib/source/lux/concurrency/actor.lux')
-rw-r--r-- | stdlib/source/lux/concurrency/actor.lux | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/stdlib/source/lux/concurrency/actor.lux b/stdlib/source/lux/concurrency/actor.lux index 94dc81e48..04a0db61e 100644 --- a/stdlib/source/lux/concurrency/actor.lux +++ b/stdlib/source/lux/concurrency/actor.lux @@ -5,7 +5,7 @@ ["ex" exception #+ exception:]) [io #- run "io/" Monad<IO>] (data text/format - (coll [list "L/" Monoid<List> Monad<List>]) + (coll [list "L/" Monoid<List> Monad<List> Fold<List>]) [product]) [macro #+ with-gensyms Monad<Lux>] (macro [code] @@ -313,28 +313,39 @@ [actor-name (resolve-actor actor-name) #let [g!type (code;symbol (product;both id state-name actor-name)) g!message (code;local-symbol (get@ #name signature)) - g!refs (: (List Code) - (if (list;empty? actor-vars) - (list) - (|> actor-vars list;size n.dec - (list;n.range +0) (L/map (|>. code;nat (~) ($) (`)))))) - g!actor (code;symbol actor-name) - g!tvars (|> (get@ #vars signature) (L/append actor-vars) (L/map code;local-symbol)) + g!actor-vars (L/map code;local-symbol actor-vars) + g!actor (` ((~ (code;symbol actor-name)) (~@ g!actor-vars))) + g!all-vars (|> (get@ #vars signature) (L/map code;local-symbol) (L/append g!actor-vars)) g!inputsC (|> (get@ #inputs signature) (L/map (|>. product;left code;local-symbol))) g!inputsT (|> (get@ #inputs signature) (L/map product;right)) - g!outputT (get@ #output signature) g!state (|> signature (get@ #state) code;local-symbol) - g!self (|> signature (get@ #self) code;local-symbol)]] + g!self (|> signature (get@ #self) code;local-symbol) + g!actor-refs (: (List Code) + (if (list;empty? actor-vars) + (list) + (|> actor-vars list;size n.dec + (list;n.range +0) (L/map (|>. code;nat (~) ($) (`)))))) + ref-replacements (|> (if (list;empty? actor-vars) + (list) + (|> actor-vars list;size n.dec + (list;n.range +0) (L/map (|>. code;nat (~) ($) (`))))) + (: (List Code)) + (list;zip2 g!all-vars) + (: (List [Code Code]))) + g!outputT (L/fold (function [[g!var g!ref] outputT] + (code;replace g!var g!ref outputT)) + (get@ #output signature) + ref-replacements)]] (wrap (list (` (def: (~@ (csw;export export)) ((~ g!message) (~@ g!inputsC) (~ g!self)) (~ (|> annotations (with-message actor-name) csw;annotations)) - (All [(~@ g!tvars)] (-> (~@ g!inputsT) (~ g!actor) (T;Task (~ g!outputT)))) + (All [(~@ g!all-vars)] (-> (~@ g!inputsT) (~ g!actor) (T;Task (~ (get@ #output signature))))) (let [(~ g!task) (T;task (~ g!outputT))] (io;run (do io;Monad<IO> [(~ g!sent?) (;;send (function [(~ g!state) (~ g!self)] (do P;Monad<Promise> - [(~ g!return) (: (T;Task [((~ g!type) (~@ g!refs)) + [(~ g!return) (: (T;Task [((~ g!type) (~@ g!actor-refs)) (~ g!outputT)]) (do T;Monad<Task> [] |