From 68d6e5bd09de7726ce39d19f0f162a23ef6fee12 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Fri, 14 Jun 2024 16:54:24 -0400 Subject: [PATCH] jets: `+rep:by` --- rust/ares/src/jets.rs | 2 ++ rust/ares/src/jets/hot.rs | 5 +++++ rust/ares/src/jets/maps.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 rust/ares/src/jets/maps.rs diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index f9ebe3c..273f1d0 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -8,6 +8,7 @@ pub mod hash; pub mod list; pub mod lock; pub mod lute; +pub mod maps; pub mod math; pub mod nock; pub mod parse; @@ -27,6 +28,7 @@ use crate::jets::lock::aes::*; use crate::jets::lock::ed::*; use crate::jets::lock::sha::*; use crate::jets::lute::*; +use crate::jets::maps::*; use crate::jets::math::*; use crate::jets::nock::*; use crate::jets::parse::*; diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 54c511b..5614579 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -224,6 +224,11 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ 1, jet_jam, ), + ( + &[K_139, Left(b"one"), Left(b"two"), Left(b"by"), Left(b"rep")], + 1, + jet_by_rep, + ), // ( &[ diff --git a/rust/ares/src/jets/maps.rs b/rust/ares/src/jets/maps.rs new file mode 100644 index 0000000..b0fbc30 --- /dev/null +++ b/rust/ares/src/jets/maps.rs @@ -0,0 +1,34 @@ +/** Map jets. */ +use crate::interpreter::Context; +use crate::jets::util::slot; +use crate::jets::Result; +use crate::noun::{Noun, D, T}; +use crate::site::{site_slam, Site}; + +crate::gdb!(); + +fn by_rep(context: &mut Context, tree: Noun, site: &Site, out: &mut Noun) { + if unsafe { tree.raw_equals(D(0)) } { + return; + } else { + let node = slot(tree, 2).unwrap(); + let left = slot(node, 6).unwrap(); + let rite = slot(node, 7).unwrap(); + + let acc = T(&mut context.stack, &[node, *out]); + *out = site_slam(context, site, acc); + + by_rep(context, left, site, out); + by_rep(context, rite, site, out); + } +} + +pub fn jet_by_rep(context: &mut Context, subject: Noun) -> Result { + let tree = slot(subject, 30)?; + let mut gate = slot(subject, 6)?; + let mut pro = slot(gate, 13)?; + + let site = Site::new(context, &mut gate); + by_rep(context, tree, &site, &mut pro); + Ok(pro) +} \ No newline at end of file