mirror of
https://github.com/urbit/ares.git
synced 2024-12-24 13:55:23 +03:00
Simplify code and tests
This commit is contained in:
parent
0228c4e300
commit
5c34632f5f
@ -350,31 +350,9 @@ 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()?;
|
||||
|
||||
let syz = util::met(0, a) as u64;
|
||||
|
||||
unsafe { Ok(DirectAtom::new_unchecked(syz).as_atom().as_noun()) }
|
||||
Ok(D(util::met(0, a) as u64))
|
||||
}
|
||||
|
||||
// return u3kc_rep(u3k(a), 1, u3kb_flop(u3qc_rip(a, 1, b)));
|
||||
// TODO
|
||||
// allocate new IndirectAtom of same size and as_bitslice()
|
||||
// so we can rebuild it back to front in bloq size
|
||||
/*pub fn jet_swp(context: &mut Context, subject: Noun) -> Result {
|
||||
let sam = slot(subject, 6)?;
|
||||
let bloq = slot(sam, 2)?.as_atom()?.as_direct()?.data() as usize;
|
||||
let atom = slot(sam, 3)?.as_atom()?;
|
||||
|
||||
let ripper = rip(context.stack, bloq, 1, atom)?;
|
||||
//println!("ripper: {:?}", ripper);
|
||||
let flopper = flop(context.stack, ripper)?;
|
||||
//println!("flopper: {:?}", flopper);
|
||||
let sample = T(context.stack, &[D(1), flopper]);
|
||||
//println!("sample: {:?}", sample);
|
||||
//println!("sample: {:?}", jet_rep(context, sample));
|
||||
jet_rep(context, sample)
|
||||
}*/
|
||||
|
||||
pub mod util {
|
||||
use crate::jets::util::*;
|
||||
use crate::jets::Result;
|
||||
@ -875,26 +853,11 @@ mod tests {
|
||||
fn test_xeb() {
|
||||
let c = &mut init_context();
|
||||
|
||||
assert_jet(c, jet_xeb, D(0), D(0));
|
||||
assert_jet(c, jet_xeb, D(1), D(1));
|
||||
assert_jet(c, jet_xeb, D(31), D(5));
|
||||
assert_jet(c, jet_xeb, D(32), D(6));
|
||||
assert_jet(c, jet_xeb, D(0xfff), D(12));
|
||||
assert_jet(c, jet_xeb, D(0xffff), D(16));
|
||||
assert_jet(c, jet_xeb, D(0x3fffffffffffffff), D(62));
|
||||
assert_jet(c, jet_xeb, D(0x4000000000000000), D(63));
|
||||
let (a0, a24, a63, a96, a128) = atoms(&mut c.stack);
|
||||
assert_jet(c, jet_xeb, a0, D(0));
|
||||
assert_jet(c, jet_xeb, a24, D(24));
|
||||
assert_jet(c, jet_xeb, a63, D(63));
|
||||
assert_jet(c, jet_xeb, a96, D(96));
|
||||
assert_jet(c, jet_xeb, a128, D(128));
|
||||
}
|
||||
|
||||
/*#[test]
|
||||
fn test_swp() {
|
||||
let s = &mut init_stack();
|
||||
let sam = T(s, &[D(1), D(0x18)]);
|
||||
assert_jet(s, jet_swp, sam, D(0x9));
|
||||
let sam = T(s, &[D(0), D(0x18)]);
|
||||
assert_jet(s, jet_swp, sam, D(0x3));
|
||||
let sam = T(s, &[D(0), D(0x80)]);
|
||||
assert_jet(s, jet_swp, sam, D(0x1));
|
||||
let sam = T(s, &[D(3), D(0x636261)]);
|
||||
assert_jet(s, jet_swp, sam, D(0x616263));
|
||||
}*/
|
||||
}
|
||||
|
@ -10,12 +10,6 @@ crate::gdb!();
|
||||
pub fn jet_flop(context: &mut Context, subject: Noun) -> Result {
|
||||
let sam = slot(subject, 6)?;
|
||||
let src = slot(sam, 1)?;
|
||||
|
||||
if unsafe { src.raw_equals(D(0)) } {
|
||||
return Ok(D(0));
|
||||
}
|
||||
|
||||
// util::flop(&mut context.stack, src).map_err(|x| x.into())
|
||||
Ok(util::flop(&mut context.stack, src)?)
|
||||
}
|
||||
|
||||
@ -28,7 +22,7 @@ pub mod util {
|
||||
use crate::interpreter::Error;
|
||||
use crate::jets::JetErr;
|
||||
use crate::mem::NockStack;
|
||||
use crate::noun::{Cell, Noun, D};
|
||||
use crate::noun::{Noun, D, T};
|
||||
use std::result::Result;
|
||||
|
||||
/// Reverse order of list
|
||||
@ -36,15 +30,12 @@ pub mod util {
|
||||
let mut list = noun;
|
||||
let mut tsil = D(0);
|
||||
loop {
|
||||
if let Some(list) = list.atom() {
|
||||
if list.as_bitslice().first_one().is_none() {
|
||||
break;
|
||||
} else {
|
||||
return Err(Error::Deterministic(D(0)));
|
||||
}
|
||||
if unsafe { list.raw_equals(D(0)) } {
|
||||
break;
|
||||
}
|
||||
|
||||
let cell = list.as_cell()?;
|
||||
tsil = Cell::new(stack, cell.head(), tsil).as_noun();
|
||||
tsil = T(stack, &[cell.head(), tsil]);
|
||||
list = cell.tail();
|
||||
}
|
||||
|
||||
@ -110,6 +101,10 @@ mod tests {
|
||||
],
|
||||
);
|
||||
assert_jet(c, jet_flop, sam, res);
|
||||
|
||||
assert_jet_err(c, jet_flop, D(1), JetErr::Fail(Error::Deterministic(D(0))));
|
||||
let sam = T(&mut c.stack, &[D(1), D(2), D(3)]);
|
||||
assert_jet_err(c, jet_flop, sam, JetErr::Fail(Error::Deterministic(D(0))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user