Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jets: non-sham dashboard #92

Merged
merged 18 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/ares/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ check_all = [ "check_acyclic", "check_forwarding", "check_junior" ]
check_acyclic = []
check_forwarding = []
check_junior = []
sham_hints = []
50 changes: 47 additions & 3 deletions rust/ares/src/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,12 @@ assert_eq_size!(&[(Noun, ())], Leaf<()>);
// Our custom stem type is the same size as a fat pointer to `Entry`s
assert_eq_size!(&[Entry<()>], Stem<()>);

#[derive(Copy, Clone)]
pub struct Hamt<T: Copy>(Stem<T>);

impl<T: Copy> Hamt<T> {
impl<T: Copy + Preserve> Hamt<T> {
// Make a new, empty HAMT
pub fn new() -> Hamt<T> {
pub fn new() -> Self {
Hamt(Stem {
bitmap: 0,
typemap: 0,
Expand Down Expand Up @@ -425,13 +426,56 @@ impl<T: Copy> Hamt<T> {
}
}

impl<T: Copy> Default for Hamt<T> {
impl<T: Copy + Preserve> Default for Hamt<T> {
fn default() -> Self {
Self::new()
}
}

impl<T: Copy + Preserve> Preserve for Hamt<T> {
unsafe fn assert_in_stack(&self, stack: &NockStack) {
stack.struct_is_in(self.0.buffer, self.0.size());
let mut traversal_stack: [Option<(Stem<T>, u32)>; 6] = [None; 6];
traversal_stack[0] = Some((self.0, 0));
let mut traversal_depth = 1;
'check: loop {
if traversal_depth == 0 {
break;
}
let (stem, mut position) = traversal_stack[traversal_depth - 1]
.expect("Attempted to access uninitialized array element");
// can we loop over the size and count leading 0s remaining in the bitmap?
'check_stem: loop {
if position >= 32 {
traversal_depth -= 1;
continue 'check;
}
match stem.entry(position) {
None => {
position += 1;
continue 'check_stem;
}
Some((Left(next_stem), _idx)) => {
stack.struct_is_in(next_stem.buffer, next_stem.size());
assert!(traversal_depth <= 5); // will increment
traversal_stack[traversal_depth - 1].as_mut().unwrap().1 = position + 1;
ashelkovnykov marked this conversation as resolved.
Show resolved Hide resolved
traversal_stack[traversal_depth] = Some((next_stem, 0));
traversal_depth += 1;
continue 'check;
}
Some((Right(leaf), _idx)) => {
stack.struct_is_in(leaf.buffer, leaf.len);
for pair in leaf.to_mut_slice().iter() {
pair.0.assert_in_stack(stack);
pair.1.assert_in_stack(stack);
}
position += 1;
continue 'check_stem;
}
}
}
}
}
unsafe fn preserve(&mut self, stack: &mut NockStack) {
if stack.is_in_frame(self.0.buffer) {
let dest_buffer = stack.struct_alloc_in_previous_frame(self.0.size());
Expand Down
217 changes: 152 additions & 65 deletions rust/ares/src/interpreter.rs

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions rust/ares/src/jets.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pub mod cold;
pub mod hot;
pub mod warm;

pub mod bits;
pub mod form;
pub mod hash;
Expand All @@ -8,12 +12,15 @@ pub mod tree;

use crate::interpreter::Context;
use crate::jets::bits::*;
use crate::jets::cold::Cold;
use crate::jets::form::*;
use crate::jets::hash::*;
use crate::jets::hot::Hot;
use crate::jets::math::*;
use crate::jets::nock::*;
use crate::jets::text::*;
use crate::jets::tree::*;
use crate::jets::warm::Warm;
use crate::mem::NockStack;
use crate::noun::{self, Noun, Slots};
use ares_macros::tas;
Expand Down Expand Up @@ -309,10 +316,17 @@ pub mod util {
}

pub fn assert_jet(stack: &mut NockStack, jet: Jet, sam: Noun, res: Noun) {
let mut cache = Hamt::<Noun>::new();
ashelkovnykov marked this conversation as resolved.
Show resolved Hide resolved
let mut cold = Cold::new(stack);
let mut warm = Warm::new();
let hot = Hot::init(stack);
let mut context = Context {
stack,
newt: None,
cache: &mut Hamt::<Noun>::new(),
cache: &mut cache,
cold: &mut cold,
warm: &mut warm,
hot: &hot,
};
let sam = T(context.stack, &[D(0), sam, D(0)]);
let jet_res = assert_no_alloc(|| jet(&mut context, sam).unwrap());
Expand All @@ -330,10 +344,17 @@ pub mod util {
}

pub fn assert_jet_err(stack: &mut NockStack, jet: Jet, sam: Noun, err: JetErr) {
let mut cache = Hamt::<Noun>::new();
let mut cold = Cold::new(stack);
let mut warm = Warm::new();
let hot = Hot::init(stack);
let mut context = Context {
stack,
newt: None,
cache: &mut Hamt::<Noun>::new(),
cache: &mut cache,
cold: &mut cold,
warm: &mut warm,
hot: &hot,
};
let sam = T(context.stack, &[D(0), sam, D(0)]);
let jet_res = jet(&mut context, sam);
Expand Down
Loading