diff --git a/rust/ares/src/jets.rs b/rust/ares/src/jets.rs index 34aa37d..fd5e3db 100644 --- a/rust/ares/src/jets.rs +++ b/rust/ares/src/jets.rs @@ -7,6 +7,7 @@ pub mod form; pub mod hash; pub mod math; pub mod nock; +pub mod serial; pub mod sort; pub mod text; pub mod tree; @@ -19,6 +20,7 @@ use crate::jets::hash::*; use crate::jets::hot::Hot; use crate::jets::math::*; use crate::jets::nock::*; +use crate::jets::serial::*; use crate::jets::sort::*; use crate::jets::text::*; use crate::jets::tree::*; @@ -106,6 +108,9 @@ pub fn get_jet(jet_name: Noun) -> Option { tas!(b"gor") => Some(jet_gor), tas!(b"mor") => Some(jet_mor), // + tas!(b"cue") => Some(jet_cue), + tas!(b"jam") => Some(jet_jam), + // tas!(b"scow") => Some(jet_scow), // tas!(b"mink") => Some(jet_mink), diff --git a/rust/ares/src/jets/serial.rs b/rust/ares/src/jets/serial.rs new file mode 100644 index 0000000..db6dec1 --- /dev/null +++ b/rust/ares/src/jets/serial.rs @@ -0,0 +1,46 @@ +use crate::interpreter::Context; +use crate::jets::util::*; +use crate::jets::Result; +use crate::noun::Noun; +use crate::serialization::{cue, jam}; + +crate::gdb!(); + +pub fn jet_cue(context: &mut Context, subject: Noun) -> Result { + Ok(cue(&mut context.stack, slot(subject, 6)?.as_atom()?)) +} + +pub fn jet_jam(context: &mut Context, subject: Noun) -> Result { + Ok(jam(&mut context.stack, slot(subject, 6)?).as_noun()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::jets::util::test::*; + use crate::noun::{D, T}; + + #[test] + fn test_jam() { + let c = &mut init_context(); + + assert_jet(c, jet_jam, D(0x0), D(0x2)); + assert_jet(c, jet_jam, D(0x1), D(0xc)); + let sam = T(&mut c.stack, &[D(0x0), D(0x0)]); + assert_jet(c, jet_jam, sam, D(0x29)); + let sam = T(&mut c.stack, &[D(0x1), D(0x2), D(0x3), D(0x0)]); + assert_jet(c, jet_jam, sam, D(0x2d0c871)); + } + + #[test] + fn test_cue() { + let c = &mut init_context(); + + assert_jet(c, jet_cue, D(0x2), D(0x0)); + assert_jet(c, jet_cue, D(0xc), D(0x1)); + let res = T(&mut c.stack, &[D(0x0), D(0x0)]); + assert_jet(c, jet_cue, D(0x29), res); + let res = T(&mut c.stack, &[D(0x1), D(0x2), D(0x3), D(0x0)]); + assert_jet(c, jet_cue, D(0x2d0c871), res); + } +}