Merge pull request #126 from urbit/as/demo-debug

Apply debugging fixes discovered during Assembly 2023 demo prep
This commit is contained in:
Alex Shelkovnykov 2023-11-15 15:09:30 -06:00 committed by GitHub
commit 77debd1a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 528 additions and 183 deletions

View File

@ -259,6 +259,9 @@ assert_eq_size!(&[Entry<()>], Stem<()>);
pub struct Hamt<T: Copy>(Stem<T>); pub struct Hamt<T: Copy>(Stem<T>);
impl<T: Copy + Preserve> Hamt<T> { impl<T: Copy + Preserve> Hamt<T> {
pub fn is_null(&self) -> bool {
self.0.bitmap == 0
}
// Make a new, empty HAMT // Make a new, empty HAMT
pub fn new() -> Self { pub fn new() -> Self {
Hamt(Stem { Hamt(Stem {

View File

@ -17,6 +17,7 @@ use ares_macros::tas;
use assert_no_alloc::assert_no_alloc; use assert_no_alloc::assert_no_alloc;
use bitvec::prelude::{BitSlice, Lsb0}; use bitvec::prelude::{BitSlice, Lsb0};
use either::Either::*; use either::Either::*;
use std::result;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
@ -284,6 +285,8 @@ impl From<cold::Error> for Error {
} }
} }
pub type Result = result::Result<Noun, Error>;
#[allow(unused_variables)] #[allow(unused_variables)]
fn debug_assertions(stack: &mut NockStack, noun: Noun) { fn debug_assertions(stack: &mut NockStack, noun: Noun) {
assert_acyclic!(noun); assert_acyclic!(noun);
@ -292,7 +295,7 @@ fn debug_assertions(stack: &mut NockStack, noun: Noun) {
} }
/** Interpret nock */ /** Interpret nock */
pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Result<Noun, Error> { pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Result {
let terminator = Arc::clone(&TERMINATOR); let terminator = Arc::clone(&TERMINATOR);
let orig_subject = subject; // for debugging let orig_subject = subject; // for debugging
let virtual_frame: *const u64 = context.stack.get_frame_pointer(); let virtual_frame: *const u64 = context.stack.get_frame_pointer();
@ -671,51 +674,54 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
} }
NockWork::Work11D(mut dint) => match dint.todo { NockWork::Work11D(mut dint) => match dint.todo {
Todo11D::ComputeHint => { Todo11D::ComputeHint => {
match hint::match_pre_hint(context, subject, dint.tag, dint.hint, dint.body) if let Some(ret) =
hint::match_pre_hint(context, subject, dint.tag, dint.hint, dint.body)
{ {
Ok(Some(found)) => { match ret {
res = found; Ok(found) => {
context.stack.pop::<NockWork>(); res = found;
} context.stack.pop::<NockWork>();
Ok(None) => { }
dint.todo = Todo11D::ComputeResult; Err(err) => {
*context.stack.top() = NockWork::Work11D(dint); break Err(err);
push_formula(&mut context.stack, dint.hint, false)?; }
}
Err(err) => {
break Err(err);
} }
} else {
dint.todo = Todo11D::ComputeResult;
*context.stack.top() = NockWork::Work11D(dint);
push_formula(&mut context.stack, dint.hint, false)?;
} }
} }
Todo11D::ComputeResult => { Todo11D::ComputeResult => {
match hint::match_pre_nock( if let Some(ret) = hint::match_pre_nock(
context, context,
subject, subject,
dint.tag, dint.tag,
Some((dint.hint, res)), Some((dint.hint, res)),
dint.body, dint.body,
) { ) {
Ok(Some(found)) => { match ret {
res = found; Ok(found) => {
context.stack.pop::<NockWork>(); res = found;
}
Ok(None) => {
if dint.tail {
context.stack.pop::<NockWork>(); context.stack.pop::<NockWork>();
} else {
dint.todo = Todo11D::Done;
dint.hint = res;
*context.stack.top() = NockWork::Work11D(dint);
} }
push_formula(&mut context.stack, dint.body, dint.tail)?; Err(err) => {
break Err(err);
}
} }
Err(err) => { } else {
break Err(err); if dint.tail {
context.stack.pop::<NockWork>();
} else {
dint.todo = Todo11D::Done;
dint.hint = res;
*context.stack.top() = NockWork::Work11D(dint);
} }
push_formula(&mut context.stack, dint.body, dint.tail)?;
} }
} }
Todo11D::Done => { Todo11D::Done => {
match hint::match_post_nock( if let Some(found) = hint::match_post_nock(
context, context,
subject, subject,
dint.tag, dint.tag,
@ -723,41 +729,40 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
dint.body, dint.body,
res, res,
) { ) {
Ok(Some(found)) => res = found, res = found;
Err(err) => break Err(err),
_ => {}
} }
context.stack.pop::<NockWork>(); context.stack.pop::<NockWork>();
} }
}, },
NockWork::Work11S(mut sint) => match sint.todo { NockWork::Work11S(mut sint) => match sint.todo {
Todo11S::ComputeResult => { Todo11S::ComputeResult => {
match hint::match_pre_nock(context, subject, sint.tag, None, sint.body) { if let Some(ret) =
Ok(Some(found)) => { hint::match_pre_nock(context, subject, sint.tag, None, sint.body)
res = found; {
context.stack.pop::<NockWork>(); match ret {
} Ok(found) => {
Ok(None) => { res = found;
if sint.tail {
context.stack.pop::<NockWork>(); context.stack.pop::<NockWork>();
} else {
sint.todo = Todo11S::Done;
*context.stack.top() = NockWork::Work11S(sint);
} }
push_formula(&mut context.stack, sint.body, sint.tail)?; Err(err) => {
break Err(err);
}
} }
Err(err) => { } else {
break Err(err); if sint.tail {
context.stack.pop::<NockWork>();
} else {
sint.todo = Todo11S::Done;
*context.stack.top() = NockWork::Work11S(sint);
} }
push_formula(&mut context.stack, sint.body, sint.tail)?;
} }
} }
Todo11S::Done => { Todo11S::Done => {
match hint::match_post_nock( if let Some(found) =
context, subject, sint.tag, None, sint.body, res, hint::match_post_nock(context, subject, sint.tag, None, sint.body, res)
) { {
Ok(Some(found)) => res = found, res = found;
Err(err) => break Err(err),
_ => {}
} }
context.stack.pop::<NockWork>(); context.stack.pop::<NockWork>();
} }
@ -849,7 +854,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
} }
} }
fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> Result<(), Error> { fn push_formula(stack: &mut NockStack, formula: Noun, tail: bool) -> result::Result<(), Error> {
unsafe { unsafe {
if let Ok(formula_cell) = formula.as_cell() { if let Ok(formula_cell) = formula.as_cell() {
// Formula // Formula
@ -1077,6 +1082,7 @@ pub fn exit(context: &mut Context, virtual_frame: *const u64, error: Error) -> E
while (stack).get_frame_pointer() != virtual_frame { while (stack).get_frame_pointer() != virtual_frame {
(stack).preserve(&mut preserve); (stack).preserve(&mut preserve);
// (stack).preserve(&mut context.cold);
(stack).frame_pop(); (stack).frame_pop();
} }
@ -1222,12 +1228,12 @@ mod hint {
tag: Atom, tag: Atom,
hint: Noun, hint: Noun,
body: Noun, body: Noun,
) -> Result<Option<Noun>, Error> { ) -> Option<Result> {
// XX: handle IndirectAtom tags // XX: handle IndirectAtom tags
match tag.as_direct()?.data() { match tag.direct()?.data() {
tas!(b"sham") => { tas!(b"sham") => {
if cfg!(feature = "sham_hints") { if cfg!(feature = "sham_hints") {
let jet_formula = hint.as_cell()?; let jet_formula = hint.cell()?;
// XX: what is the head here? // XX: what is the head here?
let jet_name = jet_formula.tail(); let jet_name = jet_formula.tail();
@ -1258,9 +1264,9 @@ mod hint {
let tape = tape(stack, "jet mismatch"); let tape = tape(stack, "jet mismatch");
let mean = T(stack, &[D(tas!(b"mean")), tape]); let mean = T(stack, &[D(tas!(b"mean")), tape]);
mean_push(stack, mean); mean_push(stack, mean);
Err(Error::Deterministic(D(0))) Some(Err(Error::Deterministic(D(0))))
} else { } else {
Ok(Some(nock_res)) Some(Ok(nock_res))
} }
} }
Err(error) => { Err(error) => {
@ -1277,17 +1283,17 @@ mod hint {
match error { match error {
Error::NonDeterministic(_) => { Error::NonDeterministic(_) => {
Err(Error::NonDeterministic(D(0))) Some(Err(Error::NonDeterministic(D(0))))
} }
_ => Err(Error::Deterministic(D(0))), _ => Some(Err(Error::Deterministic(D(0)))),
} }
} }
} }
} else { } else {
Ok(Some(jet_res)) Some(Ok(jet_res))
} }
} }
Err(JetErr::Punt) => Ok(None), Err(JetErr::Punt) => None,
Err(err) => { Err(err) => {
let stack = &mut context.stack; let stack = &mut context.stack;
// XX: need string interpolation without allocation // XX: need string interpolation without allocation
@ -1295,22 +1301,22 @@ mod hint {
let tape = tape(stack, "jet error"); let tape = tape(stack, "jet error");
let mean = T(stack, &[D(tas!(b"mean")), tape]); let mean = T(stack, &[D(tas!(b"mean")), tape]);
mean_push(stack, mean); mean_push(stack, mean);
Err(err.into()) Some(Err(err.into()))
} }
} }
} else { } else {
Ok(None) None
} }
} else { } else {
Ok(None) None
} }
} }
tas!(b"memo") => { tas!(b"memo") => {
let stack = &mut context.stack; let stack = &mut context.stack;
let mut key = Cell::new(stack, subject, body).as_noun(); let mut key = Cell::new(stack, subject, body).as_noun();
Ok(context.cache.lookup(stack, &mut key)) context.cache.lookup(stack, &mut key).map(Ok)
} }
_ => Ok(None), _ => None,
} }
} }
@ -1321,32 +1327,30 @@ mod hint {
tag: Atom, tag: Atom,
hint: Option<(Noun, Noun)>, hint: Option<(Noun, Noun)>,
_body: Noun, _body: Noun,
) -> Result<Option<Noun>, Error> { ) -> Option<Result> {
// XX: handle IndirectAtom tags // XX: handle IndirectAtom tags
match tag.as_direct()?.data() { match tag.direct()?.data() {
tas!(b"slog") => { tas!(b"slog") => {
let stack = &mut context.stack; let stack = &mut context.stack;
let newt = &mut context.newt; let newt = &mut context.newt;
let (_form, clue) = hint.ok_or(Error::Deterministic(D(0)))?; let (_form, clue) = hint?;
let slog_cell = clue.as_cell()?; let slog_cell = clue.cell()?;
let pri = slog_cell.head().as_direct()?.data(); let pri = slog_cell.head().direct()?.data();
let tank = slog_cell.tail(); let tank = slog_cell.tail();
newt.slog(stack, pri, tank); newt.slog(stack, pri, tank);
Ok(None)
} }
tas!(b"hand") | tas!(b"hunk") | tas!(b"lose") | tas!(b"mean") | tas!(b"spot") => { tas!(b"hand") | tas!(b"hunk") | tas!(b"lose") | tas!(b"mean") | tas!(b"spot") => {
let terminator = Arc::clone(&TERMINATOR); let terminator = Arc::clone(&TERMINATOR);
if (*terminator).load(Ordering::Relaxed) { if (*terminator).load(Ordering::Relaxed) {
return Err(Error::NonDeterministic(D(0))); return Some(Err(Error::NonDeterministic(D(0))));
} }
let stack = &mut context.stack; let stack = &mut context.stack;
let (_form, clue) = hint.ok_or(Error::Deterministic(D(0)))?; let (_form, clue) = hint?;
let noun = T(stack, &[tag.as_noun(), clue]); let noun = T(stack, &[tag.as_noun(), clue]);
mean_push(stack, noun); mean_push(stack, noun);
Ok(None)
} }
tas!(b"hela") => { tas!(b"hela") => {
// XX: This only prints the trace down to the bottom of THIS // XX: This only prints the trace down to the bottom of THIS
@ -1361,10 +1365,7 @@ mod hint {
let newt = &mut context.newt; let newt = &mut context.newt;
if unsafe { !toon.head().raw_equals(D(2)) } { if unsafe { !toon.head().raw_equals(D(2)) } {
let tape = tape(stack, "%hela failed: toon not %2"); panic!("serf: %hela: mook returned invalid tone");
let mean = T(stack, &[D(tas!(b"mean")), tape]);
mean_push(stack, mean);
return Err(Error::Deterministic(D(0)));
} }
let mut list = toon.tail(); let mut list = toon.tail();
@ -1373,25 +1374,28 @@ mod hint {
break; break;
} }
let cell = list.as_cell().unwrap(); if let Ok(cell) = list.as_cell() {
newt.slog(stack, 0, cell.head()); newt.slog(stack, 0, cell.head());
list = cell.tail();
list = cell.tail(); } else {
let stack = &mut context.stack;
let tape = tape(stack, "serf: %hela: list ends without ~");
slog_leaf(stack, newt, tape);
break;
}
} }
Ok(None)
} }
Err(err) => { Err(_) => {
let stack = &mut context.stack; let stack = &mut context.stack;
let tape = tape(stack, "%hela failed: mook error"); let tape = tape(stack, "serf: %hela: mook error");
let mean = T(stack, &[D(tas!(b"mean")), tape]); slog_leaf(stack, &mut context.newt, tape);
mean_push(stack, mean);
Err(err.into())
} }
} }
} }
_ => Ok(None), _ => {}
} };
None
} }
/** Match static and dynamic hints after the nock formula is evaluated */ /** Match static and dynamic hints after the nock formula is evaluated */
@ -1402,7 +1406,7 @@ mod hint {
hint: Option<Noun>, hint: Option<Noun>,
body: Noun, body: Noun,
res: Noun, res: Noun,
) -> Result<Option<Noun>, Error> { ) -> Option<Noun> {
let stack = &mut context.stack; let stack = &mut context.stack;
let newt = &mut context.newt; let newt = &mut context.newt;
let cold = &mut context.cold; let cold = &mut context.cold;
@ -1410,7 +1414,7 @@ mod hint {
let cache = &mut context.cache; let cache = &mut context.cache;
// XX: handle IndirectAtom tags // XX: handle IndirectAtom tags
match tag.as_direct()?.data() { match tag.direct()?.data() {
tas!(b"memo") => { tas!(b"memo") => {
let mut key = Cell::new(stack, subject, body).as_noun(); let mut key = Cell::new(stack, subject, body).as_noun();
context.cache = cache.insert(stack, &mut key, res); context.cache = cache.insert(stack, &mut key, res);
@ -1422,12 +1426,32 @@ mod hint {
if !cfg!(feature = "sham_hints") { if !cfg!(feature = "sham_hints") {
if let Some(clue) = hint { if let Some(clue) = hint {
let cold_res: cold::Result = { let cold_res: cold::Result = {
let chum = clue.slot(2)?; let chum = clue.slot(2).ok()?;
let parent_formula_op = clue.slot(12)?.as_atom()?.as_direct()?;
let parent_formula_ax = clue.slot(13)?.as_atom()?; let mut parent = clue.slot(6).ok()?;
loop {
if let Ok(parent_cell) = parent.as_cell() {
if unsafe { parent_cell.head().raw_equals(D(11)) } {
match parent.slot(7) {
Ok(noun) => {
parent = noun;
}
Err(_) => {
return None;
}
}
} else {
break;
}
} else {
return None;
}
}
let parent_formula_op = parent.slot(2).ok()?.atom()?.direct()?;
let parent_formula_ax = parent.slot(3).ok()?.atom()?;
if parent_formula_op.data() == 1 { if parent_formula_op.data() == 1 {
if parent_formula_ax.as_direct()?.data() == 0 { if parent_formula_ax.direct()?.data() == 0 {
cold.register(stack, res, parent_formula_ax, chum) cold.register(stack, res, parent_formula_ax, chum)
} else { } else {
// XX: Need better message in slog; need better slogging tools // XX: Need better message in slog; need better slogging tools
@ -1472,7 +1496,7 @@ mod hint {
_ => {} _ => {}
} }
Ok(None) None
} }
fn slog_leaf(stack: &mut NockStack, newt: &mut Newt, tape: Noun) { fn slog_leaf(stack: &mut NockStack, newt: &mut Newt, tape: Noun) {

View File

@ -20,6 +20,7 @@ use crate::jets::form::*;
use crate::jets::hash::*; use crate::jets::hash::*;
use crate::jets::hot::Hot; use crate::jets::hot::Hot;
use crate::jets::list::*; use crate::jets::list::*;
use crate::jets::lute::*;
use crate::jets::math::*; use crate::jets::math::*;
use crate::jets::nock::*; use crate::jets::nock::*;
use crate::jets::serial::*; use crate::jets::serial::*;

View File

@ -293,6 +293,12 @@ pub fn jet_rsh(context: &mut Context, subject: Noun) -> Result {
} }
} }
pub fn jet_xeb(_context: &mut Context, subject: Noun) -> Result {
let sam = slot(subject, 6)?;
let a = slot(sam, 1)?.as_atom()?;
Ok(D(util::met(0, a) as u64))
}
/* /*
* Bit logic * Bit logic
*/ */
@ -337,12 +343,6 @@ pub fn jet_mix(context: &mut Context, subject: Noun) -> Result {
} }
} }
pub fn jet_xeb(_context: &mut Context, subject: Noun) -> Result {
let sam = slot(subject, 6)?;
let a = slot(sam, 1)?.as_atom()?;
Ok(D(util::met(0, a) as u64))
}
pub mod util { pub mod util {
use crate::jets::util::*; use crate::jets::util::*;
use crate::jets::Result; use crate::jets::Result;

View File

@ -309,6 +309,14 @@ impl Preserve for Cold {
} }
impl Cold { impl Cold {
pub fn is_null(&self) -> bool {
unsafe {
(*self.0).battery_to_paths.is_null()
|| (*self.0).battery_to_paths.is_null()
|| (*self.0).root_to_paths.is_null()
}
}
pub fn new(stack: &mut NockStack) -> Self { pub fn new(stack: &mut NockStack) -> Self {
let battery_to_paths = Hamt::new(); let battery_to_paths = Hamt::new();
let root_to_paths = Hamt::new(); let root_to_paths = Hamt::new();

View File

@ -1,59 +1,363 @@
use crate::jets::*; use crate::jets::*;
use crate::noun::{Atom, DirectAtom, Noun, D, T}; use crate::noun::{Atom, DirectAtom, IndirectAtom, Noun, D, T};
use ares_macros::tas; use ares_macros::tas;
use either::Either::{self, Left, Right}; use either::Either::{self, Left, Right};
use std::ptr::null_mut; use std::ptr::null_mut;
const A_50: Either<u64, (u64, u64)> = Right((tas!(b"a"), 50)); // const A_50: Either<u64, (u64, u64)> = Right((b"a", 50));
const K_139: Either<&[u8], (u64, u64)> = Right((tas!(b"k"), 139));
// // This is the const state all in one spot as literals
// #[allow(clippy::complexity)]
// const SHAM_HOT_STATE: &[(&[Either<u64, (u64, u64)>], u64, Jet)] = &[
// (&[A_50, Left(b"add")], 1, jet_add),
// (&[A_50, Left(b"dec")], 1, jet_dec),
// (&[A_50, Left(b"div")], 1, jet_div),
// (&[A_50, Left(b"dvr")], 1, jet_dvr),
// (&[A_50, Left(b"gth")], 1, jet_gth),
// (&[A_50, Left(b"gte")], 1, jet_gte),
// (&[A_50, Left(b"lte")], 1, jet_lte),
// (&[A_50, Left(b"lth")], 1, jet_lth),
// (&[A_50, Left(b"mod")], 1, jet_mod),
// (&[A_50, Left(b"mul")], 1, jet_mul),
// (&[A_50, Left(b"sub")], 1, jet_sub),
// //
// (&[A_50, Left(b"cap")], 1, jet_cap),
// (&[A_50, Left(b"mas")], 1, jet_mas),
// //
// (&[A_50, Left(b"lent")], 1, jet_lent),
// (&[A_50, Left(b"flop")], 1, jet_flop),
// //
// (&[A_50, Left(b"bex")], 1, jet_bex),
// (&[A_50, Left(b"can")], 1, jet_can),
// (&[A_50, Left(b"cat")], 1, jet_cat),
// (&[A_50, Left(b"cut")], 1, jet_cut),
// (&[A_50, Left(b"end")], 1, jet_end),
// (&[A_50, Left(b"lsh")], 1, jet_lsh),
// (&[A_50, Left(b"met")], 1, jet_met),
// (&[A_50, Left(b"rap")], 1, jet_rap),
// (&[A_50, Left(b"rep")], 1, jet_rep),
// (&[A_50, Left(b"rev")], 1, jet_rev),
// (&[A_50, Left(b"rip")], 1, jet_rip),
// (&[A_50, Left(b"rsh")], 1, jet_rsh),
// (&[A_50, Left(b"xeb")], 1, jet_xeb),
// //
// (&[A_50, Left(b"con")], 1, jet_con),
// (&[A_50, Left(b"dis")], 1, jet_dis),
// (&[A_50, Left(b"mix")], 1, jet_mix),
// //
// (&[A_50, Left(b"mug")], 1, jet_mug),
// //
// (&[A_50, Left(b"dor")], 1, jet_dor),
// (&[A_50, Left(b"gor")], 1, jet_gor),
// (&[A_50, Left(b"mor")], 1, jet_mor),
// //
// (&[A_50, Left(b"scow")], 1, jet_scow),
// //
// (&[A_50, Left(b"mink")], 1, jet_mink),
// ];
// This is the const state all in one spot as literals
#[allow(clippy::complexity)] #[allow(clippy::complexity)]
const HOT_STATE: &[(&[Either<u64, (u64, u64)>], u64, Jet)] = &[ const TRUE_HOT_STATE: &[(&[Either<&[u8], (u64, u64)>], u64, Jet)] = &[
(&[A_50, Left(tas!(b"add"))], 1, jet_add), (&[K_139, Left(b"one"), Left(b"add")], 1, jet_add),
(&[A_50, Left(tas!(b"dec"))], 1, jet_dec), (&[K_139, Left(b"one"), Left(b"dec")], 1, jet_dec),
(&[A_50, Left(tas!(b"div"))], 1, jet_div), (&[K_139, Left(b"one"), Left(b"div")], 1, jet_div),
(&[A_50, Left(tas!(b"dvr"))], 1, jet_dvr), (&[K_139, Left(b"one"), Left(b"dvr")], 1, jet_dvr),
(&[A_50, Left(tas!(b"gth"))], 1, jet_gth), (&[K_139, Left(b"one"), Left(b"gte")], 1, jet_gte),
(&[A_50, Left(tas!(b"gte"))], 1, jet_gte), (&[K_139, Left(b"one"), Left(b"gth")], 1, jet_gth),
(&[A_50, Left(tas!(b"lte"))], 1, jet_lte), (&[K_139, Left(b"one"), Left(b"lte")], 1, jet_lte),
(&[A_50, Left(tas!(b"lth"))], 1, jet_lth), (&[K_139, Left(b"one"), Left(b"lth")], 1, jet_lth),
(&[A_50, Left(tas!(b"mod"))], 1, jet_mod), (&[K_139, Left(b"one"), Left(b"max")], 1, jet_max),
(&[A_50, Left(tas!(b"mul"))], 1, jet_mul), (&[K_139, Left(b"one"), Left(b"min")], 1, jet_min),
(&[A_50, Left(tas!(b"sub"))], 1, jet_sub), (&[K_139, Left(b"one"), Left(b"mod")], 1, jet_mod),
(&[K_139, Left(b"one"), Left(b"mul")], 1, jet_mul),
(&[K_139, Left(b"one"), Left(b"sub")], 1, jet_sub),
// //
(&[A_50, Left(tas!(b"cap"))], 1, jet_cap), (&[K_139, Left(b"one"), Left(b"cap")], 1, jet_cap),
(&[A_50, Left(tas!(b"mas"))], 1, jet_mas), (&[K_139, Left(b"one"), Left(b"mas")], 1, jet_mas),
(&[K_139, Left(b"one"), Left(b"peg")], 1, jet_peg),
// //
(&[A_50, Left(tas!(b"lent"))], 1, jet_lent), (
(&[A_50, Left(tas!(b"flop"))], 1, jet_flop), &[K_139, Left(b"one"), Left(b"two"), Left(b"flop")],
1,
jet_flop,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"lent")],
1,
jet_lent,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"zing")],
1,
jet_zing,
),
// //
(&[A_50, Left(tas!(b"bex"))], 1, jet_bex), (
(&[A_50, Left(tas!(b"can"))], 1, jet_can), &[K_139, Left(b"one"), Left(b"two"), Left(b"bex")],
(&[A_50, Left(tas!(b"cat"))], 1, jet_cat), 1,
(&[A_50, Left(tas!(b"cut"))], 1, jet_cut), jet_bex,
(&[A_50, Left(tas!(b"end"))], 1, jet_end), ),
(&[A_50, Left(tas!(b"lsh"))], 1, jet_lsh), (
(&[A_50, Left(tas!(b"met"))], 1, jet_met), &[K_139, Left(b"one"), Left(b"two"), Left(b"can")],
(&[A_50, Left(tas!(b"rap"))], 1, jet_rap), 1,
(&[A_50, Left(tas!(b"rep"))], 1, jet_rep), jet_can,
(&[A_50, Left(tas!(b"rev"))], 1, jet_rev), ),
(&[A_50, Left(tas!(b"rip"))], 1, jet_rip), (
(&[A_50, Left(tas!(b"rsh"))], 1, jet_rsh), &[K_139, Left(b"one"), Left(b"two"), Left(b"cat")],
(&[A_50, Left(tas!(b"xeb"))], 1, jet_xeb), 1,
jet_cat,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"cut")],
1,
jet_cut,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"end")],
1,
jet_end,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"lsh")],
1,
jet_lsh,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"met")],
1,
jet_met,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"rap")],
1,
jet_rap,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"rep")],
1,
jet_rep,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"rev")],
1,
jet_rev,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"rip")],
1,
jet_rip,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"rsh")],
1,
jet_rsh,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"xeb")],
1,
jet_xeb,
),
// //
(&[A_50, Left(tas!(b"con"))], 1, jet_con), (
(&[A_50, Left(tas!(b"dis"))], 1, jet_dis), &[K_139, Left(b"one"), Left(b"two"), Left(b"con")],
(&[A_50, Left(tas!(b"mix"))], 1, jet_mix), 1,
jet_con,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"dis")],
1,
jet_dis,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"mix")],
1,
jet_mix,
),
// //
(&[A_50, Left(tas!(b"mug"))], 1, jet_mug), (
&[K_139, Left(b"one"), Left(b"two"), Left(b"mug")],
1,
jet_mug,
),
// //
(&[A_50, Left(tas!(b"dor"))], 1, jet_dor), (
(&[A_50, Left(tas!(b"gor"))], 1, jet_gor), &[K_139, Left(b"one"), Left(b"two"), Left(b"dor")],
(&[A_50, Left(tas!(b"mor"))], 1, jet_mor), 1,
jet_dor,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"gor")],
1,
jet_gor,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"mor")],
1,
jet_mor,
),
// //
(&[A_50, Left(tas!(b"scow"))], 1, jet_scow), (
&[K_139, Left(b"one"), Left(b"two"), Left(b"cue")],
1,
jet_cue,
),
(
&[K_139, Left(b"one"), Left(b"two"), Left(b"jam")],
1,
jet_jam,
),
// //
(&[A_50, Left(tas!(b"mink"))], 1, jet_mink), (
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"scow"),
],
1,
jet_scow,
),
//
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"mink"),
],
1,
jet_mink,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"mole"),
],
1,
jet_mole,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"mule"),
],
1,
jet_mule,
),
//
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"crop"),
],
1,
jet_ut_crop,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"fish"),
],
1,
jet_ut_fish,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"fuse"),
],
1,
jet_ut_fuse,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"mint"),
],
1,
jet_ut_mint,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"mull"),
],
1,
jet_ut_mull,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"nest"),
Left(b"nest-in"),
Left(b"nest-dext"),
],
1,
jet_ut_nest_dext,
),
(
&[
K_139,
Left(b"one"),
Left(b"two"),
Left(b"tri"),
Left(b"qua"),
Left(b"pen"),
Left(b"ut"),
Left(b"rest"),
],
1,
jet_ut_rest,
),
]; ];
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -63,15 +367,15 @@ impl Hot {
pub fn init(stack: &mut NockStack) -> Self { pub fn init(stack: &mut NockStack) -> Self {
unsafe { unsafe {
let mut next = Hot(null_mut()); let mut next = Hot(null_mut());
for (htap, axe, jet) in HOT_STATE { for (htap, axe, jet) in TRUE_HOT_STATE {
let mut a_path = D(0); let mut a_path = D(0);
for i in *htap { for i in *htap {
match i { match i {
Left(tas) => { Left(tas) => {
a_path = T( let chum = IndirectAtom::new_raw_bytes_ref(stack, tas)
stack, .normalize_as_atom()
&[DirectAtom::new_panic(*tas).as_atom().as_noun(), a_path], .as_noun();
); a_path = T(stack, &[chum, a_path]);
} }
Right((tas, ver)) => { Right((tas, ver)) => {
let chum = T( let chum = T(

View File

@ -8,7 +8,7 @@ use ares_macros::tas;
crate::gdb!(); crate::gdb!();
pub fn jet_crop(context: &mut Context, subject: Noun) -> Result { pub fn jet_ut_crop(context: &mut Context, subject: Noun) -> Result {
let rff = slot(subject, 6)?; let rff = slot(subject, 6)?;
let van = slot(subject, 7)?; let van = slot(subject, 7)?;
@ -37,7 +37,7 @@ pub fn jet_crop(context: &mut Context, subject: Noun) -> Result {
} }
} }
pub fn jet_fish(context: &mut Context, subject: Noun) -> Result { pub fn jet_ut_fish(context: &mut Context, subject: Noun) -> Result {
// axe must be Atom, though we use it as Noun // axe must be Atom, though we use it as Noun
let axe = slot(subject, 6)?.as_atom()?; let axe = slot(subject, 6)?.as_atom()?;
let van = slot(subject, 7)?; let van = slot(subject, 7)?;
@ -149,7 +149,7 @@ pub fn jet_ut_mull(context: &mut Context, subject: Noun) -> Result {
} }
} }
pub fn jet_ut_nest(context: &mut Context, subject: Noun) -> Result { pub fn jet_ut_nest_dext(context: &mut Context, subject: Noun) -> Result {
let nest_in_core = slot(subject, 3)?; let nest_in_core = slot(subject, 3)?;
let seg = slot(nest_in_core, 12)?; let seg = slot(nest_in_core, 12)?;

View File

@ -252,19 +252,20 @@ pub mod util {
let tape = rip(stack, 3, 1, atom)?; let tape = rip(stack, 3, 1, atom)?;
T(stack, &[LEAF, tape]) T(stack, &[LEAF, tape])
} }
Right(cell) => { Right(_cell) => {
'tank: { // 'tank: {
if let Ok(tone) = mink(context, dat, cell.head()) { // if let Ok(tone) = mink(context, dat, cell.head()) {
if let Some(cell) = tone.cell() { // if let Some(cell) = tone.cell() {
if cell.head().raw_equals(D(0)) { // if cell.head().raw_equals(D(0)) {
// XX: need to check that this is // // XX: need to check that this is
// actually a path; // // actually a path;
// return leaf+"mook.mean" if not // // return leaf+"mook.mean" if not
break 'tank cell.tail(); // break 'tank cell.tail();
} // }
} // }
} // }
{
let stack = &mut context.stack; let stack = &mut context.stack;
let tape = tape(stack, "####"); let tape = tape(stack, "####");
T(stack, &[LEAF, tape]) T(stack, &[LEAF, tape])

View File

@ -9,24 +9,12 @@ use std::cmp::Ordering;
crate::gdb!(); crate::gdb!();
pub fn jet_mor(context: &mut Context, subject: Noun) -> jets::Result { pub fn jet_dor(context: &mut Context, subject: Noun) -> jets::Result {
let stack = &mut context.stack;
let sam = slot(subject, 6)?; let sam = slot(subject, 6)?;
let a = slot(sam, 2)?; let a = slot(sam, 2)?;
let b = slot(sam, 3)?; let b = slot(sam, 3)?;
let c = mug(stack, a); Ok(util::dor(&mut context.stack, a, b))
let d = mug(stack, b);
let e = mug(stack, c.as_noun());
let f = mug(stack, d.as_noun());
match e.data().cmp(&f.data()) {
Ordering::Greater => Ok(NO),
Ordering::Less => Ok(YES),
Ordering::Equal => Ok(util::dor(stack, a, b)),
}
} }
pub fn jet_gor(context: &mut Context, subject: Noun) -> jets::Result { pub fn jet_gor(context: &mut Context, subject: Noun) -> jets::Result {
@ -46,12 +34,24 @@ pub fn jet_gor(context: &mut Context, subject: Noun) -> jets::Result {
} }
} }
pub fn jet_dor(context: &mut Context, subject: Noun) -> jets::Result { pub fn jet_mor(context: &mut Context, subject: Noun) -> jets::Result {
let stack = &mut context.stack;
let sam = slot(subject, 6)?; let sam = slot(subject, 6)?;
let a = slot(sam, 2)?; let a = slot(sam, 2)?;
let b = slot(sam, 3)?; let b = slot(sam, 3)?;
Ok(util::dor(&mut context.stack, a, b)) let c = mug(stack, a);
let d = mug(stack, b);
let e = mug(stack, c.as_noun());
let f = mug(stack, d.as_noun());
match e.data().cmp(&f.data()) {
Ordering::Greater => Ok(NO),
Ordering::Less => Ok(YES),
Ordering::Equal => Ok(util::dor(stack, a, b)),
}
} }
pub mod util { pub mod util {

View File

@ -358,6 +358,10 @@ impl IndirectAtom {
*(indirect.normalize()) *(indirect.normalize())
} }
pub unsafe fn new_raw_bytes_ref<A: NounAllocator>(allocator: &mut A, data: &[u8]) -> Self {
IndirectAtom::new_raw_bytes(allocator, data.len(), data.as_ptr())
}
/** Make an indirect atom that can be written into. Return the atom (which should not be used /** Make an indirect atom that can be written into. Return the atom (which should not be used
* until it is written and normalized) and a mutable pointer which is the data buffer for the * until it is written and normalized) and a mutable pointer which is the data buffer for the
* indirect atom, to be written into. * indirect atom, to be written into.

View File

@ -3,7 +3,7 @@ use crate::interpreter;
use crate::interpreter::{inc, interpret, Error}; use crate::interpreter::{inc, interpret, Error};
use crate::jets::cold::Cold; use crate::jets::cold::Cold;
use crate::jets::hot::Hot; use crate::jets::hot::Hot;
use crate::jets::list::util::*; use crate::jets::list::util::{lent, zing};
use crate::jets::nock::util::mook; use crate::jets::nock::util::mook;
use crate::jets::warm::Warm; use crate::jets::warm::Warm;
use crate::mem::NockStack; use crate::mem::NockStack;
@ -38,7 +38,7 @@ impl Context {
// TODO: switch to Pma when ready // TODO: switch to Pma when ready
// let snap = &mut snapshot::pma::Pma::new(snap_path); // let snap = &mut snapshot::pma::Pma::new(snap_path);
let mut snapshot = DoubleJam::new(snap_path); let mut snapshot = DoubleJam::new(snap_path);
let mut stack = NockStack::new(256 << 10 << 10, 0); let mut stack = NockStack::new(1024 << 10 << 10, 0);
let newt = Newt::new(); let newt = Newt::new();
let cache = Hamt::<Noun>::new(); let cache = Hamt::<Noun>::new();