Skip to content

Conversation

@greenhat
Copy link
Contributor

@greenhat greenhat commented Jul 5, 2024

This PR is stacked on the #236 and should be merged after it

@greenhat greenhat force-pushed the greenhat/emu-print-stack-option branch from c06811c to 1ce9065 Compare July 5, 2024 14:26
@greenhat greenhat force-pushed the greenhat/emu-print-stack-option branch from 1ce9065 to 79d1c24 Compare July 9, 2024 15:00
@greenhat greenhat changed the title [8/x] Add Emulator::print_stack option to print the current stack on every step [8/x] Add Emulator::print_trace option to print the current stack and memory on every step Jul 9, 2024
@greenhat greenhat requested a review from bitwalker July 9, 2024 15:12
Copy link
Collaborator

@bitwalker bitwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! One minor suggestion about ordering of items in the output that you can take or leave based on your preference; and two small changes that I think we should make prior to merging.


pub struct Memory {
memory: Vec<[Felt; 4]>,
set_memory_addrs: FxHashSet<usize>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I would make this a BTreeSet, so that you can print the memory addresses in order, plus its probably faster than a hashset in this case, since memory addresses are totally ordered, and highly likely to be written to in order from least to greatest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I missed it since I only dealt with a couple of addresses, but the order is important.
Done in 8ca444b

self
}

pub fn pretty(&self) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this a Display impl, and base it on the existing Debug impl. The only difference between this and Debug seems to be how we format each stack element, which is certainly useful, but I'd rather use Display for it, since it is far more ergonomic than building strings directly, and you get to_string for free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Done in 8ca444b

@greenhat greenhat force-pushed the greenhat/fix-emu-mem-clean branch 2 times, most recently from effc46b to 8aea8fe Compare July 17, 2024 12:40
and memory contents (only written to) on every step of the execution.
@greenhat greenhat force-pushed the greenhat/emu-print-stack-option branch from 79d1c24 to fb59577 Compare July 17, 2024 12:42
…lator

Print the emulator's memory before the stack.
Impl `Display` instead of `DebugStack::pretty`.
@greenhat greenhat requested a review from bitwalker July 17, 2024 13:10
Base automatically changed from greenhat/fix-emu-mem-clean to main July 17, 2024 13:11
Copy link
Collaborator

@bitwalker bitwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bitwalker bitwalker merged commit 9b32d3b into main Jul 18, 2024
@bitwalker bitwalker deleted the greenhat/emu-print-stack-option branch July 18, 2024 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants