Merge pull request #116 from urbit/sigilante/cuejam

Post jam/cue jets.
This commit is contained in:
Edward Amsden 2023-11-07 09:36:00 -06:00 committed by GitHub
commit 7e42b2b950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -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<Jet> {
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),

View File

@ -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);
}
}