Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wires in NockApps #124

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/choo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ runes:
- `/=` load from specified path (required `%hoon` mark)
- `/*` load from specified path via specified mark (presumptively `%hoon` or `%jock`)
- `/?` version pinning (ignored)

## Developer Troubleshooting

If you make changes to the `poke` arm in `bootstrap/kernel.hoon` or in `hoon-deps/wrapper.hoon`, you'll need to update the `choo.jam` file by running:

```bash
cargo run --release bootstrap/kernel.hoon ../hoon-deps
mv out.jam bootstrap/choo.jam
```

and committing the changes to `choo.jam` so that the CI can properly bootstrap the `choo` kernel.
Binary file modified apps/choo/bootstrap/choo.jam
Binary file not shown.
2 changes: 1 addition & 1 deletion apps/choo/bootstrap/kernel.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
:: +poke: external apply
::
++ poke
|= [eny=@ our=@ux now=@da dat=*]
|= [=wire eny=@ our=@ux now=@da dat=*]
^- [(list effect) choo-state]
=/ cause=(unit cause) ((soft cause) dat)
?~ cause
Expand Down
6 changes: 3 additions & 3 deletions apps/hoon-deps/lib/wrapper.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
|~ arg=path
*(unit (unit *))
++ poke
|~ arg=input
|~ arg=ovum
[*(list *) *inner-state]
--
--
Expand Down Expand Up @@ -77,7 +77,7 @@
=- [effects ..poke]
(slog tang.goof.u.g)
::
[[%poke ~] *]
[[%poke *] *]
=/ ovum ((soft ^ovum) ovum)
?~ ovum ~&("invalid arg: {<ovum>}" ~^..poke)
=/ o ((soft input) input.u.ovum)
Expand All @@ -86,7 +86,7 @@
=+ (road |.(;;(^^ovum ovum)))
~^..poke
=^ effects internal.outer
(poke:inner-fort input.u.ovum)
(poke:inner-fort u.ovum)
[effects ..poke(internal.outer internal.outer)]
==
--
Expand Down
2 changes: 1 addition & 1 deletion apps/http-app/bootstrap/kernel.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
:: +poke: external apply
::
++ poke
|= [eny=@ our=@ux now=@da dat=*]
|= [=wire eny=@ our=@ux now=@da dat=*]
^- [(list effect) server-state]
=/ sof-cau=(unit cause) ((soft cause) dat)
?~ sof-cau
Expand Down
4 changes: 3 additions & 1 deletion apps/test-app/bootstrap/kernel.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
::
++ load
|= arg=test-state
~& >> "load"
arg
::
:: +peek: external inspect
Expand All @@ -38,8 +39,9 @@
:: +poke: external apply
::
++ poke
|= [eny=@ our=@ux now=@da dat=*]
|= [=wire eny=@ our=@ux now=@da dat=*]
^- [(list effect) test-state]
~& >> "poke: {<wire>}"
=/ sof-cau=(unit cause) ((soft cause) dat)
?~ sof-cau
~& "cause incorrectly formatted!"
Expand Down
Binary file modified apps/test-app/bootstrap/test-ker.jam
Binary file not shown.
44 changes: 39 additions & 5 deletions crown/src/drivers/file.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
use crate::nockapp::driver::{make_driver, IODriverFn};
use crate::nockapp::wire::Wire;
use crate::noun::slab::NounSlab;
use crate::noun::FromAtom;
use crate::utils::make_tas;
use crate::AtomExt;
use sword::noun::{IndirectAtom, Noun, D, T};
use sword_macros::tas;
use tracing::error;

pub enum FileWire {
Read,
Write,
}

impl Wire for FileWire {
const VERSION: u64 = 1;
const SOURCE: &'static str = "file";

fn to_noun_slab(&self) -> NounSlab {
let mut slab = NounSlab::new();
let source = make_tas(&mut slab, FileWire::SOURCE).as_noun();
let wire = match self {
FileWire::Read => T(
&mut slab,
&[source, D(FileWire::VERSION), D(tas!(b"read")), D(0)],
),
FileWire::Write => T(
&mut slab,
&[source, D(FileWire::VERSION), D(tas!(b"write")), D(0)],
),
};
slab.set_root(wire);
slab
}
}

/// File IO Driver
///
/// ## Effects
Expand Down Expand Up @@ -69,14 +98,16 @@ pub fn file() -> IODriverFn {
&[D(tas!(b"file")), D(tas!(b"read")), D(0), contents_noun],
);
poke_slab.set_root(poke_noun);
handle.poke(poke_slab).await?;
let wire = FileWire::Read.to_noun_slab();
handle.poke(wire, poke_slab).await?;
}
Err(_) => {
let mut poke_slab = NounSlab::new();
let poke_noun =
T(&mut poke_slab, &[D(tas!(b"file")), D(tas!(b"read")), D(0)]);
poke_slab.set_root(poke_noun);
handle.poke(poke_slab).await?;
let wire = FileWire::Read.to_noun_slab();
handle.poke(wire, poke_slab).await?;
}
}
}
Expand Down Expand Up @@ -106,7 +137,8 @@ pub fn file() -> IODriverFn {
],
);
poke_slab.set_root(poke_noun);
handle.poke(poke_slab).await?;
let wire = FileWire::Write.to_noun_slab();
handle.poke(wire, poke_slab).await?;
continue;
}
}
Expand All @@ -125,7 +157,8 @@ pub fn file() -> IODriverFn {
],
);
poke_slab.set_root(poke_noun);
handle.poke(poke_slab).await?;
let wire = FileWire::Write.to_noun_slab();
handle.poke(wire, poke_slab).await?;
}
Err(e) => {
error!("file driver: error writing to path: {}", e);
Expand All @@ -141,7 +174,8 @@ pub fn file() -> IODriverFn {
],
);
poke_slab.set_root(poke_noun);
handle.poke(poke_slab).await?;
let wire = FileWire::Write.to_noun_slab();
handle.poke(wire, poke_slab).await?;
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion crown/src/drivers/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::nockapp::driver::{make_driver, IODriverFn, PokeResult};
use crate::nockapp::wire::Wire;
use crate::nockapp::NockAppError;
use crate::noun::slab::NounSlab;
use crate::utils::make_tas;
use crate::{AtomExt, Bytes};
use std::collections::HashMap;
use std::sync::atomic::{AtomicU64, Ordering};
Expand Down Expand Up @@ -33,6 +35,25 @@ struct ResponseBuilder {
body: Option<axum::body::Bytes>,
}

pub enum HttpWire {
Request,
}

impl Wire for HttpWire {
const VERSION: u64 = 1;
const SOURCE: &'static str = "http";

fn to_noun_slab(&self) -> NounSlab {
let mut slab = NounSlab::new();
let source = make_tas(&mut slab, HttpWire::SOURCE).as_noun();
let wire = match self {
HttpWire::Request => T(&mut slab, &[source, D(HttpWire::VERSION), D(tas!(b"req"))]),
};
slab.set_root(wire);
slab
}
}

static COUNTER: AtomicU64 = AtomicU64::new(0);
// wraps on overflow
fn get_id() -> u64 {
Expand Down Expand Up @@ -100,7 +121,8 @@ pub fn http() -> IODriverFn {
debug!("poking: {:?}", poke);
slab.set_root(poke);

let poke_result = handle.poke(slab).await?;
let wire = HttpWire::Request.to_noun_slab();
let poke_result = handle.poke(wire, slab).await?;
debug!("poke result: {:?}", poke_result);

if let PokeResult::Nack = poke_result {
Expand Down
Loading
Loading