mirror of
https://github.com/urbit/ares.git
synced 2024-12-29 16:23:56 +03:00
Apply lints suggested by cargo clippy
This commit is contained in:
parent
7ed735e1e3
commit
b60100c806
@ -1,7 +1,6 @@
|
|||||||
use ares::mem::NockStack;
|
use ares::mem::NockStack;
|
||||||
use ares::noun::{DirectAtom, IndirectAtom};
|
use ares::noun::{DirectAtom, IndirectAtom};
|
||||||
use ares::serialization::{cue, jam};
|
use ares::serialization::{cue, jam};
|
||||||
use memmap;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -11,7 +10,7 @@ use std::time::SystemTime;
|
|||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let filename = env::args().nth(1).expect("Must provide input filename");
|
let filename = env::args().nth(1).expect("Must provide input filename");
|
||||||
let output_filename = format!("{}.out", filename.clone());
|
let output_filename = format!("{}.out", filename);
|
||||||
let f = File::open(filename)?;
|
let f = File::open(filename)?;
|
||||||
let in_len = f.metadata()?.len();
|
let in_len = f.metadata()?.len();
|
||||||
let mut stack = NockStack::new(1 << 10 << 10 << 10, 0);
|
let mut stack = NockStack::new(1 << 10 << 10 << 10, 0);
|
||||||
|
@ -69,7 +69,7 @@ impl<T: Copy> MutHamt<T> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
'lookup: loop {
|
'lookup: loop {
|
||||||
let chunk = mug & 0x1f;
|
let chunk = mug & 0x1f;
|
||||||
mug = mug >> 5;
|
mug >>= 5;
|
||||||
match (*stem).entry(chunk) {
|
match (*stem).entry(chunk) {
|
||||||
None => {
|
None => {
|
||||||
break None;
|
break None;
|
||||||
@ -79,8 +79,8 @@ impl<T: Copy> MutHamt<T> {
|
|||||||
}
|
}
|
||||||
Some(Right(leaf)) => {
|
Some(Right(leaf)) => {
|
||||||
for pair in leaf.to_mut_slice().iter_mut() {
|
for pair in leaf.to_mut_slice().iter_mut() {
|
||||||
if unifying_equality(stack, n, &mut (*pair).0) {
|
if unifying_equality(stack, n, &mut pair.0) {
|
||||||
break 'lookup Some((*pair).1);
|
break 'lookup Some(pair.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break None;
|
break None;
|
||||||
@ -97,13 +97,13 @@ impl<T: Copy> MutHamt<T> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
'insert: loop {
|
'insert: loop {
|
||||||
let chunk = mug & 0x1f;
|
let chunk = mug & 0x1f;
|
||||||
mug = mug >> 5;
|
mug >>= 5;
|
||||||
match (*stem).entry(chunk) {
|
match (*stem).entry(chunk) {
|
||||||
None => {
|
None => {
|
||||||
let new_leaf_buffer = stack.struct_alloc(1);
|
let new_leaf_buffer = stack.struct_alloc(1);
|
||||||
*new_leaf_buffer = (*n, t);
|
*new_leaf_buffer = (*n, t);
|
||||||
(*stem).bitmap = (*stem).bitmap | chunk_to_bit(chunk);
|
(*stem).bitmap |= chunk_to_bit(chunk);
|
||||||
(*stem).typemap = (*stem).typemap & !chunk_to_bit(chunk);
|
(*stem).typemap &= !chunk_to_bit(chunk);
|
||||||
(*stem).buffer[chunk as usize] = MutEntry {
|
(*stem).buffer[chunk as usize] = MutEntry {
|
||||||
leaf: Leaf {
|
leaf: Leaf {
|
||||||
len: 1,
|
len: 1,
|
||||||
@ -119,8 +119,8 @@ impl<T: Copy> MutHamt<T> {
|
|||||||
}
|
}
|
||||||
Some(Right(leaf)) => {
|
Some(Right(leaf)) => {
|
||||||
for pair in leaf.to_mut_slice().iter_mut() {
|
for pair in leaf.to_mut_slice().iter_mut() {
|
||||||
if unifying_equality(stack, n, &mut (*pair).0) {
|
if unifying_equality(stack, n, &mut pair.0) {
|
||||||
(*pair).1 = t;
|
pair.1 = t;
|
||||||
break 'insert;
|
break 'insert;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,9 +142,9 @@ impl<T: Copy> MutHamt<T> {
|
|||||||
let leaf_chunk = (leaf_mug >> ((depth + 1) * 5)) & 0x1f;
|
let leaf_chunk = (leaf_mug >> ((depth + 1) * 5)) & 0x1f;
|
||||||
(*new_stem).bitmap = chunk_to_bit(leaf_chunk);
|
(*new_stem).bitmap = chunk_to_bit(leaf_chunk);
|
||||||
(*new_stem).typemap = 0;
|
(*new_stem).typemap = 0;
|
||||||
(*new_stem).buffer[leaf_chunk as usize] = MutEntry { leaf: leaf };
|
(*new_stem).buffer[leaf_chunk as usize] = MutEntry { leaf };
|
||||||
(*stem).buffer[chunk as usize] = MutEntry { stem: new_stem };
|
(*stem).buffer[chunk as usize] = MutEntry { stem: new_stem };
|
||||||
(*stem).typemap = (*stem).typemap | chunk_to_bit(chunk);
|
(*stem).typemap |= chunk_to_bit(chunk);
|
||||||
stem = new_stem;
|
stem = new_stem;
|
||||||
depth += 1;
|
depth += 1;
|
||||||
continue;
|
continue;
|
||||||
@ -281,7 +281,7 @@ impl<T: Copy> Hamt<T> {
|
|||||||
let mut mug = mug_u32(stack, *n);
|
let mut mug = mug_u32(stack, *n);
|
||||||
'lookup: loop {
|
'lookup: loop {
|
||||||
let chunk = mug & 0x1F; // 5 bits
|
let chunk = mug & 0x1F; // 5 bits
|
||||||
mug = mug >> 5;
|
mug >>= 5;
|
||||||
match stem.entry(chunk) {
|
match stem.entry(chunk) {
|
||||||
None => {
|
None => {
|
||||||
break None;
|
break None;
|
||||||
@ -314,7 +314,7 @@ impl<T: Copy> Hamt<T> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
'insert: loop {
|
'insert: loop {
|
||||||
let chunk = mug & 0x1F; // 5 bits
|
let chunk = mug & 0x1F; // 5 bits
|
||||||
mug = mug >> 5;
|
mug >>= 5;
|
||||||
match stem.entry(chunk) {
|
match stem.entry(chunk) {
|
||||||
None => {
|
None => {
|
||||||
let new_leaf_buffer = stack.struct_alloc(1);
|
let new_leaf_buffer = stack.struct_alloc(1);
|
||||||
@ -399,7 +399,7 @@ impl<T: Copy> Hamt<T> {
|
|||||||
// next time around
|
// next time around
|
||||||
assert!(leaf.len == 1);
|
assert!(leaf.len == 1);
|
||||||
let fake_buffer = stack.struct_alloc(1);
|
let fake_buffer = stack.struct_alloc(1);
|
||||||
*fake_buffer = Entry { leaf: leaf };
|
*fake_buffer = Entry { leaf };
|
||||||
// get the mug chunk for the noun at *the next level* so
|
// get the mug chunk for the noun at *the next level* so
|
||||||
// we can build a fake stem for it
|
// we can build a fake stem for it
|
||||||
let fake_mug = mug_u32(stack, (*leaf.buffer).0);
|
let fake_mug = mug_u32(stack, (*leaf.buffer).0);
|
||||||
@ -430,13 +430,13 @@ impl<T: Copy> Hamt<T> {
|
|||||||
|
|
||||||
impl<T: Copy + Preserve> Preserve for Hamt<T> {
|
impl<T: Copy + Preserve> Preserve for Hamt<T> {
|
||||||
unsafe fn preserve(&mut self, stack: &mut NockStack) {
|
unsafe fn preserve(&mut self, stack: &mut NockStack) {
|
||||||
if stack.in_frame((*self).0.buffer) {
|
if stack.in_frame(self.0.buffer) {
|
||||||
let dest_buffer = stack.struct_alloc_in_previous_frame((*self).0.size());
|
let dest_buffer = stack.struct_alloc_in_previous_frame(self.0.size());
|
||||||
copy_nonoverlapping((*self).0.buffer, dest_buffer, (*self).0.size());
|
copy_nonoverlapping(self.0.buffer, dest_buffer, self.0.size());
|
||||||
(*self).0.buffer = dest_buffer;
|
self.0.buffer = dest_buffer;
|
||||||
let traversal_stack = stack.struct_alloc::<(Stem<T>, u32)>(6);
|
let traversal_stack = stack.struct_alloc::<(Stem<T>, u32)>(6);
|
||||||
let mut traversal_depth = 1;
|
let mut traversal_depth = 1;
|
||||||
*traversal_stack = ((*self).0, 0);
|
*traversal_stack = (self.0, 0);
|
||||||
'preserve: loop {
|
'preserve: loop {
|
||||||
if traversal_depth == 0 {
|
if traversal_depth == 0 {
|
||||||
break;
|
break;
|
||||||
@ -487,8 +487,8 @@ impl<T: Copy + Preserve> Preserve for Hamt<T> {
|
|||||||
buffer: dest_buffer,
|
buffer: dest_buffer,
|
||||||
};
|
};
|
||||||
for pair in new_leaf.to_mut_slice().iter_mut() {
|
for pair in new_leaf.to_mut_slice().iter_mut() {
|
||||||
(*pair).0.preserve(stack);
|
pair.0.preserve(stack);
|
||||||
(*pair).1.preserve(stack);
|
pair.1.preserve(stack);
|
||||||
}
|
}
|
||||||
*(stem.buffer.add(idx) as *mut Entry<T>) = Entry { leaf: new_leaf };
|
*(stem.buffer.add(idx) as *mut Entry<T>) = Entry { leaf: new_leaf };
|
||||||
}
|
}
|
||||||
|
@ -653,20 +653,20 @@ fn match_pre_hint(
|
|||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(jet_res);
|
Ok(jet_res)
|
||||||
} else {
|
} else {
|
||||||
// Print jet errors and punt to Nock
|
// Print jet errors and punt to Nock
|
||||||
eprintln!("\rJet {} failed", jet_name);
|
eprintln!("\rJet {} failed", jet_name);
|
||||||
return Err(());
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tas!(b"memo") => {
|
tas!(b"memo") => {
|
||||||
let formula = unsafe { *stack.local_noun_pointer(2) };
|
let formula = unsafe { *stack.local_noun_pointer(2) };
|
||||||
let mut key = Cell::new(stack, subject, formula).as_noun();
|
let mut key = Cell::new(stack, subject, formula).as_noun();
|
||||||
if let Some(res) = cache.lookup(stack, &mut key) {
|
if let Some(res) = cache.lookup(stack, &mut key) {
|
||||||
return Ok(res);
|
Ok(res)
|
||||||
} else {
|
} else {
|
||||||
return Err(());
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
@ -711,10 +711,8 @@ fn match_post_hinted(
|
|||||||
let formula = unsafe { *stack.local_noun_pointer(2) };
|
let formula = unsafe { *stack.local_noun_pointer(2) };
|
||||||
let mut key = Cell::new(stack, subject, formula).as_noun();
|
let mut key = Cell::new(stack, subject, formula).as_noun();
|
||||||
*cache = cache.insert(stack, &mut key, res);
|
*cache = cache.insert(stack, &mut key, res);
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(());
|
|
||||||
}
|
}
|
||||||
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ use bitvec::prelude::{BitSlice, Lsb0};
|
|||||||
use either::Either::*;
|
use either::Either::*;
|
||||||
use ibig::ops::DivRem;
|
use ibig::ops::DivRem;
|
||||||
use ibig::UBig;
|
use ibig::UBig;
|
||||||
use std::cmp;
|
use std::{cmp, convert::TryFrom};
|
||||||
|
|
||||||
crate::gdb!();
|
crate::gdb!();
|
||||||
|
|
||||||
@ -136,8 +136,7 @@ pub fn jet_div(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
|
|
||||||
if unsafe { b.as_noun().raw_equals(D(0)) } {
|
if unsafe { b.as_noun().raw_equals(D(0)) } {
|
||||||
Err(Deterministic)
|
Err(Deterministic)
|
||||||
} else {
|
} else if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
|
||||||
if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
|
|
||||||
Ok(unsafe { DirectAtom::new_unchecked(a.data() / b.data()) }.as_noun())
|
Ok(unsafe { DirectAtom::new_unchecked(a.data() / b.data()) }.as_noun())
|
||||||
} else {
|
} else {
|
||||||
let a_big = a.as_ubig(stack);
|
let a_big = a.as_ubig(stack);
|
||||||
@ -145,7 +144,6 @@ pub fn jet_div(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
let res = UBig::div_stack(stack, a_big, b_big);
|
let res = UBig::div_stack(stack, a_big, b_big);
|
||||||
Ok(Atom::from_ubig(stack, &res).as_noun())
|
Ok(Atom::from_ubig(stack, &res).as_noun())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn jet_mod(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
pub fn jet_mod(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
||||||
@ -155,14 +153,12 @@ pub fn jet_mod(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
|
|
||||||
if unsafe { b.as_noun().raw_equals(D(0)) } {
|
if unsafe { b.as_noun().raw_equals(D(0)) } {
|
||||||
Err(Deterministic)
|
Err(Deterministic)
|
||||||
} else {
|
} else if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
|
||||||
if let (Ok(a), Ok(b)) = (a.as_direct(), b.as_direct()) {
|
|
||||||
Ok(unsafe { DirectAtom::new_unchecked(a.data() % b.data()) }.as_noun())
|
Ok(unsafe { DirectAtom::new_unchecked(a.data() % b.data()) }.as_noun())
|
||||||
} else {
|
} else {
|
||||||
let res = a.as_ubig(stack) % b.as_ubig(stack);
|
let res = a.as_ubig(stack) % b.as_ubig(stack);
|
||||||
Ok(Atom::from_ubig(stack, &res).as_noun())
|
Ok(Atom::from_ubig(stack, &res).as_noun())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn jet_dvr(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
pub fn jet_dvr(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
||||||
@ -204,18 +200,14 @@ pub fn jet_lth(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
}
|
||||||
} else {
|
} else if a.bit_size() < b.bit_size() {
|
||||||
if a.bit_size() < b.bit_size() {
|
|
||||||
YES
|
YES
|
||||||
} else if a.bit_size() > b.bit_size() {
|
} else if a.bit_size() > b.bit_size() {
|
||||||
NO
|
NO
|
||||||
} else {
|
} else if a.as_ubig(stack) < b.as_ubig(stack) {
|
||||||
if a.as_ubig(stack) < b.as_ubig(stack) {
|
|
||||||
YES
|
YES
|
||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,18 +222,14 @@ pub fn jet_lte(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
}
|
||||||
} else {
|
} else if a.bit_size() < b.bit_size() {
|
||||||
if a.bit_size() < b.bit_size() {
|
|
||||||
YES
|
YES
|
||||||
} else if a.bit_size() > b.bit_size() {
|
} else if a.bit_size() > b.bit_size() {
|
||||||
NO
|
NO
|
||||||
} else {
|
} else if a.as_ubig(stack) <= b.as_ubig(stack) {
|
||||||
if a.as_ubig(stack) <= b.as_ubig(stack) {
|
|
||||||
YES
|
YES
|
||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,18 +244,14 @@ pub fn jet_gth(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
}
|
||||||
} else {
|
} else if a.bit_size() > b.bit_size() {
|
||||||
if a.bit_size() > b.bit_size() {
|
|
||||||
YES
|
YES
|
||||||
} else if a.bit_size() < b.bit_size() {
|
} else if a.bit_size() < b.bit_size() {
|
||||||
NO
|
NO
|
||||||
} else {
|
} else if a.as_ubig(stack) > b.as_ubig(stack) {
|
||||||
if a.as_ubig(stack) > b.as_ubig(stack) {
|
|
||||||
YES
|
YES
|
||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,18 +266,14 @@ pub fn jet_gte(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
}
|
||||||
} else {
|
} else if a.bit_size() > b.bit_size() {
|
||||||
if a.bit_size() > b.bit_size() {
|
|
||||||
YES
|
YES
|
||||||
} else if a.bit_size() < b.bit_size() {
|
} else if a.bit_size() < b.bit_size() {
|
||||||
NO
|
NO
|
||||||
} else {
|
} else if a.as_ubig(stack) >= b.as_ubig(stack) {
|
||||||
if a.as_ubig(stack) >= b.as_ubig(stack) {
|
|
||||||
YES
|
YES
|
||||||
} else {
|
} else {
|
||||||
NO
|
NO
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,7 +448,7 @@ pub fn jet_can(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
}
|
}
|
||||||
let original_list = raw_slot(arg, 3);
|
let original_list = raw_slot(arg, 3);
|
||||||
|
|
||||||
let mut len = 0 as usize;
|
let mut len = 0usize;
|
||||||
let mut list = original_list;
|
let mut list = original_list;
|
||||||
loop {
|
loop {
|
||||||
if unsafe { list.raw_equals(D(0)) } {
|
if unsafe { list.raw_equals(D(0)) } {
|
||||||
@ -477,7 +457,7 @@ pub fn jet_can(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
|
|
||||||
let cell = list.as_cell()?;
|
let cell = list.as_cell()?;
|
||||||
let item = cell.head().as_cell()?;
|
let item = cell.head().as_cell()?;
|
||||||
let step = item.head().as_direct()?.data() as usize;
|
let step = usize::try_from(item.head().as_direct()?.data()).unwrap();
|
||||||
|
|
||||||
len = len.checked_add(step).ok_or(NonDeterministic)?;
|
len = len.checked_add(step).ok_or(NonDeterministic)?;
|
||||||
list = cell.tail();
|
list = cell.tail();
|
||||||
@ -515,7 +495,7 @@ pub fn jet_rep(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
|||||||
let (bloq, step) = bite(raw_slot(arg, 2))?;
|
let (bloq, step) = bite(raw_slot(arg, 2))?;
|
||||||
let original_list = raw_slot(arg, 3);
|
let original_list = raw_slot(arg, 3);
|
||||||
|
|
||||||
let mut len = 0 as usize;
|
let mut len = 0usize;
|
||||||
let mut list = original_list;
|
let mut list = original_list;
|
||||||
loop {
|
loop {
|
||||||
if unsafe { list.raw_equals(D(0)) } {
|
if unsafe { list.raw_equals(D(0)) } {
|
||||||
@ -663,14 +643,12 @@ unsafe fn chop(
|
|||||||
pub fn met(bloq: usize, a: Atom) -> usize {
|
pub fn met(bloq: usize, a: Atom) -> usize {
|
||||||
if unsafe { a.as_noun().raw_equals(D(0)) } {
|
if unsafe { a.as_noun().raw_equals(D(0)) } {
|
||||||
0
|
0
|
||||||
} else {
|
} else if bloq < 6 {
|
||||||
if bloq < 6 {
|
|
||||||
(a.bit_size() + ((1 << bloq) - 1)) >> bloq
|
(a.bit_size() + ((1 << bloq) - 1)) >> bloq
|
||||||
} else {
|
} else {
|
||||||
let bloq_word = bloq - 6;
|
let bloq_word = bloq - 6;
|
||||||
(a.size() + ((1 << bloq_word) - 1)) >> bloq_word
|
(a.size() + ((1 << bloq_word) - 1)) >> bloq_word
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -33,7 +33,7 @@ fn main() -> io::Result<()> {
|
|||||||
return serf();
|
return serf();
|
||||||
}
|
}
|
||||||
|
|
||||||
let output_filename = format!("{}.out", filename.clone());
|
let output_filename = format!("{}.out", filename);
|
||||||
let f = File::open(filename)?;
|
let f = File::open(filename)?;
|
||||||
let in_len = f.metadata()?.len();
|
let in_len = f.metadata()?.len();
|
||||||
let mut stack = NockStack::new(8 << 10 << 10, 0);
|
let mut stack = NockStack::new(8 << 10 << 10, 0);
|
||||||
|
@ -98,12 +98,12 @@ impl NockStack {
|
|||||||
*frame_pointer.add(1) = ptr::null::<u64>() as u64;
|
*frame_pointer.add(1) = ptr::null::<u64>() as u64;
|
||||||
};
|
};
|
||||||
NockStack {
|
NockStack {
|
||||||
start: start,
|
start,
|
||||||
size: size,
|
size,
|
||||||
polarity: Polarity::West,
|
polarity: Polarity::West,
|
||||||
stack_pointer: stack_pointer,
|
stack_pointer,
|
||||||
frame_pointer: frame_pointer,
|
frame_pointer,
|
||||||
memory: memory,
|
memory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ impl Newt {
|
|||||||
fn write_noun(&mut self, stack: &mut NockStack, noun: Noun) {
|
fn write_noun(&mut self, stack: &mut NockStack, noun: Noun) {
|
||||||
let atom = jam(stack, noun);
|
let atom = jam(stack, noun);
|
||||||
let size = atom.size() << 3;
|
let size = atom.size() << 3;
|
||||||
let mut buf = vec![0 as u8; size + 5];
|
let mut buf = vec![0u8; size + 5];
|
||||||
buf[1] = size as u8;
|
buf[1] = size as u8;
|
||||||
buf[2] = (size >> 8) as u8;
|
buf[2] = (size >> 8) as u8;
|
||||||
buf[3] = (size >> 16) as u8;
|
buf[3] = (size >> 16) as u8;
|
||||||
@ -192,8 +192,7 @@ impl Newt {
|
|||||||
|
|
||||||
/** Fetch next message. */
|
/** Fetch next message. */
|
||||||
pub fn next(&mut self, stack: &mut NockStack) -> Option<Noun> {
|
pub fn next(&mut self, stack: &mut NockStack) -> Option<Noun> {
|
||||||
let mut header: Vec<u8> = Vec::with_capacity(5);
|
let mut header: Vec<u8> = vec![0; 5];
|
||||||
header.resize(5, 0);
|
|
||||||
if let Err(err) = self.input.read_exact(&mut header) {
|
if let Err(err) = self.input.read_exact(&mut header) {
|
||||||
if err.kind() == std::io::ErrorKind::UnexpectedEof {
|
if err.kind() == std::io::ErrorKind::UnexpectedEof {
|
||||||
return None;
|
return None;
|
||||||
|
@ -63,7 +63,7 @@ fn acyclic_noun_go(noun: Noun, seen: &mut IntMap<()>) -> bool {
|
|||||||
match noun.as_either_atom_cell() {
|
match noun.as_either_atom_cell() {
|
||||||
Either::Left(_atom) => true,
|
Either::Left(_atom) => true,
|
||||||
Either::Right(cell) => {
|
Either::Right(cell) => {
|
||||||
if let Some(_) = seen.get(cell.0) {
|
if seen.get(cell.0).is_some() {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
seen.insert(cell.0, ());
|
seen.insert(cell.0, ());
|
||||||
@ -155,8 +155,8 @@ impl DirectAtom {
|
|||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bitslice<'a>(&'a self) -> &'a BitSlice<u64, Lsb0> {
|
pub fn as_bitslice(&self) -> &BitSlice<u64, Lsb0> {
|
||||||
&(BitSlice::from_element(&self.0))
|
BitSlice::from_element(&self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,16 +345,16 @@ impl IndirectAtom {
|
|||||||
unsafe { self.to_raw_pointer().add(2) as *const u64 }
|
unsafe { self.to_raw_pointer().add(2) as *const u64 }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_slice<'a>(&'a self) -> &'a [u64] {
|
pub fn as_slice(&self) -> &[u64] {
|
||||||
unsafe { from_raw_parts(self.data_pointer(), self.size()) }
|
unsafe { from_raw_parts(self.data_pointer(), self.size()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
unsafe { from_raw_parts(self.data_pointer() as *const u8, self.size() << 3) }
|
unsafe { from_raw_parts(self.data_pointer() as *const u8, self.size() << 3) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** BitSlice view on an indirect atom, with lifetime tied to reference to indirect atom. */
|
/** BitSlice view on an indirect atom, with lifetime tied to reference to indirect atom. */
|
||||||
pub fn as_bitslice<'a>(&'a self) -> &'a BitSlice<u64, Lsb0> {
|
pub fn as_bitslice(&self) -> &BitSlice<u64, Lsb0> {
|
||||||
BitSlice::from_slice(self.as_slice())
|
BitSlice::from_slice(self.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,11 +617,11 @@ impl Atom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bitslice<'a>(&'a self) -> &'a BitSlice<u64, Lsb0> {
|
pub fn as_bitslice(&self) -> &BitSlice<u64, Lsb0> {
|
||||||
if self.is_indirect() {
|
if self.is_indirect() {
|
||||||
unsafe { self.indirect.as_bitslice() }
|
unsafe { self.indirect.as_bitslice() }
|
||||||
} else {
|
} else {
|
||||||
unsafe { &(self.direct.as_bitslice()) }
|
unsafe { self.direct.as_bitslice() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,7 +843,7 @@ impl Noun {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn from_raw(raw: u64) -> Noun {
|
pub unsafe fn from_raw(raw: u64) -> Noun {
|
||||||
Noun { raw: raw }
|
Noun { raw }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Produce the total size of a noun, in words
|
/** Produce the total size of a noun, in words
|
||||||
|
@ -31,8 +31,8 @@ pub fn serf() -> io::Result<()> {
|
|||||||
snap_path.push("chk");
|
snap_path.push("chk");
|
||||||
create_dir_all(&snap_path)?;
|
create_dir_all(&snap_path)?;
|
||||||
|
|
||||||
let ref mut stack = NockStack::new(96 << 10 << 10, 0);
|
let stack = &mut NockStack::new(96 << 10 << 10, 0);
|
||||||
let ref mut newt = Newt::new();
|
let newt = &mut Newt::new();
|
||||||
let mut event_number;
|
let mut event_number;
|
||||||
let mut arvo;
|
let mut arvo;
|
||||||
|
|
||||||
@ -42,13 +42,7 @@ pub fn serf() -> io::Result<()> {
|
|||||||
newt.ripe(stack, event_number, mug as u64);
|
newt.ripe(stack, event_number, mug as u64);
|
||||||
|
|
||||||
// Can't use for loop because it borrows newt
|
// Can't use for loop because it borrows newt
|
||||||
loop {
|
while let Some(writ) = newt.next(stack) {
|
||||||
let writ = if let Some(writ) = newt.next(stack) {
|
|
||||||
writ
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
let tag = raw_slot(writ, 2).as_direct().unwrap();
|
let tag = raw_slot(writ, 2).as_direct().unwrap();
|
||||||
match tag.data() {
|
match tag.data() {
|
||||||
tas!(b"live") => {
|
tas!(b"live") => {
|
||||||
@ -89,8 +83,7 @@ pub fn serf() -> io::Result<()> {
|
|||||||
// event_number = raw_slot(writ, 6).as_direct().unwrap().data();
|
// event_number = raw_slot(writ, 6).as_direct().unwrap().data();
|
||||||
|
|
||||||
let mut lit = raw_slot(writ, 7);
|
let mut lit = raw_slot(writ, 7);
|
||||||
loop {
|
while let Ok(cell) = lit.as_cell() {
|
||||||
if let Ok(cell) = lit.as_cell() {
|
|
||||||
if run {
|
if run {
|
||||||
let ovo = cell.head();
|
let ovo = cell.head();
|
||||||
let res = slam(stack, newt, arvo, POKE_AXIS, ovo).as_cell().unwrap();
|
let res = slam(stack, newt, arvo, POKE_AXIS, ovo).as_cell().unwrap();
|
||||||
@ -98,9 +91,6 @@ pub fn serf() -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
event_number += 1;
|
event_number += 1;
|
||||||
lit = cell.tail();
|
lit = cell.tail();
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
newt.play_done(stack, 0);
|
newt.play_done(stack, 0);
|
||||||
}
|
}
|
||||||
|
@ -168,9 +168,9 @@ pub fn jam(stack: &mut NockStack, noun: Noun) -> Atom {
|
|||||||
let (atom, slice) = unsafe { IndirectAtom::new_raw_mut_bitslice(stack, size) };
|
let (atom, slice) = unsafe { IndirectAtom::new_raw_mut_bitslice(stack, size) };
|
||||||
let mut state = JamState {
|
let mut state = JamState {
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
size: size,
|
size,
|
||||||
atom: atom,
|
atom,
|
||||||
slice: slice,
|
slice,
|
||||||
};
|
};
|
||||||
stack.push(1);
|
stack.push(1);
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -97,7 +97,7 @@ fn latest_snapshot(
|
|||||||
snap_path: PathBuf,
|
snap_path: PathBuf,
|
||||||
) -> io::Result<(u8, u64, IndirectAtom)> {
|
) -> io::Result<(u8, u64, IndirectAtom)> {
|
||||||
let res0 = load_snapshot(stack, snap_path.clone(), 0);
|
let res0 = load_snapshot(stack, snap_path.clone(), 0);
|
||||||
let res1 = load_snapshot(stack, snap_path.clone(), 1);
|
let res1 = load_snapshot(stack, snap_path, 1);
|
||||||
|
|
||||||
match (res0, res1) {
|
match (res0, res1) {
|
||||||
(Ok((event_number_0, state_0)), Ok((event_number_1, state_1))) => {
|
(Ok((event_number_0, state_0)), Ok((event_number_1, state_1))) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user