[jets] add met jet

This commit is contained in:
Philip Monk 2023-02-14 20:15:03 -07:00
parent 956045a91d
commit 8946568a08
2 changed files with 26 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"cut") => Ok(jet_cut),
tas!(b"met") => Ok(jet_met),
tas!(b"mug") => Ok(jet_mug),
_ => {
// eprintln!("Unknown jet: {:?}", jet_name);

View File

@ -380,6 +380,17 @@ pub fn jet_rsh(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
}
}
pub fn jet_met(_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;
if bloq >= 64 {
return Err(Deterministic);
}
let a = raw_slot(arg, 3).as_atom()?;
Ok(D(met(bloq, a) as u64))
}
pub fn jet_mug(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
let arg = raw_slot(subject, 6);
Ok(mug(stack, arg).as_noun())
@ -861,6 +872,20 @@ mod tests {
assert_jet(s, jet_cut, sam, res);
}
#[test]
fn test_jet_met() {
let ref mut s = init();
let (a0, a24, _a63, _a96, a128) = atoms(s);
let sam = T(s, &[a0, a0]);
assert_jet(s, jet_met, sam, D(0));
let sam = T(s, &[a0, a24]);
assert_jet(s, jet_met, sam, D(24));
let sam = T(s, &[D(3), a24]);
assert_jet(s, jet_met, sam, D(3));
let sam = T(s, &[D(1), a128]);
assert_jet(s, jet_met, sam, D(64));
}
#[test]
fn test_mug() {
let ref mut s = init();