urbit/gen/metal.hoon

192 lines
6.4 KiB
Plaintext
Raw Normal View History

2016-11-20 06:53:20 +03:00
::
:::: /hoon/metal/gen
::
/? 310
::
::::
!:
:- %say
2016-11-24 07:25:07 +03:00
|= $: {now/@da eny/@uvJ bec/beak}
{{who/@p $~} $~}
2016-11-20 06:53:20 +03:00
==
:- %noun
2016-11-28 03:33:23 +03:00
::
:: we're creating an event series E whose lifecycle can be computed
:: with the standard lifecycle formula L, [2 [0 3] [0 2]]. that is:
:: 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).
::
:: in practice, the first five nouns in E are: two boot loaders,
:: a hoon compiler as a nock formula, the same compiler as source,
:: and the arvo kernel as source. after the first five events,
:: we enter an iterative form in which the state is a function
:: that, passed the next event, produces the next state.
::
2016-11-20 06:53:20 +03:00
=+ ^= event-zero
::
:: event 0 is the lifecycle formula which computes the final
:: 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.
::
:: in real life we don't actually run the lifecycle loop,
2016-11-24 07:25:07 +03:00
:: 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-20 06:53:20 +03:00
::
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(+< -.main-sequence) -.state-gate)
==
=+ ^= event-one
::
:: event 1 is the boot formula, which verifies the compiler
:: and starts the main lifecycle.
::
2016-11-24 07:25:07 +03:00
=> :* :: event 2: 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
::
:: event 3: hoon compiler source, compiling to event 2
::
2016-11-24 07:25:07 +03:00
compiler-source=*@t
2016-11-20 06:53:20 +03:00
::
:: event 4: arvo kernel source
::
2016-11-25 22:32:48 +03:00
arvo-source=*@t
2016-11-20 06:53:20 +03:00
::
:: events 5..n: main sequence with normal semantics
::
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-11-28 03:33:23 +03:00
~> %slog.[0 leaf+"1-b"]
2016-11-24 07:25:07 +03:00
=+ ^= 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-11-28 03:33:23 +03:00
~> %slog.[0 leaf+"1-c"]
2016-11-20 06:53:20 +03:00
=+ ^= compiler-tool
.*(compiler-gate(+< [%noun compiler-source]) -.compiler-gate)
::
2016-11-24 07:25:07 +03:00
:: check that the new compiler formula equals the old formula.
2016-11-28 03:33:23 +03:00
:: this is not proof against thompson attacks but it doesn't hurt.
2016-11-20 06:53:20 +03:00
::
2016-11-28 03:33:23 +03:00
~> %slog.[0 leaf+"1-d"]
2016-11-25 22:32:48 +03:00
?> =(compiler-formula +:compiler-tool)
2016-11-20 06:53:20 +03:00
::
2016-11-25 22:32:48 +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-11-28 03:33:23 +03:00
~> %slog.[0 leaf+"1-e"]
2016-11-25 22:32:48 +03:00
=+ ^= kernel-span
2016-11-24 07:25:07 +03:00
-:.*(compiler-gate(+< [-.compiler-tool '+>']) -.compiler-gate)
2016-11-20 06:53:20 +03:00
::
2016-11-25 22:32:48 +03:00
:: compile the arvo source against the kernel core.
2016-11-20 06:53:20 +03:00
::
2016-11-28 03:33:23 +03:00
~> %slog.[0 leaf+"1-f"]
2016-11-20 06:53:20 +03:00
=+ ^= kernel-tool
2016-11-25 22:32:48 +03:00
.*(compiler-gate(+< [kernel-span arvo-source]) -.compiler-gate)
2016-11-20 06:53:20 +03:00
::
2016-11-28 03:33:23 +03:00
:: create the arvo kernel, whose subject is the kernel core.
2016-11-20 06:53:20 +03:00
::
2016-11-28 03:33:23 +03:00
~> %slog.[0 leaf+"1-g"]
2016-11-20 06:53:20 +03:00
.*(+>:compiler-gate +:kernel-tool)
2016-11-24 07:25:07 +03:00
::
:: load files. ship and desk are in generator beak. case is now.
:: source files:
::
:: sys/hoon compiler
:: sys/arvo kernel
:: sys/zuse standard library
:: sys/vane/ames network vane
:: sys/vane/behn timer vane
:: sys/vane/clay revision-control vane
:: sys/vane/dill console vane
:: sys/vane/eyre web/internet vane
:: sys/vane/ford build vane
:: sys/vane/gall app vane
:: sys/vane/jael security vane
::
=+ sys=`path`/(scot %p p.bec)/[q.bec]/(scot %da now)/sys
=+ compiler-source=.^(@t %cx (welp sys /hoon/hoon))
~& %metal-parsing
=+ compiler-twig=(ream compiler-source)
~& %metal-parsed
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-25 22:32:48 +03:00
=+ arvo-source=.^(@t %cx (welp sys /arvo/hoon))
2016-11-24 07:25:07 +03:00
=+ ^= vane-sequence
|^ ^- (list ovum)
:~ (vent %$ /zuse)
[[%name (scot %p who) ~] [%veal who]]
(vent %c /vane/clay)
(vent %g /vane/gall)
(vent %f /vane/ford)
(vent %a /vane/ames)
(vent %b /vane/behn)
(vent %d /vane/dill)
(vent %e /vane/eyre)
(vent %j /vane/jael)
==
::
++ 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
::
:: ~& %metal-testing
:: =+ ^= yop
:: ^- @p
:: %- mug
:: .* :* event-zero
:: event-one
:: compiler-formula
:: compiler-source
:: arvo-source
:: vane-sequence
:: ==
:: [2 [0 3] [0 2]]
:: ~& [%metal-tested yop]
::
:* event-zero
event-one
compiler-formula
compiler-source
arvo-source
vane-sequence
==