Skip to content

Commit eaa02d0

Browse files
committed
bit_machine: rename private new/move/drop methods and variants
There are three basic operations on the frame stack in the bit machine: creating a new write frame, popping the write stack onto the read stack, and dropping a read frame. Our code uses shorthand like "new_frame" and "drop_frame" which makes it easy to forget which stacks these operations are operating on. This makes it harder to understand the code for somebody who doesn't currently have the bit machine algorithm loaded into their head. Rename to make stuff easier to follow.
1 parent 228a85f commit eaa02d0

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

src/bit_machine/mod.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl BitMachine {
7474
}
7575

7676
/// Push a new frame of given size onto the write frame stack
77-
fn new_frame(&mut self, len: usize) {
77+
fn new_write_frame(&mut self, len: usize) {
7878
debug_assert!(
7979
self.next_frame_start + len <= self.data.len() * 8,
8080
"Data out of bounds: number of cells"
@@ -89,14 +89,14 @@ impl BitMachine {
8989
}
9090

9191
/// Move the active write frame to the read frame stack
92-
fn move_frame(&mut self) {
92+
fn move_write_frame_to_read(&mut self) {
9393
let mut _active_write_frame = self.write.pop().unwrap();
9494
_active_write_frame.reset_cursor();
9595
self.read.push(_active_write_frame);
9696
}
9797

9898
/// Drop the active read frame
99-
fn drop_frame(&mut self) {
99+
fn drop_read_frame(&mut self) {
100100
let active_read_frame = self.read.pop().unwrap();
101101
self.next_frame_start -= active_read_frame.bit_width();
102102
assert_eq!(self.next_frame_start, active_read_frame.start());
@@ -206,9 +206,9 @@ impl BitMachine {
206206
}
207207
// Unit value doesn't need extra frame
208208
if !input.is_empty() {
209-
self.new_frame(input.padded_len());
209+
self.new_write_frame(input.padded_len());
210210
self.write_value(input);
211-
self.move_frame();
211+
self.move_write_frame_to_read();
212212
}
213213
Ok(())
214214
}
@@ -259,8 +259,8 @@ impl BitMachine {
259259
) -> Result<Value, ExecutionError> {
260260
enum CallStack<'a, J: Jet> {
261261
Goto(&'a RedeemNode<J>),
262-
MoveFrame,
263-
DropFrame,
262+
MoveWriteFrameToRead,
263+
DropReadFrame,
264264
CopyFwd(usize),
265265
Back(usize),
266266
}
@@ -270,8 +270,8 @@ impl BitMachine {
270270
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
271271
match self {
272272
CallStack::Goto(ins) => write!(f, "goto {}", ins.inner()),
273-
CallStack::MoveFrame => f.write_str("move frame"),
274-
CallStack::DropFrame => f.write_str("drop frame"),
273+
CallStack::MoveWriteFrameToRead => f.write_str("move frame"),
274+
CallStack::DropReadFrame => f.write_str("drop frame"),
275275
CallStack::CopyFwd(n) => write!(f, "copy/fwd {}", n),
276276
CallStack::Back(n) => write!(f, "back {}", n),
277277
}
@@ -287,7 +287,7 @@ impl BitMachine {
287287

288288
let output_width = ip.arrow().target.bit_width();
289289
if output_width > 0 {
290-
self.new_frame(output_width);
290+
self.new_write_frame(output_width);
291291
}
292292

293293
'main_loop: loop {
@@ -316,10 +316,10 @@ impl BitMachine {
316316
node::Inner::Comp(left, right) => {
317317
let size_b = left.arrow().target.bit_width();
318318

319-
self.new_frame(size_b);
320-
call_stack.push(CallStack::DropFrame);
319+
self.new_write_frame(size_b);
320+
call_stack.push(CallStack::DropReadFrame);
321321
call_stack.push(CallStack::Goto(right));
322-
call_stack.push(CallStack::MoveFrame);
322+
call_stack.push(CallStack::MoveWriteFrameToRead);
323323
call_stack.push(CallStack::Goto(left));
324324
}
325325
node::Inner::Disconnect(left, right) => {
@@ -328,18 +328,18 @@ impl BitMachine {
328328
let size_prod_b_c = left.arrow().target.bit_width();
329329
let size_b = size_prod_b_c - right.arrow().source.bit_width();
330330

331-
self.new_frame(size_prod_256_a);
331+
self.new_write_frame(size_prod_256_a);
332332
self.write_bytes(right.cmr().as_ref());
333333
self.copy(size_a);
334-
self.move_frame();
335-
self.new_frame(size_prod_b_c);
334+
self.move_write_frame_to_read();
335+
self.new_write_frame(size_prod_b_c);
336336

337337
// Remember that call stack pushes are executed in reverse order
338-
call_stack.push(CallStack::DropFrame);
339-
call_stack.push(CallStack::DropFrame);
338+
call_stack.push(CallStack::DropReadFrame);
339+
call_stack.push(CallStack::DropReadFrame);
340340
call_stack.push(CallStack::Goto(right));
341341
call_stack.push(CallStack::CopyFwd(size_b));
342-
call_stack.push(CallStack::MoveFrame);
342+
call_stack.push(CallStack::MoveWriteFrameToRead);
343343
call_stack.push(CallStack::Goto(left));
344344
}
345345
node::Inner::Take(left) => call_stack.push(CallStack::Goto(left)),
@@ -403,8 +403,8 @@ impl BitMachine {
403403
ip = loop {
404404
match call_stack.pop() {
405405
Some(CallStack::Goto(next)) => break next,
406-
Some(CallStack::MoveFrame) => self.move_frame(),
407-
Some(CallStack::DropFrame) => self.drop_frame(),
406+
Some(CallStack::MoveWriteFrameToRead) => self.move_write_frame_to_read(),
407+
Some(CallStack::DropReadFrame) => self.drop_read_frame(),
408408
Some(CallStack::CopyFwd(n)) => {
409409
self.copy(n);
410410
self.fwd(n);

0 commit comments

Comments
 (0)