on master help sign in
cat
a22aab6iko
nock/src/jets.rs+37−2
@@ -1,5 +1,4 @@
1use core::panic;
1use core::panic;
2−use num_bigint::BigUint;
3use num_integer::Integer;
2use num_integer::Integer;
4use std::{
3use std::{
5 cmp::Ordering,
4 cmp::Ordering,
@@ -65,6 +64,8 @@ pub fn generate_jets() -> Jets {
65 (59352245691598674621226842217946522940, BEX),
64 (59352245691598674621226842217946522940, BEX),
66 (102718716366123785010912772034318125155, END),
65 (102718716366123785010912772034318125155, END),
67 (233905026649167301608240871123208487851, CAN),
66 (233905026649167301608240871123208487851, CAN),
67+ (88906713429699361214497715048276521868, CAT),
68+ (194217032002582779752566874231896746840, MET),
68 ])
69 ])
69}
70}
70
71
@@ -562,7 +563,7 @@ static END: Jet = |ctx, n| {
562 let (a, b) = n.as_cell().unwrap();
563 let (a, b) = n.as_cell().unwrap();
563 let bite = a.as_bite().unwrap();
564 let bite = a.as_bite().unwrap();
564
565
565− let bits = 2u32.pow(bite.bloq) * bite.step;
566+ let bits = bite.bits();
566
567
567 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
568 let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
568
569
@@ -588,3 +589,37 @@ static CAN: Jet = |ctx, n| {
588 });
589 });
589 Rc::new(Noun::Atom(atom))
590 Rc::new(Noun::Atom(atom))
590};
591};
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 {
169 pub step: u32,
169 pub step: u32,
170}
170}
171
171
172+impl Bite {
173+ pub fn bits(self: &Self) -> u32 {
174+ 2u32.pow(self.bloq) * self.step
175+ }
176+}
177+
172#[derive(Clone)]
178#[derive(Clone)]
173pub struct NounListIterator {
179pub struct NounListIterator {
174 noun: Rc<Noun>,
180 noun: Rc<Noun>,