on master help sign in
end
f4d4f3aiko
nock/src/jets.rs+13−1
@@ -62,6 +62,7 @@ pub fn generate_jets() -> Jets {
62 (161636738411171172446435323238280743696, WELP),
62 (161636738411171172446435323238280743696, WELP),
63 (90634096513747887582230817128332929026, ZING),
63 (90634096513747887582230817128332929026, ZING),
64 (59352245691598674621226842217946522940, BEX),
64 (59352245691598674621226842217946522940, BEX),
65+ (102718716366123785010912772034318125155, END),
65 ])
66 ])
66}
67}
67
68
@@ -553,4 +554,15 @@ static ZING: Jet = |_ctx, n| {
553 )
554 )
554};
555};
555
556
556−static BEX: Jet = |ctx, n| Rc::new(Noun::Atom(ctx.big_uints.one.clone() << n.as_u32().unwrap()));
557+static BEX: Jet = |ctx, n| Rc::new(Noun::Atom(&ctx.big_uints.one << n.as_u32().unwrap()));
558+
559+static END: Jet = |ctx, n| {
560+ let (a, b) = n.as_cell().unwrap();
561+ let bite = a.as_bite().unwrap();
562+
563+ let bits = 2u32.pow(bite.bloq) * bite.step;
564+
565+ let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
566+
567+ Rc::new(Noun::Atom(mask & b.as_atom().unwrap()))
568+};
nock/src/noun.rs+22
@@ -145,6 +145,28 @@ impl Noun {
145
145
146 (hash_pair((*battery).clone(), context), sample)
146 (hash_pair((*battery).clone(), context), sample)
147 }
147 }
148+
149+ pub fn as_bite(self: &Self) -> Option<Bite> {
150+ match self {
151+ Noun::Atom(_) => Option::Some(Bite {
152+ bloq: self.as_u32()?,
153+ step: 1,
154+ }),
155+
156+ Noun::Cell {
157+ p: bloq, q: step, ..
158+ } => Option::Some(Bite {
159+ bloq: bloq.as_u32()?,
160+ step: step.as_u32()?,
161+ }),
162+ }
163+ }
164+}
165+
166+#[derive(Clone)]
167+pub struct Bite {
168+ pub bloq: u32,
169+ pub step: u32,
148}
170}
149
171
150#[derive(Clone)]
172#[derive(Clone)]