Skip to content

Commit

Permalink
Fix builder concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 2, 2023
1 parent 8091028 commit c4283bb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl<'a> Context<'a> {
pub fn run(&mut self) -> Result<u8> {
let mut current = Some(Rc::new(cont::InterpreterCont) as Cont);
while let Some(cont) = current.take() {
//eprintln!(" >>> {}", cont.display_name(&self.dictionary));
current = cont.run(self)?;
if current.is_none() {
current = self.next.take();
Expand Down
15 changes: 9 additions & 6 deletions src/core/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use num_bigint::BigInt;
use num_traits::{One, ToPrimitive, Zero};

use super::cont::*;
use crate::util::DisplaySliceExt;

pub struct Stack {
items: Vec<Box<dyn StackValue>>,
Expand Down Expand Up @@ -56,6 +57,7 @@ impl Stack {
anyhow::ensure!(lhs < len, StackError::StackUnderflow(lhs));
anyhow::ensure!(rhs < len, StackError::StackUnderflow(rhs));
self.items.swap(len - lhs - 1, len - rhs - 1);
//eprintln!("AFTER SWAP: {}", self.display_dump());
Ok(())
}

Expand All @@ -72,6 +74,7 @@ impl Stack {
*capacity += 1;
}
self.items.push(item);
//eprintln!("AFTER PUSH: {}", self.display_dump());
Ok(())
}

Expand All @@ -93,6 +96,7 @@ impl Stack {
}

pub fn pop(&mut self) -> Result<Box<dyn StackValue>> {
//eprintln!("BEFORE POP: {}", self.display_dump());
self.items
.pop()
.ok_or(StackError::StackUnderflow(0))
Expand Down Expand Up @@ -337,18 +341,17 @@ define_stack_value! {
&& a.raw_data() == b.raw_data()
&& a.references() == b.references()
},
fmt_dump(_v, f) = {
// TODO: print builder data as hex
f.write_str("BC{_data_}")
fmt_dump(v, f) = {
let bytes = (v.bit_len() + 7) / 8;
write!(f, "BC{{{}, bits={}}}", hex::encode(&v.raw_data()[..bytes as usize]), v.bit_len())
},
as_builder(v): CellBuilder = Ok(v),
into_builder,
},
Slice(OwnedCellSlice) = {
eq(a, b) = are_cell_slice_equal(a.pin(), b).unwrap_or_default(),
fmt_dump(_v, f) = {
// TODO: print slice data as hex
f.write_str("CS{_data_}")
fmt_dump(v, f) = {
write!(f, "CS{{{}}}", v.pin().display_slice_data())
},
as_slice(v): CellSlice = Ok(v.pin()),
into_slice,
Expand Down
3 changes: 1 addition & 2 deletions src/modules/cell_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl CellUtils {
fn interpret_concat_builders(stack: &mut Stack) -> Result<()> {
let cb2 = stack.pop_builder()?;
let mut cb1 = stack.pop_builder()?;
cb1.store_raw(cb2.raw_data(), cb1.bit_len())?;
cb1.store_raw(cb2.raw_data(), cb2.bit_len())?;
for cell in cb2.references() {
cb1.store_reference(cell.clone())?;
}
Expand Down Expand Up @@ -218,7 +218,6 @@ impl CellUtils {
} else {
BigInt::from_bytes_be(Sign::Plus, buffer)
};
println!("INT: {int}");
int >>= align;
int
})
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl std::fmt::Display for DisplaySliceData<'_, '_> {
append_tag(&mut buffer, bits);

let mut result = hex::encode(&buffer[..(bits as usize + 7) / 8]);
if bits % 8 <= 4 {
if (1..=4).contains(&(bits % 8)) {
result.pop();
}
if bits % 4 != 0 {
Expand Down

0 comments on commit c4283bb

Please sign in to comment.