on master help sign in
cat
commita22aab61c5601570624e6861ffda52aff79cbf63 authoriko <mail@iko.soy> dateSun 25 Aug 2024, 16:59 (2 years ago) parenteb29c2e
2 files changed+43−2
nock/src/jets.rs+37−2 nock/src/noun.rs+6
nock/src/jets.rs+37−2
@@ -1,5 +1,4 @@
11use core::panic;
2−use num_bigint::BigUint;
32use num_integer::Integer;
43use std::{
54 cmp::Ordering,
@@ -65,6 +64,8 @@ pub fn generate_jets() -> Jets {
6564 (59352245691598674621226842217946522940, BEX),
6665 (102718716366123785010912772034318125155, END),
6766 (233905026649167301608240871123208487851, CAN),
67+ (88906713429699361214497715048276521868, CAT),
68+ (194217032002582779752566874231896746840, MET),
6869 ])
6970}
7071
@@ -562,7 +563,7 @@ static END: Jet = |ctx, n| {
562563 let (a, b) = n.as_cell().unwrap();
563564 let bite = a.as_bite().unwrap();
564565
565− let bits = 2u32.pow(bite.bloq) * bite.step;
566+ let bits = bite.bits();
566567
567568 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
568569
@@ -588,3 +589,37 @@ static CAN: Jet = |ctx, n| {
588589 });
589590 Rc::new(Noun::Atom(atom))
590591};
592+
593+static CAT: Jet = |_ctx, n| {
594+ let (bloq, b) = n.as_cell().unwrap();
595+ let (b, c) = b.as_cell().unwrap();
596+
597+ let bloq = bloq.as_u32().unwrap();
598+ let b = b.as_atom().unwrap();
599+ let c = c.as_atom().unwrap();
600+
601+ Rc::new(Noun::Atom(
602+ (c << (met(bloq, b.clone()) * 2u32.pow(bloq))) | b,
603+ ))
604+};
605+
606+static MET: Jet = |_ctx, n| {
607+ let (bloq, b) = n.as_cell().unwrap();
608+ let b: Atom = b.as_atom().unwrap().clone();
609+ let bloq = bloq.as_u32().unwrap();
610+
611+ Rc::new(Noun::from_u32(met(bloq, b)))
612+};
613+
614+fn met(bloq: u32, mut a: Atom) -> u32 {
615+ let bits = 2u32.pow(bloq);
616+
617+ let mut c = 0;
618+
619+ while a > Atom::ZERO {
620+ a = a >> bits;
621+ c += 1;
622+ }
623+
624+ c
625+}
nock/src/noun.rs+6
@@ -169,6 +169,12 @@ pub struct Bite {
169169 pub step: u32,
170170}
171171
172+impl Bite {
173+ pub fn bits(self: &Self) -> u32 {
174+ 2u32.pow(self.bloq) * self.step
175+ }
176+}
177+
172178#[derive(Clone)]
173179pub struct NounListIterator {
174180 noun: Rc<Noun>,