2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
|
|
|
Effect Types and Their Noun Conversions
|
|
|
|
-}
|
2020-01-24 08:28:38 +03:00
|
|
|
module Urbit.Arvo.Effect where
|
2019-07-24 04:34:16 +03:00
|
|
|
|
2020-06-08 20:24:05 +03:00
|
|
|
import Urbit.Noun.Time
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Prelude
|
2019-07-24 04:34:16 +03:00
|
|
|
|
2020-01-24 08:28:38 +03:00
|
|
|
import Urbit.Arvo.Common (KingId(..), ServId(..))
|
|
|
|
import Urbit.Arvo.Common (Header, HttpEvent, HttpServerConf, Method, Mime)
|
|
|
|
import Urbit.Arvo.Common (AmesDest, Turf)
|
|
|
|
import Urbit.Arvo.Common (ReOrg(..), reorgThroughNoun)
|
|
|
|
import Urbit.Arvo.Common (Desk)
|
2019-07-24 04:34:16 +03:00
|
|
|
|
|
|
|
|
2019-07-25 04:59:45 +03:00
|
|
|
-- Newt Effects ----------------------------------------------------------------
|
2019-07-24 04:34:16 +03:00
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-25 04:59:45 +03:00
|
|
|
%turf -- Set which domain names we've bound.
|
|
|
|
%send -- Send a UDP packet.
|
2019-07-24 04:34:16 +03:00
|
|
|
-}
|
|
|
|
data NewtEf
|
|
|
|
= NewtEfTurf (Atom, ()) [Turf]
|
2019-08-01 00:52:49 +03:00
|
|
|
| NewtEfSend (Atom, ()) AmesDest Bytes
|
2019-07-24 04:34:16 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''NewtEf
|
|
|
|
|
|
|
|
|
|
|
|
-- HTTP Client Effects ---------------------------------------------------------
|
|
|
|
|
|
|
|
data HttpClientReq = HttpClientReq
|
|
|
|
{ method :: Method
|
|
|
|
, url :: Cord
|
|
|
|
, headerList :: [Header]
|
|
|
|
, body :: Maybe Octs
|
|
|
|
}
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-24 04:34:16 +03:00
|
|
|
%request -- TODO
|
|
|
|
%cancel-request -- TODO
|
|
|
|
-}
|
|
|
|
data HttpClientEf
|
|
|
|
= HCERequest (Atom, ()) Word HttpClientReq
|
|
|
|
| HCECancelRequest Path Word
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''HttpClientReq
|
|
|
|
deriveNoun ''HttpClientEf
|
|
|
|
|
|
|
|
|
|
|
|
-- HTTP Server Effects ---------------------------------------------------------
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-24 04:34:16 +03:00
|
|
|
%set-config -- Update HTTP server configuration.
|
|
|
|
%response -- Respond to an active HTTP request.
|
|
|
|
-}
|
|
|
|
data HttpServerEf
|
2019-08-08 01:24:02 +03:00
|
|
|
= HSESetConfig (ServId, ()) HttpServerConf
|
|
|
|
| HSEResponse (ServId, UD, UD, ()) HttpEvent
|
2019-07-24 04:34:16 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''HttpServerEf
|
|
|
|
|
|
|
|
|
|
|
|
-- File System Effects ---------------------------------------------------------
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-24 04:34:16 +03:00
|
|
|
%hill -- TODO
|
|
|
|
%dirk -- mark mount dirty
|
|
|
|
%ergo -- TODO
|
|
|
|
%ogre -- TODO
|
|
|
|
-}
|
|
|
|
data SyncEf
|
2019-09-10 23:14:43 +03:00
|
|
|
= SyncEfHill () [Desk]
|
|
|
|
| SyncEfDirk Path Desk
|
|
|
|
| SyncEfErgo Path Desk [(Path, Maybe Mime)]
|
|
|
|
| SyncEfOgre Path Desk
|
2019-07-24 04:34:16 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''SyncEf
|
|
|
|
|
|
|
|
|
|
|
|
-- Timer Effects ---------------------------------------------------------------
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-24 04:34:16 +03:00
|
|
|
%doze -- Set or clear timer.
|
|
|
|
%void -- Nasty hack to make the parser not treat this as a record.
|
|
|
|
-}
|
|
|
|
data BehnEf
|
2019-08-08 01:24:02 +03:00
|
|
|
= BehnEfDoze (KingId, ()) (Maybe Wen)
|
2019-07-24 04:34:16 +03:00
|
|
|
| BehnEfVoid Void
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''BehnEf
|
|
|
|
|
|
|
|
|
|
|
|
-- Terminal Effects ------------------------------------------------------------
|
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-24 04:34:16 +03:00
|
|
|
%bel -- TODO
|
|
|
|
%clr -- TODO
|
|
|
|
%hop -- TODO
|
|
|
|
%lin -- TODO
|
|
|
|
%mor -- TODO
|
|
|
|
%sag -- TODO
|
|
|
|
%sav -- TODO
|
|
|
|
%url -- TODO
|
|
|
|
-}
|
|
|
|
data Blit
|
2019-08-01 08:16:02 +03:00
|
|
|
= Bel ()
|
|
|
|
| Clr ()
|
2019-07-24 04:34:16 +03:00
|
|
|
| Hop Word64
|
|
|
|
| Lin [Char]
|
2019-08-01 08:16:02 +03:00
|
|
|
| Mor ()
|
2019-07-24 04:34:16 +03:00
|
|
|
| Sag Path Noun
|
|
|
|
| Sav Path Atom
|
|
|
|
| Url Cord
|
2019-09-04 02:38:14 +03:00
|
|
|
deriving (Eq, Ord)
|
|
|
|
|
|
|
|
-- Manual instance to not save the noun/atom in Sag/Sav, because these can be
|
|
|
|
-- megabytes and makes king hang.
|
|
|
|
instance Show Blit where
|
2019-10-01 21:36:46 +03:00
|
|
|
show (Bel ()) = "Bel ()"
|
|
|
|
show (Clr ()) = "Clr ()"
|
|
|
|
show (Hop x) = "Hop " ++ (show x)
|
|
|
|
show (Lin c) = "Lin " ++ (show c)
|
|
|
|
show (Mor ()) = "Mor ()"
|
2019-09-04 02:38:14 +03:00
|
|
|
show (Sag path _) = "Sag " ++ (show path)
|
|
|
|
show (Sav path _) = "Sav " ++ (show path)
|
2019-10-01 21:36:46 +03:00
|
|
|
show (Url c) = "Url " ++ (show c)
|
2019-07-24 04:34:16 +03:00
|
|
|
|
2020-01-23 07:16:09 +03:00
|
|
|
{-|
|
2019-07-24 04:34:16 +03:00
|
|
|
%blip -- TODO
|
|
|
|
%init -- TODO
|
|
|
|
%logo -- Shutdown
|
|
|
|
%mass -- Measure memory usage (unused)
|
|
|
|
-}
|
|
|
|
data TermEf
|
2019-08-24 00:07:58 +03:00
|
|
|
= TermEfBlit (UD, ()) [Blit]
|
2019-10-01 21:36:46 +03:00
|
|
|
| TermEfInit (UD, ()) Ship
|
2019-07-24 04:34:16 +03:00
|
|
|
| TermEfLogo Path ()
|
|
|
|
| TermEfMass Path Noun -- Irrelevant
|
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''Blit
|
|
|
|
deriveNoun ''TermEf
|
|
|
|
|
|
|
|
|
|
|
|
-- IO-Driver Routing -----------------------------------------------------------
|
|
|
|
|
|
|
|
data VaneEf
|
2019-07-24 07:03:04 +03:00
|
|
|
= VENewt NewtEf
|
|
|
|
| VEHttpClient HttpClientEf
|
|
|
|
| VEHttpServer HttpServerEf
|
|
|
|
| VEBehn BehnEf
|
|
|
|
| VETerm TermEf
|
|
|
|
| VEClay SyncEf
|
|
|
|
| VESync SyncEf
|
|
|
|
| VEBoat SyncEf
|
2019-07-24 04:34:16 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
|
|
|
deriveNoun ''VaneEf
|
|
|
|
|
|
|
|
|
2019-07-24 07:03:04 +03:00
|
|
|
-- Top-Level Ef Type -----------------------------------------------------------
|
2019-07-24 04:34:16 +03:00
|
|
|
|
2019-07-24 07:03:04 +03:00
|
|
|
data Ef
|
|
|
|
= EfVane VaneEf
|
|
|
|
| EfVega Cord EvilPath -- second path component, rest of path
|
|
|
|
| EfExit Cord EvilPath -- second path component, rest of path
|
2019-07-24 04:34:16 +03:00
|
|
|
deriving (Eq, Ord, Show)
|
|
|
|
|
2019-07-24 07:03:04 +03:00
|
|
|
instance ToNoun Ef where
|
2019-07-24 04:34:16 +03:00
|
|
|
toNoun = \case
|
2019-07-24 07:03:04 +03:00
|
|
|
EfVane v -> toNoun $ reorgThroughNoun ("", v)
|
|
|
|
EfExit s p -> toNoun $ ReOrg "" s "exit" p (A 0)
|
|
|
|
EfVega s p -> toNoun $ ReOrg "" s "vega" p (A 0)
|
|
|
|
|
|
|
|
instance FromNoun Ef where
|
|
|
|
parseNoun = parseNoun >=> \case
|
|
|
|
ReOrg "" s "exit" p (A 0) -> pure (EfExit s p)
|
|
|
|
ReOrg "" s "exit" p _ -> fail "%exit effect expects nil value"
|
|
|
|
ReOrg "" s "vega" p (A 0) -> pure (EfVega s p)
|
|
|
|
ReOrg "" s "vega" p _ -> fail "%vega effect expects nil value"
|
|
|
|
ReOrg "" s tag p val -> EfVane <$> parseNoun (toNoun (s, tag, p, val))
|
|
|
|
ReOrg _ _ _ _ _ -> fail "Non-empty first path-element"
|