[jets] add dis jet

This commit is contained in:
Philip Monk 2023-02-14 20:43:25 -07:00
parent f5d0bea6ac
commit 9825db95ff
2 changed files with 34 additions and 0 deletions

View File

@ -43,6 +43,7 @@ pub fn get_jet(jet_name: Noun) -> Result<Jet, ()> {
tas!(b"lsh") => Ok(jet_lsh),
tas!(b"rsh") => Ok(jet_rsh),
tas!(b"con") => Ok(jet_con),
tas!(b"dis") => Ok(jet_dis),
tas!(b"cut") => Ok(jet_cut),
tas!(b"met") => Ok(jet_met),
tas!(b"mug") => Ok(jet_mug),

View File

@ -378,6 +378,22 @@ pub fn jet_con(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
}
}
pub fn jet_dis(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
let arg = raw_slot(subject, 6);
let a = raw_slot(arg, 2).as_atom()?;
let b = raw_slot(arg, 3).as_atom()?;
let new_size = cmp::max(a.size(), b.size());
unsafe {
let (mut atom, dest) = IndirectAtom::new_raw_mut_bitslice(stack, new_size);
let a_bit = a.as_bitslice();
dest[..a_bit.len()].copy_from_bitslice(a_bit);
*dest &= b.as_bitslice();
Ok(atom.normalize_as_atom().as_noun())
}
}
pub fn jet_cut(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
let arg = raw_slot(subject, 6);
let bloq = raw_slot(arg, 2).as_direct()?.data() as usize;
@ -892,6 +908,23 @@ mod tests {
assert_math_jet_noun(s, jet_con, &[atom_128, atom_0], a128);
}
#[test]
fn test_dis() {
let ref mut s = init();
let (a0, a24, _a63, _a96, _a128) = atoms(s);
assert_math_jet(s, jet_dis, &[atom_0, atom_0], ubig!(0));
assert_math_jet(s, jet_dis, &[atom_24, atom_96], ubig!(0x22442));
assert_math_jet(
s,
jet_dis,
&[atom_96, atom_128],
ubig!(0x1204100814dca89866103010),
);
assert_math_jet_noun(s, jet_dis, &[atom_24, atom_63], a24);
assert_math_jet_noun(s, jet_dis, &[atom_0, atom_128], a0);
assert_math_jet_noun(s, jet_dis, &[atom_128, atom_0], a0);
}
#[test]
fn test_cut() {
let ref mut s = init();