From f2f63a93443fbc6c9a82c7706dc3964a3f5f8394 Mon Sep 17 00:00:00 2001 From: Edward Amsden Date: Wed, 21 Aug 2024 11:54:33 -0500 Subject: [PATCH] add jet for +trip (#11) --- rust/ares/src/jets/hot.rs | 13 +++++++++++++ rust/ares/src/jets/parse.rs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/rust/ares/src/jets/hot.rs b/rust/ares/src/jets/hot.rs index 71ba179..dacb843 100644 --- a/rust/ares/src/jets/hot.rs +++ b/rust/ares/src/jets/hot.rs @@ -276,6 +276,19 @@ pub const URBIT_HOT_STATE: &[HotEntry] = &[ jet_sha1, ), // + ( + &[ + K_139, + Left(b"one"), + Left(b"two"), + Left(b"tri"), + Left(b"qua"), + Left(b"trip"), + ], + 1, + jet_trip, + ), + // ( &[ K_139, diff --git a/rust/ares/src/jets/parse.rs b/rust/ares/src/jets/parse.rs index 01b452e..9538574 100644 --- a/rust/ares/src/jets/parse.rs +++ b/rust/ares/src/jets/parse.rs @@ -1,14 +1,45 @@ /** Parsing jets */ use crate::interpreter::Context; +use crate::jets::bits::util::met; use crate::jets::math::util::{gte_b, lte_b, lth_b}; use crate::jets::util::{kick, slam, slot, BAIL_FAIL}; use crate::jets::Result; -use crate::noun::{Noun, D, T}; +use crate::noun::{Cell, Noun, D, T}; use either::{Left, Right}; crate::gdb!(); +// +// Text conversion +// +pub fn jet_trip(context: &mut Context, subject: Noun) -> Result { + let sam = slot(subject, 6)?.as_atom()?; + let chars = met(3, sam); + if chars == 0 { + return Ok(D(0)); + }; + + let bytes = &sam.as_bytes()[0..chars]; + + let mut result = D(0); + let mut dest = &mut result as *mut Noun; + + for byte in bytes { + unsafe { + let (it, it_mem) = Cell::new_raw_mut(&mut context.stack); + + // safe because a byte can't overflow a direct atom + (*it_mem).head = D((*byte) as u64); + + *dest = it.as_noun(); + dest = &mut (*it_mem).tail as *mut Noun; + } + } + unsafe { *dest = D(0) }; + Ok(result) +} + // // Tracing //