mall: hood framework

This commit is contained in:
Philip Monk 2019-09-04 15:44:22 -07:00
parent f52e60bb09
commit 274e8aad90
No known key found for this signature in database
GPG Key ID: B66E1F02604E44EC
3 changed files with 189 additions and 4 deletions

175
pkg/arvo/age/hood.hoon Normal file
View File

@ -0,0 +1,175 @@
:: :: ::
:::: /hoon/hood/app :: ::
:: :: ::
/? 310 :: zuse version
/+ 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
hood-helm, hood-kiln, hood-drum, hood-write
:: :: ::
:::: :: ::
:: :: ::
|%
++ hood-module
:: each hood module follows this general shape
=> |%
+$ part [%module %0 pith]
+$ pith ~
::
+$ move [bone card]
+$ card $% [%fake ~]
==
--
|= [bowl:gall own=part]
|_ moz=(list move)
++ abet [(flop moz) own]
--
--
:: :: ::
:::: :: :: state handling
:: :: ::
!:
=> |% ::
++ hood-old :: unified old-state
{?($0 $1) lac/(map @tas hood-part-old)} ::
++ hood-1 :: unified state
{$1 lac/(map @tas hood-part)} ::
++ hood-good :: extract specific
=+ hed=$:hood-head
|@ ++ $
|: paw=$:hood-part
?- hed
$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)
==
--
++ hood-head _-:$:hood-part :: initialize state
++ hood-make ::
=+ $:{our/@p hed/hood-head} ::
|@ ++ $
?- hed
$drum (make:hood-drum our)
$helm *part:hood-helm
$kiln *part:hood-kiln
$write *part:hood-write
==
--
++ 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
$% {$drum $2 pith-2:hood-drum} ::
{$helm $0 pith:hood-helm} ::
{$kiln $0 pith:hood-kiln} ::
{$write $0 pith:hood-write} ::
== ::
-- ::
:: :: ::
:::: :: :: app proper
:: :: ::
^- agent:mall
=| hood-1 :: module states
=> |%
++ able :: find+make part
|= hid=bowl:mall
=+ 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}
|@ ++ $
[(flop +<-) (~(put by lac) +<+< +<+)]
--
:: :: ::
:::: :: :: 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
:: [~ %_(+> lac (~(put by lac) -.dat dat))]
::
::
++ from-module :: create wrapper
|* _[identity=%module start=..$ finish=_abet]:(hood-module)
|= hid=bowl:mall
=- [wrap=- *start] :: usage (wrap handle-arm):from-foo
|* handle/_finish
|= a=_+<.handle
=. +>.handle (start hid ((able hid) identity))
(ably (handle a))
:: per-module interface wrappers
++ 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))
--
|_ hid/bowl:mall :: gall environment
++ handle-init
`..handle-init
::
++ handle-prep
|= =old-state=vase
=/ old-state !<(hood-1 old-state-vase)
?~ old-state
~& %prep-lost
`..handle-init
~& %prep-found
`..handle-init(lac lac.u.old-state)
::
++ handle-poke
|= [=mark =vase]
^- (quip move:agent:mall agent:mall)
=^ moves lac
?+ mark ~|([%poke-hood-bad-mark mark] !!)
%atom ((wrap poke-atom):(from-helm hid) (need !<(@ vase)))
==
[moves ..handle-init]
::
++ handle-peer
|= path
`..handle-init
::
++ handle-pull
|= path
`..handle-init
::
++ handle-peek
|= path
*(unit (unit cage))
::
++ handle-mall
|= [wire internal-gift:mall]
`..handle-init
::
++ handle-take
|= [wire vase]
`..handle-init
::
++ handle-lame
|= [term tang]
`..handle-init
::
++ handle-stay
!>([%1 lac])
--

View File

@ -12,8 +12,8 @@
^- (quip move _this)
:_ this :_ ~
?+ arg ~|(%bad-arg !!)
%conf `move`[ost.bowl %conf-mall / [our.bowl %first] [our.bowl %home]]
%poke `move`[ost.bowl %deal-mall / [our.bowl our.bowl] %first %poke %noun !>(%hey)]
%conf `move`[ost.bowl %conf-mall / [our.bowl %hood] [our.bowl %home]]
%poke `move`[ost.bowl %deal-mall / [our.bowl our.bowl] %hood %poke %atom !>(%hey)]
==
::
++ onto

View File

@ -57,11 +57,19 @@
== ::
--
=+ moz=((list move))
=| moi=(list move:agent:mall)
|%
++ abet :: resolve
[(flop moz) %_(+<+.$ hoc (~(put by hoc) ost sez))]
::
++ abei
[(flop moi) %_(+<+.$ hoc (~(put by hoc) ost sez))]
::
++ emit |=(card %_(+> moz [[ost +<] moz])) :: return card
++ emii
|= (wind internal-note:mall internal-gift:mall)
%_(+> moi [[ost +<] moi])
::
++ emil :: return cards
|= (list card)
^+ +>
@ -144,8 +152,10 @@
|= ato/@
=+ len=(scow %ud (met 3 ato))
=+ gum=(scow %p (mug ato))
=< abet
(emit %flog /di %text "< {<src>}: atom: {len} bytes, mug {gum}")
=< abei
%^ emii %pass /di
:+ %meta %d
!> [%flog %text "< {<src>}: atom: {len} bytes, mug {gum}"]
::
++ coup-hi
|= {pax/path cop/(unit tang)} =< abet