urbit/pkg/arvo/app/hood.hoon

224 lines
7.9 KiB
Plaintext
Raw Normal View History

2019-09-05 01:44:22 +03:00
:: :: ::
:::: /hoon/hood/app :: ::
:: :: ::
/? 310 :: zuse version
2019-09-06 06:01:31 +03:00
/- *sole
2019-09-05 01:44:22 +03:00
/+ sole, :: libraries
:: XX these should really be separate apps, as
:: none of them interact with each other in
:: any fashion; however, to reduce boot-time
:: complexity and work around the current
:: non-functionality of end-to-end acknowledgments,
:: they have been bundled into :hood
::
:: |command handlers
2019-11-14 21:39:50 +03:00
hood-helm, hood-kiln, hood-drum, hood-write
2019-09-05 01:44:22 +03:00
:: :: ::
:::: :: ::
:: :: ::
|%
++ hood-module
:: each hood module follows this general shape
=> |%
+$ part [%module %0 pith]
+$ pith ~
++ take
|~ [wire sign-arvo]
2019-11-19 07:36:21 +03:00
*(quip card:agent:gall part)
++ take-agent
2019-11-19 07:36:21 +03:00
|~ [wire gift:agent:gall]
*(quip card:agent:gall part)
++ poke
|~ [mark vase]
2019-11-19 07:36:21 +03:00
*(quip card:agent:gall part)
2019-09-05 01:44:22 +03:00
--
2019-11-19 07:36:21 +03:00
|= [bowl:gall own=part]
|_ moz=(list card:agent:gall)
2019-09-05 01:44:22 +03:00
++ abet [(flop moz) own]
--
--
:: :: ::
:::: :: :: state handling
:: :: ::
!:
=> |% ::
++ hood-old :: unified old-state
{?($1 $2) lac/(map @tas hood-part-old)} ::
2019-09-05 01:44:22 +03:00
++ hood-1 :: unified state
{$2 lac/(map @tas hood-part)} ::
2019-09-05 01:44:22 +03:00
++ hood-good :: extract specific
=+ hed=$:hood-head
|@ ++ $
|: paw=$:hood-part
?- hed
2019-11-14 21:39:50 +03:00
$drum ?>(?=($drum -.paw) `part:hood-drum`paw)
$helm ?>(?=($helm -.paw) `part:hood-helm`paw)
$kiln ?>(?=($kiln -.paw) `part:hood-kiln`paw)
$write ?>(?=($write -.paw) `part:hood-write`paw)
2019-09-05 01:44:22 +03:00
==
--
++ hood-head _-:$:hood-part :: initialize state
++ hood-make ::
=+ $:{our/@p hed/hood-head} ::
|@ ++ $
?- hed
2019-11-14 21:39:50 +03:00
$drum (make:hood-drum our)
$helm *part:hood-helm
$kiln *part:hood-kiln
$write *part:hood-write
2019-09-05 01:44:22 +03:00
==
--
++ hood-part-old hood-part :: old state for ++prep
++ hood-port :: state transition
|: paw=$:hood-part-old ^- hood-part ::
paw ::
:: ::
++ hood-part :: current module state
2019-11-14 21:39:50 +03:00
$% {$drum $2 pith-2:hood-drum} ::
{$helm $0 pith:hood-helm} ::
{$kiln $0 pith:hood-kiln} ::
{$write $0 pith:hood-write} ::
2019-09-05 01:44:22 +03:00
== ::
-- ::
:: :: ::
:::: :: :: app proper
:: :: ::
2019-11-19 07:36:21 +03:00
^- agent:gall
2019-09-05 01:44:22 +03:00
=| hood-1 :: module states
2019-09-10 06:00:56 +03:00
=> |%
++ help
2019-11-19 07:36:21 +03:00
|= hid/bowl:gall
2019-09-10 06:00:56 +03:00
|%
++ able :: find+make part
=+ hed=$:hood-head
|@ ++ $
=+ rep=(~(get by lac) hed)
=+ par=?^(rep u.rep `hood-part`(hood-make our.hid hed))
((hood-good hed) par)
--
::
++ ably :: save part
=+ $:{(list) hood-part}
|@ ++ $
2019-11-14 03:16:36 +03:00
[+<- (~(put by lac) +<+< +<+)]
2019-09-10 06:00:56 +03:00
--
2019-09-05 01:44:22 +03:00
:: :: ::
2019-09-10 06:00:56 +03:00
:::: :: :: generic handling
:: :: ::
++ prep
|= old/(unit hood-old) ^- (quip _!! _+>)
:- ~
?~ old +>
+>(lac (~(run by lac.u.old) hood-port))
::
++ poke-hood-load :: recover lost brain
|= dat/hood-part
?> =(our.hid src.hid)
~& loaded+-.dat
[~ (~(put by lac) -.dat dat)]
::
::
++ from-module :: create wrapper
|* _[identity=%module start=..$ finish=_abet]:(hood-module)
=- [wrap=- *start] :: usage (wrap handle-arm):from-foo
|* handle/_finish
|= a=_+<.handle
=. +>.handle (start hid (able identity))
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _lac)
%- ably
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall hood-part)
(handle a)
2019-09-10 06:00:56 +03:00
:: per-module interface wrappers
2019-11-14 21:39:50 +03:00
++ from-drum (from-module %drum [..$ _se-abet]:(hood-drum))
++ from-helm (from-module %helm [..$ _abet]:(hood-helm))
++ from-kiln (from-module %kiln [..$ _abet]:(hood-kiln))
++ from-write (from-module %write [..$ _abet]:(hood-write))
2019-09-10 06:00:56 +03:00
--
2019-09-05 01:44:22 +03:00
--
2019-11-19 07:36:21 +03:00
|_ hid/bowl:gall :: gall environment
2019-11-07 09:19:32 +03:00
++ on-init
`..on-init
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-save
!>([%2 lac])
::
2019-11-07 09:19:32 +03:00
++ on-load
2019-09-05 01:44:22 +03:00
|= =old-state=vase
=/ old-state !<(hood-old old-state-vase)
=^ cards lac
=. lac lac.old-state
?. ?=(%1 -.old-state)
`lac
((wrap on-load):from-drum:(help hid) %1)
[cards ..on-init]
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-poke
2019-09-05 01:44:22 +03:00
|= [=mark =vase]
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall agent:gall)
2019-09-06 04:18:31 +03:00
=/ h (help hid)
=^ cards lac
?: =(%helm (end 3 4 mark))
((wrap poke):from-helm:h mark vase)
?: =(%drum (end 3 4 mark))
((wrap poke):from-drum:h mark vase)
?: =(%kiln (end 3 4 mark))
((wrap poke):from-kiln:h mark vase)
?: =(%write (end 3 5 mark))
((wrap poke):from-write:h mark vase)
:: XX should rename and move to libs
::
2019-09-05 01:44:22 +03:00
?+ mark ~|([%poke-hood-bad-mark mark] !!)
%hood-load (poke-hood-load:h !<(hood-part vase))
%atom ((wrap poke-atom):from-helm:h !<(@ vase))
%dill-belt ((wrap poke-dill-belt):from-drum:h !<(dill-belt:dill vase))
%dill-blit ((wrap poke-dill-blit):from-drum:h !<(dill-blit:dill vase))
%hood-sync ((wrap poke-sync):from-kiln:h !<([desk ship desk] vase))
2019-09-05 01:44:22 +03:00
==
2019-11-07 09:19:32 +03:00
[cards ..on-init]
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-watch
2019-09-06 06:01:31 +03:00
|= =path
=/ h (help hid)
=^ cards lac
2019-09-06 06:01:31 +03:00
?+ path ~|([%hood-bad-path wire] !!)
[%drum *] ((wrap peer):from-drum:h t.path)
==
2019-11-07 09:19:32 +03:00
[cards ..on-init]
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-leave
2019-09-05 01:44:22 +03:00
|= path
2019-11-07 09:19:32 +03:00
`..on-init
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-peek
2019-09-05 01:44:22 +03:00
|= path
*(unit (unit cage))
::
2019-11-07 09:19:32 +03:00
++ on-agent
2019-11-19 07:36:21 +03:00
|= [=wire =sign:agent:gall]
2019-09-06 04:18:31 +03:00
=/ h (help hid)
=^ cards lac
2019-09-06 04:18:31 +03:00
?+ wire ~|([%hood-bad-wire wire] !!)
[%helm *] ((wrap take-agent):from-helm:h wire sign)
[%kiln *] ((wrap take-agent):from-kiln:h wire sign)
[%drum *] ((wrap take-agent):from-drum:h wire sign)
[%write *] ((wrap take-agent):from-write:h wire sign)
2019-09-06 04:18:31 +03:00
==
2019-11-07 09:19:32 +03:00
[cards ..on-init]
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-arvo
|= [=wire =sign-arvo]
2019-09-06 04:18:31 +03:00
=/ h (help hid)
=^ cards lac
2019-09-06 04:18:31 +03:00
?+ wire ~|([%hood-bad-wire wire] !!)
[%helm *] ((wrap take):from-helm:h t.wire sign-arvo)
[%drum *] ((wrap take):from-drum:h t.wire sign-arvo)
[%kiln *] ((wrap take-general):from-kiln:h t.wire sign-arvo)
[%write *] ((wrap take):from-write:h t.wire sign-arvo)
2019-09-06 04:18:31 +03:00
==
2019-11-07 09:19:32 +03:00
[cards ..on-init]
2019-09-05 01:44:22 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-fail
2019-09-05 01:44:22 +03:00
|= [term tang]
2019-11-07 09:19:32 +03:00
`..on-init
2019-09-05 01:44:22 +03:00
--