2022-01-21 21:48:05 +03:00
|
|
|
|
:: %khan, thread runner
|
2022-02-08 19:42:22 +03:00
|
|
|
|
::
|
|
|
|
|
:: this vane presents a command/response interface for running
|
|
|
|
|
:: threads. two modes are supported: %fard for intra-arvo
|
|
|
|
|
:: requests (i.e. within the same kernel space) and %fyrd for
|
|
|
|
|
:: external requests (e.g. from the unix control plane.)
|
|
|
|
|
::
|
|
|
|
|
:: both modes take a thread start request consisting of a
|
|
|
|
|
:: namespace, thread name, and input data; they respond over the
|
|
|
|
|
:: same duct with either success or failure. %fard takes its
|
2022-02-12 08:14:39 +03:00
|
|
|
|
:: input arguments as a $vase and produces %arow, which contains
|
2022-02-08 19:42:22 +03:00
|
|
|
|
:: a $vase on success (or $tang on failure). %fyrd takes an
|
|
|
|
|
:: output mark and input `(cask)` (short for `(cask *)`); it
|
2022-02-12 08:14:39 +03:00
|
|
|
|
:: produces %avow, which contains a `(cask)` on success.
|
2022-02-08 19:42:22 +03:00
|
|
|
|
::
|
|
|
|
|
:: %fard passes its arguments and produces its result
|
|
|
|
|
:: unmodified. %fyrd does mark conversion on both ends, and
|
|
|
|
|
:: additionally lifts its input into a $unit. this second step
|
|
|
|
|
:: is done because threads conventionally take their input as a
|
|
|
|
|
:: $unit, with ~ for the case of "no arguments".
|
|
|
|
|
::
|
|
|
|
|
:: n.b. the current convention for threads is to use !< to
|
|
|
|
|
:: unpack their input into a well-defined type. !< imposes the
|
|
|
|
|
:: requirement that the input type nests within the specified
|
|
|
|
|
:: type. this limits %fyrd to threads with inputs for which a
|
|
|
|
|
:: named mark exists; it is impossible to use %noun in general
|
|
|
|
|
:: since it does not nest. to support using the %noun mark for
|
|
|
|
|
:: inputs, it would be sufficient to convert threads to use ;;
|
|
|
|
|
:: rather than !< on their inputs, at the cost of losing type
|
|
|
|
|
:: validation.
|
2022-01-21 21:48:05 +03:00
|
|
|
|
!:
|
|
|
|
|
!? 164
|
|
|
|
|
::
|
2022-02-12 09:13:31 +03:00
|
|
|
|
=, khan
|
2022-01-21 21:48:05 +03:00
|
|
|
|
|= our=ship
|
2022-02-12 08:14:39 +03:00
|
|
|
|
=> |% :: %khan types
|
2022-02-12 09:13:31 +03:00
|
|
|
|
+$ move [p=duct q=(wite note gift)] ::
|
2022-02-12 08:14:39 +03:00
|
|
|
|
+$ note :: out request $->
|
|
|
|
|
$~ [%g %deal *sock *term *deal:gall] ::
|
|
|
|
|
$% $: %g :: to %gall
|
2022-01-22 04:46:59 +03:00
|
|
|
|
$>(%deal task:gall) :: full transmission
|
2022-02-12 08:14:39 +03:00
|
|
|
|
== ::
|
|
|
|
|
$: %k :: to self
|
2022-02-12 09:13:31 +03:00
|
|
|
|
$>(%fard task) :: internal thread
|
2022-01-22 04:46:59 +03:00
|
|
|
|
== == ::
|
2022-02-12 08:14:39 +03:00
|
|
|
|
+$ sign :: in response $<-
|
|
|
|
|
$% $: %gall :: from %gall
|
|
|
|
|
$>(%unto gift:gall) :: update
|
|
|
|
|
== ::
|
|
|
|
|
$: %khan :: from self
|
2022-02-12 09:13:31 +03:00
|
|
|
|
$> ?(%arow %avow) gift :: thread result
|
2022-02-12 08:14:39 +03:00
|
|
|
|
== == ::
|
|
|
|
|
+$ khan-state ::
|
|
|
|
|
[%2 hey=duct] :: current unix duct
|
|
|
|
|
-- ::
|
2022-01-22 04:46:59 +03:00
|
|
|
|
=>
|
|
|
|
|
|%
|
2022-02-12 08:14:39 +03:00
|
|
|
|
++ get-beak
|
2022-02-12 09:13:31 +03:00
|
|
|
|
|= [=bear now=@da]
|
2022-02-12 08:14:39 +03:00
|
|
|
|
?@(bear [our bear %da now] bear)
|
2022-01-27 04:41:01 +03:00
|
|
|
|
++ get-dais
|
|
|
|
|
|= [=beak =mark rof=roof]
|
|
|
|
|
^- dais:clay
|
|
|
|
|
?~ ret=(rof ~ %cb beak /[mark])
|
|
|
|
|
~|(%mark-unknown !!)
|
|
|
|
|
?~ u.ret
|
|
|
|
|
~|(%mark-invalid !!)
|
|
|
|
|
?> =(%dais p.u.u.ret)
|
|
|
|
|
!<(dais:clay q.u.u.ret)
|
2022-02-12 08:14:39 +03:00
|
|
|
|
++ make-wire
|
|
|
|
|
|= [=beak =mark]
|
|
|
|
|
^- wire
|
|
|
|
|
:~ %fyrd
|
|
|
|
|
(scot %p p.beak)
|
|
|
|
|
q.beak
|
|
|
|
|
-.r.beak
|
|
|
|
|
?- -.r.beak
|
|
|
|
|
%da (scot %da p.r.beak)
|
|
|
|
|
%tas p.r.beak
|
|
|
|
|
%ud (scot %ud p.r.beak)
|
|
|
|
|
==
|
|
|
|
|
mark
|
|
|
|
|
==
|
|
|
|
|
++ read-wire
|
|
|
|
|
|= =wire
|
|
|
|
|
^- (pair beak mark)
|
|
|
|
|
=/ ras (snag 4 wire)
|
|
|
|
|
:_ (snag 5 wire)
|
|
|
|
|
:+ (slav %p (snag 1 wire))
|
|
|
|
|
(snag 2 wire)
|
|
|
|
|
?+ (snag 3 wire) !!
|
|
|
|
|
%da [%da (slav %da ras)]
|
|
|
|
|
%tas [%tas ras]
|
|
|
|
|
%ud [%ud (slav %ud ras)]
|
|
|
|
|
==
|
2022-01-22 04:46:59 +03:00
|
|
|
|
++ start-spider
|
2022-02-08 01:46:02 +03:00
|
|
|
|
|= [our=@p =vase]
|
2022-01-26 02:37:48 +03:00
|
|
|
|
^- note
|
2022-02-08 01:46:02 +03:00
|
|
|
|
[%g %deal [our our] %spider %poke %spider-start vase]
|
2022-01-22 04:46:59 +03:00
|
|
|
|
++ watch-spider
|
2022-01-26 02:37:48 +03:00
|
|
|
|
|= [our=@p =path]
|
|
|
|
|
^- note
|
|
|
|
|
[%g %deal [our our] %spider %watch path]
|
2022-01-22 04:46:59 +03:00
|
|
|
|
--
|
2022-01-21 21:48:05 +03:00
|
|
|
|
=| khan-state
|
|
|
|
|
=* state -
|
|
|
|
|
|= [now=@da eny=@uvJ rof=roof]
|
|
|
|
|
=* khan-gate .
|
|
|
|
|
^?
|
|
|
|
|
|%
|
2022-02-12 09:13:31 +03:00
|
|
|
|
:: +call: handle a +task request
|
2022-01-21 21:48:05 +03:00
|
|
|
|
::
|
|
|
|
|
++ call
|
|
|
|
|
|= $: hen=duct
|
|
|
|
|
dud=(unit goof)
|
2022-02-12 09:13:31 +03:00
|
|
|
|
wrapped-task=(hobo task)
|
2022-01-21 21:48:05 +03:00
|
|
|
|
==
|
|
|
|
|
^- [(list move) _khan-gate]
|
|
|
|
|
::
|
2022-02-12 09:13:31 +03:00
|
|
|
|
=/ =task ((harden task) wrapped-task)
|
2022-01-26 08:28:45 +03:00
|
|
|
|
?+ -.task [~ khan-gate]
|
2022-01-22 01:09:01 +03:00
|
|
|
|
%born
|
2022-02-12 08:14:39 +03:00
|
|
|
|
[~ khan-gate(hey hen)]
|
2022-02-08 01:46:02 +03:00
|
|
|
|
::
|
|
|
|
|
%fard
|
2022-02-12 08:14:39 +03:00
|
|
|
|
=* fyd p.task
|
|
|
|
|
=/ =beak (get-beak bear.fyd now)
|
2022-01-26 08:28:45 +03:00
|
|
|
|
=/ wir=wire (head hen)
|
|
|
|
|
=/ rid=@ta (rear wir)
|
2022-02-12 08:14:39 +03:00
|
|
|
|
=/ tid=@ta (cat 3 'khan-fyrd--' rid)
|
|
|
|
|
=/ args [~ `tid beak name.fyd args.fyd]
|
2022-01-26 02:37:48 +03:00
|
|
|
|
=/ start-moves=(list move)
|
|
|
|
|
%+ turn
|
2022-01-26 08:28:45 +03:00
|
|
|
|
:~ (watch-spider our /thread-result/[tid])
|
2022-02-08 01:46:02 +03:00
|
|
|
|
(start-spider our !>(args))
|
2022-01-26 02:37:48 +03:00
|
|
|
|
==
|
|
|
|
|
|=(=note ^-(move [hen %pass //g note]))
|
2022-01-22 04:46:59 +03:00
|
|
|
|
[start-moves khan-gate]
|
2022-02-12 08:14:39 +03:00
|
|
|
|
::
|
|
|
|
|
%fyrd
|
|
|
|
|
=* fyd p.task
|
|
|
|
|
=/ =beak (get-beak bear.fyd now)
|
|
|
|
|
=/ =dais:clay (get-dais beak p.q.args.fyd rof)
|
|
|
|
|
=/ =vase
|
|
|
|
|
(slam !>(some) (vale.dais q.q.args.fyd))
|
|
|
|
|
=/ =wire (make-wire beak p.args.fyd)
|
|
|
|
|
:_ khan-gate
|
|
|
|
|
[hen %pass wire %k %fard bear.fyd name.fyd vase]~
|
2022-01-22 01:09:01 +03:00
|
|
|
|
==
|
2022-01-21 21:48:05 +03:00
|
|
|
|
:: +load: migrate an old state to a new khan version
|
|
|
|
|
::
|
|
|
|
|
++ load
|
2022-02-08 01:46:02 +03:00
|
|
|
|
|= $= old
|
2022-02-12 08:14:39 +03:00
|
|
|
|
$% [?(%0 %1) hey=duct *]
|
2022-02-08 01:46:02 +03:00
|
|
|
|
khan-state
|
|
|
|
|
==
|
2022-01-21 21:48:05 +03:00
|
|
|
|
^+ khan-gate
|
2022-02-08 01:46:02 +03:00
|
|
|
|
=/ new=khan-state
|
2022-02-12 08:14:39 +03:00
|
|
|
|
?: ?=(%2 -.old)
|
|
|
|
|
old
|
|
|
|
|
:- %2
|
|
|
|
|
hey.old
|
2022-02-08 01:46:02 +03:00
|
|
|
|
khan-gate(state new)
|
2022-01-26 08:28:45 +03:00
|
|
|
|
:: +scry: nothing to see as yet
|
2022-01-21 21:48:05 +03:00
|
|
|
|
::
|
|
|
|
|
++ scry
|
|
|
|
|
^- roon
|
|
|
|
|
|= [lyc=gang car=term bem=beam]
|
|
|
|
|
^- (unit (unit cage))
|
|
|
|
|
~
|
|
|
|
|
++ stay state
|
2022-01-26 08:28:45 +03:00
|
|
|
|
:: +take: handle responses.
|
|
|
|
|
::
|
2022-01-21 21:48:05 +03:00
|
|
|
|
++ take
|
|
|
|
|
|= [tea=wire hen=duct dud=(unit goof) hin=sign]
|
|
|
|
|
^- [(list move) _khan-gate]
|
|
|
|
|
?^ dud
|
|
|
|
|
~|(%khan-take-dud (mean tang.u.dud))
|
2022-02-12 08:14:39 +03:00
|
|
|
|
:_ khan-gate
|
|
|
|
|
?- -.hin
|
|
|
|
|
%gall
|
|
|
|
|
?+ -.p.hin ~
|
|
|
|
|
?(%poke-ack %watch-ack)
|
|
|
|
|
?~ p.p.hin ~
|
|
|
|
|
%- (slog 'khan-ack' u.p.p.hin)
|
2022-02-08 01:46:02 +03:00
|
|
|
|
[hen %give %arow %| -.p.hin u.p.p.hin]~
|
2022-01-26 04:43:48 +03:00
|
|
|
|
::
|
2022-02-12 08:14:39 +03:00
|
|
|
|
%fact
|
|
|
|
|
=* cag cage.p.hin
|
|
|
|
|
?+ p.cag ~&(bad-fact+p.cag !!)
|
|
|
|
|
%thread-fail
|
|
|
|
|
=/ =tang !<(tang q.cag)
|
|
|
|
|
%- (slog 'khan-fact' tang)
|
|
|
|
|
[hen %give %arow %| p.cag tang]~
|
|
|
|
|
::
|
|
|
|
|
%thread-done
|
2022-02-08 01:46:02 +03:00
|
|
|
|
[hen %give %arow %& q.cag]~
|
2022-02-12 08:14:39 +03:00
|
|
|
|
==
|
2022-01-26 04:43:48 +03:00
|
|
|
|
==
|
2022-02-12 08:14:39 +03:00
|
|
|
|
::
|
|
|
|
|
%khan
|
|
|
|
|
?. ?=(%arow +<.hin) ~
|
2022-02-12 09:13:31 +03:00
|
|
|
|
?~ tea ~
|
2022-02-12 08:14:39 +03:00
|
|
|
|
?. ?=(%fyrd -.tea) ~
|
|
|
|
|
=* row p.hin
|
|
|
|
|
?. ?=(%& -.row)
|
|
|
|
|
[hen %give %avow row]~
|
2022-02-12 09:13:31 +03:00
|
|
|
|
=/ [=beak =mark]
|
|
|
|
|
(read-wire tea)
|
2022-02-12 08:14:39 +03:00
|
|
|
|
=/ =dais:clay (get-dais beak mark rof)
|
2022-02-12 09:13:31 +03:00
|
|
|
|
=/ =vase (vale:dais q.p.row)
|
2022-02-12 08:14:39 +03:00
|
|
|
|
[hen %give %avow %& mark q.vase]~
|
2022-01-26 04:43:48 +03:00
|
|
|
|
==
|
2022-01-21 21:48:05 +03:00
|
|
|
|
--
|