@@ -2,13 +2,14 @@ use core::panic;
22use murmur3::murmur3_32;
33use num_integer::Integer;
44use std::{
5+ borrow::Borrow,
56 collections::BTreeMap,
67 iter::{once, repeat_n, zip},
78 rc::Rc,
89};
910
1011use crate::{
11− interpreter::{slam_pulled_gate, InterpreterContext, TTanks},
12+ interpreter::{slam_pulled_gate, InterpreterContext, TTanks, EMPTY_TANKS},
1213 noun::{self, cell, Atom, Edge, Hair, Nail, Noun},
1314};
1415
@@ -107,6 +108,10 @@ pub fn generate_jets() -> Jets {
107108 (124976064672625230427889101290245200507, TRIP),
108109 (4078279288073906183633157465551067635, MUK),
109110 (261900159748071234702685239353558471892, MUG),
111+ (198191257620924788695943358402651905954, AOR),
112+ (299422828284010240628877806738195667652, DOR),
113+ (166326796552601297695313176538120818632, GOR),
114+ (7942398240152905363972500667649380756, MOR),
110115 ])
111116}
112117
@@ -1007,6 +1012,105 @@ static MUK: Jet = |_ctx, n| {
10071012 Ok(Rc::new(Noun::from_u32(muk(seed, len, key))))
10081013};
10091014
1015+static AOR: Jet = |ctx, n| {
1016+ let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1017+
1018+ if a == b {
1019+ Ok(ctx.nouns.y.clone())
1020+ } else {
1021+ match (a.borrow(), b.borrow()) {
1022+ (Noun::Cell { .. }, Noun::Atom(_)) => Ok(ctx.nouns.n.clone()),
1023+ (Noun::Cell { p: a_p, q: a_q, .. }, Noun::Cell { p: b_p, q: b_q, .. }) => {
1024+ if a_p == b_p {
1025+ AOR(ctx, &cell(a_q, b_q))
1026+ } else {
1027+ AOR(ctx, &cell(a_p, b_p))
1028+ }
1029+ }
1030+ (Noun::Atom(_), Noun::Cell { .. }) => Ok(ctx.nouns.y.clone()),
1031+ (Noun::Atom(a), Noun::Atom(b)) => {
1032+ let a = a.to_bytes_le();
1033+ let b = b.to_bytes_le();
1034+
1035+ let mut i = 0;
1036+ loop {
1037+ let c = a.get(i).unwrap_or(&0);
1038+ let d = b.get(i).unwrap_or(&0);
1039+
1040+ if a[0] == b[0] {
1041+ i += 1;
1042+ } else {
1043+ if c < d {
1044+ return Ok(ctx.nouns.y.clone());
1045+ } else {
1046+ return Ok(ctx.nouns.n.clone());
1047+ }
1048+ }
1049+ }
1050+ }
1051+ }
1052+ }
1053+};
1054+
1055+static DOR: Jet = |ctx, n| {
1056+ let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1057+
1058+ if a == b {
1059+ Ok(ctx.nouns.y.clone())
1060+ } else {
1061+ match (a.borrow(), b.borrow()) {
1062+ (Noun::Cell { .. }, Noun::Atom(_)) => Ok(ctx.nouns.n.clone()),
1063+ (Noun::Cell { p: a_p, q: a_q, .. }, Noun::Cell { p: b_p, q: b_q, .. }) => {
1064+ if a_p == b_p {
1065+ DOR(ctx, &cell(a_q, b_q))
1066+ } else {
1067+ DOR(ctx, &cell(a_p, b_p))
1068+ }
1069+ }
1070+ (Noun::Atom(_), Noun::Cell { .. }) => Ok(ctx.nouns.y.clone()),
1071+ (Noun::Atom(a), Noun::Atom(b)) => {
1072+ if a < b {
1073+ Ok(ctx.nouns.y.clone())
1074+ } else {
1075+ Ok(ctx.nouns.n.clone())
1076+ }
1077+ }
1078+ }
1079+ }
1080+};
1081+
1082+static GOR: Jet = |ctx, n| {
1083+ let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1084+ let c = a.mug();
1085+ let d = b.mug();
1086+
1087+ if c == d {
1088+ DOR(ctx, n)
1089+ } else {
1090+ if c < d {
1091+ Ok(ctx.nouns.y.clone())
1092+ } else {
1093+ Ok(ctx.nouns.n.clone())
1094+ }
1095+ }
1096+};
1097+
1098+static MOR: Jet = |ctx, n| {
1099+ let (a, b) = n.as_cell().ok_or(EMPTY_TANKS)?;
1100+ let c = Noun::from_u32(a.mug()).mug();
1101+ let d = Noun::from_u32(b.mug()).mug();
1102+
1103+ if c == d {
1104+ DOR(ctx, n)
1105+ } else {
1106+ if c < d {
1107+ Ok(ctx.nouns.y.clone())
1108+ } else {
1109+ Ok(ctx.nouns.n.clone())
1110+ }
1111+ }
1112+};
1113+
10101114static JUST: DoubleJet = |ctx, n, m| {
10111115 let char = n.as_atom()?;
10121116 let nail = m.as_nail()?;