shrub/pkg/arvo/gen/metal.hoon

324 lines
9.9 KiB
Plaintext
Raw Normal View History

:: Produce a metal pill
2016-11-20 06:53:20 +03:00
::
:::: /hoon/metal/gen
::
/? 310
::
::::
!:
:- %say
2016-11-29 22:48:10 +03:00
|= $: {now/@da * bec/beak}
2018-03-19 07:18:20 +03:00
{{who/@p ~} try/_| ~}
2016-11-20 06:53:20 +03:00
==
2016-11-28 03:33:23 +03:00
::
:: we're creating an event series E whose lifecycle can be computed
2016-11-29 22:48:10 +03:00
:: with the urbit lifecycle formula L, `[2 [0 3] [0 2]]`. that is:
2016-11-28 03:33:23 +03:00
:: if E is the list of events processed by a computer in its life,
:: its final state is S, where S is nock(E L).
::
2016-11-29 22:48:10 +03:00
:: in practice, the first five nouns in E are: two boot formulas,
2016-11-28 03:33:23 +03:00
:: a hoon compiler as a nock formula, the same compiler as source,
:: and the arvo kernel as source.
2016-11-29 22:48:10 +03:00
::
:: after the first five special events, we enter an iterative
:: sequence of regular events which continues for the rest of the
:: computer's life. during this sequence, each state is a function
:: that, passed the next event, produces the next state.
2016-11-29 22:48:10 +03:00
::
:: each event is a `[date wire type data]` tuple, where `date` is a
:: 128-bit Urbit date; `wire` is an opaque path which output can
:: match to track causality; `type` is a symbol describing the type
:: of input; and `data` is input data specific to `type`.
::
:: in real life we don't actually run the lifecycle loop,
:: since real life is updated incrementally and also cares
:: about things like output. we couple to the internal
:: structure of the state machine and work directly with
:: the underlying arvo engine.
2016-11-28 03:33:23 +03:00
::
2016-11-29 22:48:10 +03:00
:: this arvo core, which is at `+7` (Lisp `cddr`) of the state
:: function (see its public interface in `sys/arvo`), gives us
:: extra features, like output, which are relevant to running
:: a real-life urbit vm, but don't affect the formal definition.
::
:: so a real-life urbit interpreter is coupled to the shape of
:: the arvo core. it becomes very hard to change this shape.
:: fortunately, it is not a very complex interface.
::
:- %noun
::
:: boot-one: lifecycle formula
::
=+ ^= boot-one
2016-11-20 06:53:20 +03:00
::
2016-11-29 22:48:10 +03:00
:: event 1 is the lifecycle formula which computes the final
2016-11-20 06:53:20 +03:00
:: state from the full event sequence.
::
:: the formal urbit state is always just a gate (function)
:: which, passed the next event, produces the next state.
::
=> [boot-formula=* full-sequence=*]
!= ::
:: first we use the boot formula (event 1) to set up
:: the pair of state function and main sequence. the boot
:: formula peels off the first n (currently 3) events
:: to set up the lifecycle loop.
::
2016-11-23 04:12:24 +03:00
=+ [state-gate main-sequence]=.*(full-sequence boot-formula)
2016-11-20 06:53:20 +03:00
::
:: in this lifecycle loop, we replace the state function
:: with its product, called on the next event, until
:: we run out of events.
::
2016-11-28 03:33:23 +03:00
|- ?@ main-sequence
2016-11-20 06:53:20 +03:00
state-gate
%= $
main-sequence +.main-sequence
state-gate .*(state-gate [%9 2 %10 [6 %1 -.main-sequence] %0 1])
2016-11-20 06:53:20 +03:00
==
2016-11-29 22:48:10 +03:00
::
:: boot-two: startup formula
::
=+ ^= boot-two
2016-11-20 06:53:20 +03:00
::
2016-11-29 22:48:10 +03:00
:: event 2 is the startup formula, which verifies the compiler
2016-11-20 06:53:20 +03:00
:: and starts the main lifecycle.
::
2016-11-29 22:48:10 +03:00
=> :* :: event 3: a formula producing the hoon compiler
2016-11-20 06:53:20 +03:00
::
2016-11-24 07:25:07 +03:00
compiler-formula=**
2016-11-20 06:53:20 +03:00
::
2016-11-29 22:48:10 +03:00
:: event 4: hoon compiler source, compiling to event 2
2016-11-20 06:53:20 +03:00
::
2016-11-24 07:25:07 +03:00
compiler-source=*@t
2016-11-20 06:53:20 +03:00
::
2016-11-29 22:48:10 +03:00
:: event 5: arvo kernel source
2016-11-20 06:53:20 +03:00
::
2016-11-25 22:32:48 +03:00
arvo-source=*@t
2016-11-20 06:53:20 +03:00
::
2016-11-29 22:48:10 +03:00
:: events 6..n: main sequence with normal semantics
2016-11-20 06:53:20 +03:00
::
2016-11-23 04:12:24 +03:00
main-sequence=**
2016-11-20 06:53:20 +03:00
==
!= :_ main-sequence
::
2016-11-24 07:25:07 +03:00
:: activate the compiler gate. the product of this formula
:: is smaller than the formula. so you might think we should
:: save the gate itself rather than the formula producing it.
:: but we have to run the formula at runtime, to register jets.
2016-11-20 06:53:20 +03:00
::
:: as always, we have to use raw nock as we have no type.
:: the gate is in fact ++ride.
::
2016-12-02 22:54:41 +03:00
~> %slog.[0 leaf+"1-b"]
=+ ^= compiler-gate
2016-11-25 22:32:48 +03:00
.*(0 compiler-formula)
2016-11-20 06:53:20 +03:00
::
:: compile the compiler source, producing (pair span nock).
:: the compiler ignores its input so we use a trivial span.
::
2016-12-02 22:54:41 +03:00
~> %slog.[0 leaf+"1-c"]
2016-11-20 06:53:20 +03:00
=+ ^= compiler-tool
.*(compiler-gate [%9 2 %10 [6 %1 [%noun compiler-source]] %0 1])
2016-11-20 06:53:20 +03:00
::
:: switch to the second-generation compiler. we want to be
:: able to generate matching reflection nouns even if the
:: language changes -- the first-generation formula will
:: generate last-generation spans for `!>`, etc.
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
~> %slog.[0 leaf+"1-d"]
=. compiler-gate .*(0 +:compiler-tool)
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
:: get the span (type) of the kernel core, which is the context
2016-11-24 07:25:07 +03:00
:: of the compiler gate. we just compiled the compiler,
:: so we know the span (type) of the compiler gate. its
:: context is at tree address `+>` (ie, `+7` or Lisp `cddr`).
:: we use the compiler again to infer this trivial program.
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
~> %slog.[0 leaf+"1-e"]
2016-11-25 22:32:48 +03:00
=+ ^= kernel-span
-:.*(compiler-gate [%9 2 %10 [6 %1 [-.compiler-tool '+>']] %0 1])
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
:: compile the arvo source against the kernel core.
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
~> %slog.[0 leaf+"1-f"]
2016-11-20 06:53:20 +03:00
=+ ^= kernel-tool
.*(compiler-gate [%9 2 %10 [6 %1 [kernel-span arvo-source]] %0 1])
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
:: create the arvo kernel, whose subject is the kernel core.
2016-11-20 06:53:20 +03:00
::
2016-12-02 22:54:41 +03:00
~> %slog.[0 leaf+"1-g"]
2016-11-20 06:53:20 +03:00
.*(+>:compiler-gate +:kernel-tool)
::
2016-11-29 22:48:10 +03:00
:: sys: root path to boot system, `/~me/[desk]/now/sys`
2016-11-24 07:25:07 +03:00
::
=+ sys=`path`/(scot %p p.bec)/[q.bec]/(scot %da now)/sys
2016-11-29 22:48:10 +03:00
::
:: compiler-source: hoon source file producing compiler, `sys/hoon`
::
2016-11-24 07:25:07 +03:00
=+ compiler-source=.^(@t %cx (welp sys /hoon/hoon))
2016-11-29 22:48:10 +03:00
::
:: compiler-twig: compiler as hoon expression
::
2016-11-24 07:25:07 +03:00
~& %metal-parsing
=+ compiler-twig=(ream compiler-source)
~& %metal-parsed
2016-11-29 22:48:10 +03:00
::
:: compiler-formula: compiler as nock formula
2016-11-29 22:48:10 +03:00
::
~& %metal-compiling
2016-11-25 22:32:48 +03:00
=+ compiler-formula=q:(~(mint ut %noun) %noun compiler-twig)
2016-11-24 07:25:07 +03:00
~& %metal-compiled
2016-11-29 22:48:10 +03:00
::
:: arvo-source: hoon source file producing arvo kernel, `sys/arvo`
::
2016-11-25 22:32:48 +03:00
=+ arvo-source=.^(@t %cx (welp sys /arvo/hoon))
2016-11-29 22:48:10 +03:00
::
:: main-moves: installation actions
::
=+ ^= main-moves
2016-11-24 07:25:07 +03:00
|^ ^- (list ovum)
2016-11-29 22:48:10 +03:00
:~ ::
:: configure identity
::
2016-11-24 07:25:07 +03:00
[[%name (scot %p who) ~] [%veal who]]
2016-11-29 22:48:10 +03:00
::
:: sys/zuse: standard library
::
(vent %$ /zuse)
::
:: sys/vane/ames: network
::
2016-11-24 07:25:07 +03:00
(vent %a /vane/ames)
2016-11-29 22:48:10 +03:00
::
:: sys/vane/behn: timer
::
2016-11-24 07:25:07 +03:00
(vent %b /vane/behn)
2016-11-29 22:48:10 +03:00
::
:: sys/vane/clay: revision control
::
(vent %c /vane/clay)
::
:: sys/vane/dill: console
::
2016-11-24 07:25:07 +03:00
(vent %d /vane/dill)
2016-11-29 22:48:10 +03:00
::
:: sys/vane/eyre: web
::
2016-11-24 07:25:07 +03:00
(vent %e /vane/eyre)
2016-11-29 22:48:10 +03:00
::
:: sys/vane/ford: build
::
(vent %f /vane/ford)
::
:: sys/vane/gall: applications
::
(vent %g /vane/gall)
::
:: sys/vane/jael: security
::
2016-11-24 07:25:07 +03:00
(vent %j /vane/jael)
::
:: legacy boot event
::
[[%$ %term '1' ~] [%boot %sith who `@uw`who &]]
::
:: userspace:
::
:: /app %gall applications
:: /gen :dojo generators
:: /lib %ford libraries
:: /mar %ford marks
:: /sur %ford structures
:: /ren %ford renderers
:: /web %eyre web content
:: /sys system files
::
(user /app /gen /lib /mar /ren /sec /sur /sys /web ~)
2016-11-24 07:25:07 +03:00
==
:: ::
++ user :: userspace loading
|= :: sal: all spurs to load from
::
sal/(list spur)
^- ovum
::
:: hav: all user files
::
=; hav ~& user-files+(lent hav)
[[%$ %sync ~] [%into %$ & hav]]
=| hav/mode:clay
|- ^+ hav
?~ sal ~
=. hav $(sal t.sal)
::
:: tyl: spur
::
=/ tyl i.sal
|- ^+ hav
::
:: pax: full path at `tyl`
:: lon: directory at `tyl`
::
=/ pax (en-beam:format bec tyl)
=/ lon .^(arch %cy pax)
=? hav ?=(^ fil.lon)
?. ?=({$hoon *} tyl)
::
:: install only hoon files for now
::
hav
::
:: cot: file as plain-text octet-stream
::
=; cot [[(flop `path`tyl) `[/text/plain cot]] hav]
^- octs
?- tyl
{$hoon *}
=/ dat .^(@t %cx pax)
[(met 3 dat) dat]
==
2017-11-10 03:52:38 +03:00
=/ all ~(tap by dir.lon)
|- ^- mode:clay
?~ all hav
$(all t.all, hav ^$(tyl [p.i.all tyl]))
2016-11-24 07:25:07 +03:00
::
++ vent
|= {abr/term den/path}
=+ pax=(weld sys den)
=+ txt=.^(@ %cx (welp pax /hoon))
`ovum`[[%vane den] [%veer abr pax txt]]
--
2016-11-28 03:33:23 +03:00
::
2016-11-29 22:48:10 +03:00
:: main-events: full events with advancing times
::
=. now ~2017.3.1
2016-11-29 22:48:10 +03:00
=+ ^= main-events
|- ^- (list (pair @da ovum))
?~ main-moves ~
:- [now i.main-moves]
$(main-moves t.main-moves, now (add now (bex 48)))
2016-12-02 22:54:41 +03:00
::
~? try
~& %metal-testing
=+ ^= yop
^- @p
%- mug
.* :* boot-one
boot-two
compiler-formula
compiler-source
arvo-source
main-events
==
[2 [0 3] [0 2]]
[%metal-tested yop]
2016-11-28 03:33:23 +03:00
::
2016-11-29 22:48:10 +03:00
:* boot-one
boot-two
2016-11-28 03:33:23 +03:00
compiler-formula
compiler-source
arvo-source
2016-11-29 22:48:10 +03:00
main-events
2016-11-28 03:33:23 +03:00
==