mirror of
https://github.com/urbit/ares.git
synced 2024-11-26 09:57:56 +03:00
[jets] add rsh jet
This commit is contained in:
parent
89e7d612f8
commit
dec93b9ed8
@ -40,6 +40,7 @@ pub fn get_jet(jet_name: Noun) -> Result<Jet, ()> {
|
||||
tas!(b"gte") => Ok(jet_gte),
|
||||
tas!(b"bex") => Ok(jet_bex),
|
||||
tas!(b"lsh") => Ok(jet_lsh),
|
||||
tas!(b"rsh") => Ok(jet_rsh),
|
||||
tas!(b"cut") => Ok(jet_cut),
|
||||
tas!(b"mug") => Ok(jet_mug),
|
||||
_ => {
|
||||
@ -52,6 +53,7 @@ pub fn get_jet(jet_name: Noun) -> Result<Jet, ()> {
|
||||
pub fn get_jet_test_mode(jet_name: Noun) -> bool {
|
||||
match jet_name.as_direct().unwrap().data() {
|
||||
tas!(b"cut") => true,
|
||||
tas!(b"rsh") => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -327,6 +327,7 @@ pub fn jet_lsh(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
||||
let step = step.as_direct()?.data() as usize;
|
||||
let a = raw_slot(arg, 3).as_atom()?;
|
||||
|
||||
// TODO: need to assert step << bloq doesn't overflow?
|
||||
let len = met(bloq, a);
|
||||
let new_size = (a
|
||||
.bit_size()
|
||||
@ -347,6 +348,37 @@ pub fn jet_lsh(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn jet_rsh(stack: &mut NockStack, subject: Noun) -> Result<Noun, JetErr> {
|
||||
let arg = raw_slot(subject, 6);
|
||||
let (bloq, step) = bite(raw_slot(arg, 2))?;
|
||||
let bloq = bloq.as_direct()?.data() as usize;
|
||||
if bloq >= 64 {
|
||||
return Err(Deterministic);
|
||||
}
|
||||
let step = step.as_direct()?.data() as usize;
|
||||
let a = raw_slot(arg, 3).as_atom()?;
|
||||
|
||||
let len = met(bloq, a);
|
||||
if step >= len {
|
||||
return Ok(D(0));
|
||||
}
|
||||
|
||||
// TODO: need to assert step << bloq doesn't overflow?
|
||||
let new_size = (a
|
||||
.bit_size()
|
||||
.checked_sub(step << bloq)
|
||||
.ok_or(NonDeterministic)?
|
||||
.checked_add(63)
|
||||
.ok_or(NonDeterministic)?)
|
||||
>> 6;
|
||||
|
||||
unsafe {
|
||||
let (mut atom, dest) = IndirectAtom::new_raw_mut_bitslice(stack, new_size);
|
||||
chop(bloq, step, len - step, 0, dest, a.as_bitslice())?;
|
||||
Ok(atom.normalize_as_atom().as_noun())
|
||||
}
|
||||
}
|
||||
|
||||
/** Extract the bloq and step from a bite */
|
||||
fn bite(a: Noun) -> Result<(Atom, Atom), ()> {
|
||||
if let Ok(cell) = a.as_cell() {
|
||||
|
Loading…
Reference in New Issue
Block a user