mirror of
https://github.com/urbit/ares.git
synced 2024-12-24 13:55:23 +03:00
interpreter: formatting
This commit is contained in:
parent
8d783d0b39
commit
4e292b88a0
@ -434,47 +434,47 @@ impl<T: Copy + Preserve> Default for Hamt<T> {
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
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;
|
||||
traversal_stack[traversal_depth] = Some((next_stem, 0));
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
|
@ -1,14 +1,14 @@
|
||||
use crate::hamt::Hamt;
|
||||
use crate::jets;
|
||||
use crate::jets::cold::Cold;
|
||||
use crate::jets::warm::Warm;
|
||||
use crate::jets::hot::Hot;
|
||||
use crate::jets::warm::Warm;
|
||||
use crate::mem::unifying_equality;
|
||||
use crate::mem::NockStack;
|
||||
use crate::newt::Newt;
|
||||
use crate::noun::{Atom, Cell, DirectAtom, IndirectAtom, Noun, D, T};
|
||||
use ares_macros::tas;
|
||||
use assert_no_alloc::{assert_no_alloc};
|
||||
use assert_no_alloc::assert_no_alloc;
|
||||
use bitvec::prelude::{BitSlice, Lsb0};
|
||||
use either::Either::*;
|
||||
|
||||
@ -311,8 +311,10 @@ pub fn interpret(
|
||||
push_formula(stack, vale.formula, false);
|
||||
}
|
||||
Todo2::ComputeResult => {
|
||||
if let Some(jet) = warm.find_jet(stack, &mut vale.subject, &mut res) { // a jet match
|
||||
if let Ok(jet_res) = jet(stack, vale.subject) { // XX TODO: nondeterministic errors
|
||||
if let Some(jet) = warm.find_jet(stack, &mut vale.subject, &mut res) {
|
||||
// a jet match
|
||||
if let Ok(jet_res) = jet(stack, vale.subject) {
|
||||
// XX TODO: nondeterministic errors
|
||||
res = jet_res;
|
||||
stack.pop::<NockWork>();
|
||||
continue;
|
||||
@ -461,8 +463,10 @@ pub fn interpret(
|
||||
}
|
||||
Todo9::ComputeResult => {
|
||||
let mut formula = slot(res, kale.axis.as_bitslice());
|
||||
if let Some(jet) = warm.find_jet(stack, &mut res, &mut formula) { // a jet match
|
||||
if let Ok(jet_res) = jet(stack, res) { // XX TODO: nondeterministic errors
|
||||
if let Some(jet) = warm.find_jet(stack, &mut res, &mut formula) {
|
||||
// a jet match
|
||||
if let Ok(jet_res) = jet(stack, res) {
|
||||
// XX TODO: nondeterministic errors
|
||||
res = jet_res;
|
||||
stack.pop::<NockWork>();
|
||||
continue;
|
||||
@ -534,7 +538,9 @@ pub fn interpret(
|
||||
}
|
||||
Todo11D::Done => {
|
||||
let hint = Cell::new(stack, dint.tag.as_noun(), dint.hint).as_noun();
|
||||
let _ = match_post_hinted(stack, subject, hint, res, &mut cache, cold, warm, hot);
|
||||
let _ = match_post_hinted(
|
||||
stack, subject, hint, res, &mut cache, cold, warm, hot,
|
||||
);
|
||||
stack.pop::<NockWork>();
|
||||
}
|
||||
},
|
||||
@ -553,8 +559,16 @@ pub fn interpret(
|
||||
}
|
||||
}
|
||||
Todo11S::Done => {
|
||||
let _ =
|
||||
match_post_hinted(stack, subject, sint.tag.as_noun(), res, &mut cache, cold, warm, hot);
|
||||
let _ = match_post_hinted(
|
||||
stack,
|
||||
subject,
|
||||
sint.tag.as_noun(),
|
||||
res,
|
||||
&mut cache,
|
||||
cold,
|
||||
warm,
|
||||
hot,
|
||||
);
|
||||
stack.pop::<NockWork>();
|
||||
}
|
||||
},
|
||||
@ -931,7 +945,7 @@ fn match_post_hinted(
|
||||
cache: &mut Hamt<Noun>,
|
||||
cold: &mut Cold,
|
||||
warm: &mut Warm,
|
||||
hot: Hot
|
||||
hot: Hot,
|
||||
) -> Result<(), ()> {
|
||||
let direct = hint.as_cell()?.head().as_direct()?;
|
||||
match direct.data() {
|
||||
@ -940,7 +954,7 @@ fn match_post_hinted(
|
||||
let mut key = Cell::new(stack, subject, formula).as_noun();
|
||||
*cache = cache.insert(stack, &mut key, res);
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
tas!(b"fast") => {
|
||||
let clue = raw_slot_result(hint, 7)?;
|
||||
let chum = raw_slot_result(clue, 2)?;
|
||||
@ -948,15 +962,19 @@ fn match_post_hinted(
|
||||
let parent_formula_ax = raw_slot_result(clue, 13)?.as_atom()?;
|
||||
if parent_formula_op.data() == 1 {
|
||||
if parent_formula_ax.as_direct()?.data() == 0 {
|
||||
let changed = cold.register(stack, res, parent_formula_ax, chum)?;
|
||||
if changed { *warm = Warm::init(stack, cold, hot); }
|
||||
Ok(())
|
||||
let changed = cold.register(stack, res, parent_formula_ax, chum)?;
|
||||
if changed {
|
||||
*warm = Warm::init(stack, cold, hot);
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
} else {
|
||||
let changed = cold.register(stack, res, parent_formula_ax, chum)?;
|
||||
if changed { *warm = Warm::init(stack, cold, hot); }
|
||||
if changed {
|
||||
*warm = Warm::init(stack, cold, hot);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ impl Preserve for Batteries {
|
||||
break;
|
||||
};
|
||||
cursor = (*cursor.0).parent_batteries;
|
||||
};
|
||||
}
|
||||
}
|
||||
unsafe fn preserve(&mut self, stack: &mut NockStack) {
|
||||
if self.0.is_null() {
|
||||
@ -130,7 +130,6 @@ impl Preserve for BatteriesList {
|
||||
};
|
||||
cursor = (*cursor.0).next;
|
||||
}
|
||||
|
||||
}
|
||||
unsafe fn preserve(&mut self, stack: &mut NockStack) {
|
||||
if self.0.is_null() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use ares::interpreter::interpret;
|
||||
use ares::jets::cold::Cold;
|
||||
use ares::jets::warm::Warm;
|
||||
use ares::jets::hot::Hot;
|
||||
use ares::jets::warm::Warm;
|
||||
use ares::mem::NockStack;
|
||||
use ares::noun::IndirectAtom;
|
||||
use ares::serf::serf;
|
||||
@ -58,7 +58,15 @@ fn main() -> io::Result<()> {
|
||||
let input_cell = input
|
||||
.as_cell()
|
||||
.expect("Input must be jam of subject/formula pair");
|
||||
let result = interpret(&mut stack, &mut None, &mut cold, &mut warm, hot, input_cell.head(), input_cell.tail());
|
||||
let result = interpret(
|
||||
&mut stack,
|
||||
&mut None,
|
||||
&mut cold,
|
||||
&mut warm,
|
||||
hot,
|
||||
input_cell.head(),
|
||||
input_cell.tail(),
|
||||
);
|
||||
if let Ok(atom) = result.as_atom() {
|
||||
println!("Result: {}", atom);
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ impl NockStack {
|
||||
assert_acyclic!(*noun);
|
||||
}
|
||||
|
||||
pub unsafe fn struct_is_in<T>(&self, ptr: *const T, count: usize ) {
|
||||
pub unsafe fn struct_is_in<T>(&self, ptr: *const T, count: usize) {
|
||||
let ap = (if self.pc {
|
||||
*(self.prev_alloc_pointer_pointer())
|
||||
} else {
|
||||
@ -458,7 +458,13 @@ impl NockStack {
|
||||
} else if (ptr as usize) >= hi && (ptr.add(count) as usize) > hi {
|
||||
return;
|
||||
}
|
||||
panic!("Use after free: allocation from {:#x} to {:#x}, free space from {:#x} to {:#x}", ptr as usize, ptr.add(count) as usize, low, hi);
|
||||
panic!(
|
||||
"Use after free: allocation from {:#x} to {:#x}, free space from {:#x} to {:#x}",
|
||||
ptr as usize,
|
||||
ptr.add(count) as usize,
|
||||
low,
|
||||
hi
|
||||
);
|
||||
}
|
||||
|
||||
unsafe fn noun_in(&self, noun: Noun) {
|
||||
@ -480,7 +486,7 @@ impl NockStack {
|
||||
if let Ok(a) = subnoun.as_allocated() {
|
||||
let np = a.to_raw_pointer() as usize;
|
||||
if np >= low && np < hi {
|
||||
panic!("noun not in {:?}: {:?}", (low,hi), subnoun);
|
||||
panic!("noun not in {:?}: {:?}", (low, hi), subnoun);
|
||||
}
|
||||
if let Right(c) = a.as_either() {
|
||||
dbg_stack.push(c.tail());
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::interpreter::{interpret, raw_slot};
|
||||
use crate::jets::cold::Cold;
|
||||
use crate::jets::warm::Warm;
|
||||
use crate::jets::hot::Hot;
|
||||
use crate::jets::warm::Warm;
|
||||
use crate::mem::NockStack;
|
||||
use crate::mug::mug_u32;
|
||||
use crate::newt::Newt;
|
||||
@ -82,7 +82,8 @@ pub fn serf() -> io::Result<()> {
|
||||
let lit = raw_slot(writ, 7);
|
||||
let sub = T(stack, &[D(0), D(3)]);
|
||||
let lyf = T(stack, &[D(2), sub, D(0), D(2)]);
|
||||
let gat = interpret(stack, &mut Some(newt), &mut cold, &mut warm, hot, lit, lyf);
|
||||
let gat =
|
||||
interpret(stack, &mut Some(newt), &mut cold, &mut warm, hot, lit, lyf);
|
||||
arvo = raw_slot(gat, 7);
|
||||
false
|
||||
} else {
|
||||
@ -96,7 +97,10 @@ pub fn serf() -> io::Result<()> {
|
||||
while let Ok(cell) = lit.as_cell() {
|
||||
if run {
|
||||
let ovo = cell.head();
|
||||
let res = slam(stack, newt, &mut cold, &mut warm, hot, arvo, POKE_AXIS, ovo).as_cell().unwrap();
|
||||
let res =
|
||||
slam(stack, newt, &mut cold, &mut warm, hot, arvo, POKE_AXIS, ovo)
|
||||
.as_cell()
|
||||
.unwrap();
|
||||
arvo = res.tail();
|
||||
}
|
||||
event_number += 1;
|
||||
@ -108,7 +112,9 @@ pub fn serf() -> io::Result<()> {
|
||||
}
|
||||
tas!(b"work") => {
|
||||
let ovo = raw_slot(writ, 7);
|
||||
let res = slam(stack, newt, &mut cold, &mut warm, hot, arvo, POKE_AXIS, ovo).as_cell().unwrap();
|
||||
let res = slam(stack, newt, &mut cold, &mut warm, hot, arvo, POKE_AXIS, ovo)
|
||||
.as_cell()
|
||||
.unwrap();
|
||||
let fec = res.head();
|
||||
arvo = res.tail();
|
||||
snap.save(stack, &mut arvo);
|
||||
@ -124,7 +130,16 @@ pub fn serf() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn slam(stack: &mut NockStack, newt: &mut Newt, cold: &mut Cold, warm: &mut Warm, hot: Hot, core: Noun, axis: u64, ovo: Noun) -> Noun {
|
||||
pub fn slam(
|
||||
stack: &mut NockStack,
|
||||
newt: &mut Newt,
|
||||
cold: &mut Cold,
|
||||
warm: &mut Warm,
|
||||
hot: Hot,
|
||||
core: Noun,
|
||||
axis: u64,
|
||||
ovo: Noun,
|
||||
) -> Noun {
|
||||
let pul = T(stack, &[D(9), D(axis), D(0), D(2)]);
|
||||
let sam = T(stack, &[D(6), D(0), D(7)]);
|
||||
let fol = T(stack, &[D(8), pul, D(9), D(2), D(10), sam, D(0), D(2)]);
|
||||
|
Loading…
Reference in New Issue
Block a user