on master help sign in
end
commitf4d4f3a226d24cb89522898b1ebfba2117432734 authoriko <mail@iko.soy> dateSat 24 Aug 2024, 17:29 (2 years ago) parentb002a59
2 files changed+35−1
nock/src/jets.rs+13−1 nock/src/noun.rs+22
nock/src/jets.rs+13−1
@@ -62,6 +62,7 @@ pub fn generate_jets() -> Jets {
6262 (161636738411171172446435323238280743696, WELP),
6363 (90634096513747887582230817128332929026, ZING),
6464 (59352245691598674621226842217946522940, BEX),
65+ (102718716366123785010912772034318125155, END),
6566 ])
6667}
6768
@@ -553,4 +554,15 @@ static ZING: Jet = |_ctx, n| {
553554 )
554555};
555556
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 {
145145
146146 (hash_pair((*battery).clone(), context), sample)
147147 }
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,
148170}
149171
150172#[derive(Clone)]