Skip to content

Commit

Permalink
choo: use wrapper for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
tacryt-socryp committed Aug 27, 2024
1 parent 4f0905d commit f474ac1
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 105 deletions.
Binary file modified choo/bootstrap/choo.jam
Binary file not shown.
11 changes: 8 additions & 3 deletions choo/hoon/lib/builder.hoon
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* hoon-139-hoon %hoon /lib/hoon-139/hoon
/* wrapper-hoon %hoon /lib/wrapper/hoon
/* kernel-hoon %hoon /lib/kernel/hoon
!.
::
::
:: Bootstrap builder: to build the bootstrap formula for Choo using
:: Urbit Ford
::
Expand All @@ -15,8 +16,12 @@
=/ hoon-knob=[t=type form=nock]
~> %bout
(~(mint ut %noun) %noun (ream hoon-139-hoon))
~& "compiling wrapper"
=/ wrapper-knob=[t=type form=nock]
~> %bout
(~(mint ut t.hoon-knob) %noun (ream wrapper-hoon))
~& "compiling kernel"
=/ kernel-knob=[t=type form=nock]
~> %bout
(~(mint ut t.hoon-knob) %noun (rain /lib/choo/kernel/hoon kernel-hoon))
[%7 form.hoon-knob form.kernel-knob]
(~(mint ut t.wrapper-knob) %noun (rain /lib/choo/kernel/hoon kernel-hoon))
[%7 [%7 form.hoon-knob form.wrapper-knob] form.kernel-knob]
158 changes: 56 additions & 102 deletions choo/hoon/lib/kernel.hoon
Original file line number Diff line number Diff line change
@@ -1,126 +1,80 @@
::/+ *wrapper
::
:: arvo-shaped outer core
::
!:
=<
~& "choo choo"
|_ k=kernel-state
+* this .
=>
|%
+$ choo-state %stateless
++ moat (keep choo-state)
::
:: nock compiled from hoon, along with type. form is independent of
:: subject, usually expected to be 0
+$ knob [t=type f=nock]
+$ cause [%compile sub=knob pax=path fil=cord nob=?]
+$ effect [%jam p=*]
--
::
~& %choo-choo
%- moat
^- fort:moat
|_ k=choo-state
::
:: +load: upgrade from previous state
::
++ load
^- ^
|= arg=*
^- [(list *) *]
!!
:: TODO work in ares
:: ++ load :: 4
:: |= hir=kernel-state
:: ^- _this
:: ~& >>> hir+hir
:: =; t ~& >> k.t t
:: =. epoch.hir +(epoch.k)
:: =. chain.k chain.hir
:: this(k hir)
::
:: +peek: external inspect
::
++ peek :: 22
|= arg=*
|= path=*
^- (unit (unit *))
(do-peek k arg)
!!
::
:: +poke: external apply
::
++ poke :: 23
|= arg=*
^- ^
:: ~& "poked with arg {<arg>}"
=^ effects k (do-poke k arg)
[effects this(k k)]
|= [event-num=@ud eny=@ our=@ux now=@da dat=*]
^- [(list *) choo-state]
=/ sof-cau=(unit cause) ((soft cause) dat)
?~ sof-cau
~& "cause incorrectly formatted!"
!!
=/ =cause u.sof-cau
|^
=; p=*
~& nob+nob.cause
[[%jam p]~ k]
?: nob.cause
(compile-knob [sub pax fil]:cause)
(compile-nock [sub pax fil]:cause)
::
++ compile-knob
|= [sub=knob pax=path fil=cord]
~& %compile-knob
^- knob
=/ ast
~& %parsing (rain pax fil)
=/ [t=type form=nock]
~& %compiling (~(mint ut t.sub) %noun ast)
[t %7 f.sub form]
::
++ compile-nock
|= [sub=knob pax=path fil=cord]
~& %compile-knob
^- nock
=/ ast
~& %parsing (rain pax fil)
=/ [t=type form=nock]
~& %compiling (~(mint ut t.sub) %noun ast)
[%7 f.sub form]
--
::
:: +wish: external compute
::
++ wish :: 10
|= txt=@
!!
--
::
:: inner core that does the actual work
|%
+$ kernel-state %stateless
::
:: nock compiled from hoon, along with type. form is independent of
:: subject, usually expected to be 0
+$ knob [t=type f=nock]
+$ cause [%compile sub=knob pax=path fil=cord nob=?]
+$ effect [%jam p=*]
+$ goof [mote=term =tang]
+$ ovum $%([[%poke ~] =pok] [%crud =goof %poke =pok])
+$ pok [eny=@ our=@ux now=@da =cause]
+$ crud [=goof =pok]
++ do-poke
|= [k=kernel-state arg=*]
^- [(list effect) kernel-state]
|^
?@ arg ~&("bad poke type: {<arg>}" !!)
?+ +.arg ~&("invalid arg: {<arg>}" !!)
[[%$ %arvo ~] %crud gof=* cru=*]
=/ g ((soft goof) gof.arg)
?~ g ~&(%invalid-goof !!)
(handle-crud u.g cru.arg)
::
[[%poke ~] pok=*]
=/ o ((soft ovum) +.arg)
?~ o
~& "could not mold poke type: {<+.arg>}"
=+ (road |.(;;(ovum +.arg)))
~^k
?. ?=([%poke ~] -.u.o)
~& %bad-poke-header !!
(handle-poke *@da pok.u.o)
==
::
++ handle-crud
|= [=goof cru=*]
^- [(list effect) kernel-state]
~& "%crud: event failed"
=- [~ k]
%+ turn tang.goof
|=(g=tank ~>(%slog.[3 g] 0))
::
++ handle-poke
|= [event-num=@da eny=@ our=@ux now=@da =cause]
^- [(list effect) kernel-state]
:: ~& "poked at {<now>}"
=; p=*
~& nob+nob.cause
[[%jam p]~ k]
?: nob.cause
(compile-knob [sub pax fil]:cause)
(compile-nock [sub pax fil]:cause)
--
++ compile-knob
|= [sub=knob pax=path fil=cord]
~& %compile-knob
^- knob
=/ ast
~& %parsing (rain pax fil)
=/ [t=type form=nock]
~& %compiling (~(mint ut t.sub) %noun ast)
[t %7 f.sub form]
++ compile-nock
|= [sub=knob pax=path fil=cord]
~& %compile-knob
^- nock
=/ ast
~& %parsing (rain pax fil)
=/ [t=type form=nock]
~& %compiling (~(mint ut t.sub) %noun ast)
[%7 f.sub form]
::
++ do-peek
|= [k=kernel-state arg=*]
^- (unit (unit *))
=/ path ((soft path) arg)
~&(invalid-peek+path !!)
--
95 changes: 95 additions & 0 deletions choo/hoon/lib/wrapper.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
|%
+$ goof [mote=term =tang]
+$ ovum
$% [[%poke ~] =input]
[%crud =goof %poke =input]
==
+$ crud [=goof =input]
+$ input [event-num=@ud eny=@ our=@ux now=@da cause=*]
::
++ keep
|* inner=mold
=>
|%
+$ inner-state inner
+$ outer-state [desk-hash=(unit @uvI) internal=inner]
+$ outer-fort
$_ ^|
|_ outer-state
++ load
|~ arg=*
*[(list *) *]
++ peek
|~ arg=path
*(unit (unit *))
++ poke
|~ arg=input
*[(list *) outer-state]
++ wish
|~ txt=@
**
--
::
+$ fort
$_ ^|
|_ inner-state
++ load
|~ arg=*
*[(list *) *]
++ peek
|~ arg=path
*(unit (unit *))
++ poke
|~ arg=input
*[(list *) inner-state]
++ wish
|~ txt=@
**
--
--
::
|= inner=fort
|= hash=@uvI
=< .(desk-hash.outer `hash)
|_ outer=outer-state
++ load
|= arg=*
^- [(list *) *]
(load:inner arg)
::
++ peek
|= arg=path
^- (unit (unit *))
(peek:inner arg)
::
++ wish
|= arg=@
^- *
(wish:inner arg)
::
++ poke
|= =input
^- [(list *) outer-state]
?@ input ~&("bad poke type: {<input>}" !!)
?+ +.input ~&("invalid arg: {<input>}" !!)
[[%$ %arvo ~] %crud gof=* cru=*]
=/ g ((soft goof) gof.arg)
?~ g ~&(%invalid-goof !!)
=- [~ outer]
%+ turn tang.u.g
|=(=tank ~>(%slog.[3 tank] 0))
::
[[%poke ~] pok=*]
=/ o ((soft ovum) +.input)
?~ o
~& "could not mold poke type: {<+.input>}"
=+ (road |.(;;(ovum +.input)))
~^outer
~& "going to poke inner"
?> ?=([%poke ~] -.u.o)
=^ effects internal.outer
(poke:inner input)
[effects outer]
==
--
--

0 comments on commit f474ac1

Please sign in to comment.