warm: return %fast-path with jet

This commit is contained in:
Edward Amsden 2023-11-13 23:03:40 -06:00
parent ac86b4455c
commit a43a12b9f3
2 changed files with 29 additions and 5 deletions

View File

@ -485,7 +485,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
}
Todo2::ComputeResult => {
if !cfg!(feature = "sham_hints") {
if let Some(jet) = context.warm.find_jet(
if let Some((jet, _path)) = context.warm.find_jet(
&mut context.stack,
&mut vale.subject,
&mut res,
@ -673,7 +673,7 @@ pub fn interpret(context: &mut Context, mut subject: Noun, formula: Noun) -> Res
Todo9::ComputeResult => {
if let Ok(mut formula) = res.slot_atom(kale.axis) {
if !cfg!(feature = "sham_hints") {
if let Some(jet) = context.warm.find_jet(
if let Some((jet, _path)) = context.warm.find_jet(
&mut context.stack,
&mut res,
&mut formula,
@ -1302,6 +1302,30 @@ pub fn inc(stack: &mut NockStack, atom: Atom) -> Atom {
}
}
fn assert_normalized(atom: Atom, path: Noun) {
unsafe {
if let Ok(indirect) = atom.as_indirect() {
if indirect.size() == 1 && *indirect.data_pointer() <= crate::noun::DIRECT_MAX{
panic!("Un-normalized indirect_atom (should be direct) returned from jet for {:?}", path);
} else if *indirect.data_pointer().add(indirect.size() - 1) == 0 {
panic!("Un-normalized indirect_atom (last word 0) returned from jet for {:?}", path);
}
} // nothing to do for direct atom
}
}
pub fn assert_all_normalized(res: Noun, path: Noun, depth: usize) {
match res.as_either_atom_cell() {
Left(atom) => { assert_normalized(atom, path); },
Right(cell) => {
if depth > 0 {
assert_all_normalized(cell.head(), path, depth - 1);
assert_all_normalized(cell.tail(), path, depth - 1);
}
},
}
}
fn path_to_cord(stack: &mut NockStack, path: Noun) -> Atom {
let mut cursor = path;
let mut length = 0usize;

View File

@ -133,11 +133,11 @@ impl Warm {
/// Walk through the linked list of WarmEntry objects and do a partial check
/// against the subject using Batteries (walk to root of parent batteries).
/// If there's a match, then we've found a valid jet.
pub fn find_jet(&mut self, stack: &mut NockStack, s: &mut Noun, f: &mut Noun) -> Option<Jet> {
pub fn find_jet(&mut self, stack: &mut NockStack, s: &mut Noun, f: &mut Noun) -> Option<(Jet, Noun)> {
let warm_it = self.0.lookup(stack, f)?;
for (_path, batteries, jet) in warm_it {
for (path, batteries, jet) in warm_it {
if batteries.matches(stack, *s) {
return Some(jet);
return Some((jet, path));
}
}
None