-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Display trait to Memory struct #812
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format the temporary memory too.
Ideally something like
temp_memory: [[1,2,3][1,2]]
real_memory: [[1,2]]
should look like this:
-1:0 : 1
-1:1 : 2
-1:2 : 3
-2:0 : 1
-2:1 : 2
0;0 : 1
0:1 : 2
src/vm/vm_memory/memory.rs
Outdated
for (i, segment) in self.data.iter().enumerate() { | ||
for (j, cell) in segment.iter().enumerate() { | ||
if let Some(cell) = cell { | ||
writeln!(f, " {},{} : {}", i, j, cell)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writeln!(f, " {},{} : {}", i, j, cell)?; | |
writeln!(f, " ({i},{j}) : {cell}")?; |
src/vm/vm_memory/memory.rs
Outdated
@@ -300,6 +301,29 @@ impl Memory { | |||
} | |||
} | |||
|
|||
impl Display for Memory { | |||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { | |||
writeln!(f, "temp_memory {{")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid making distinctions between real and temporary memory and just pritnt them out as a single memory. Temporary segments can be identified by their negative index
src/vm/vm_memory/memory.rs
Outdated
for (i, segment) in self.temp_data.iter().enumerate() { | ||
for (j, cell) in segment.iter().enumerate() { | ||
if let Some(cell) = cell { | ||
writeln!(f, " ({i},{j}) : {cell}")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that temporary memory segment indexes start from -1, but we store them from 0 (cuz vec). So when printing out the temporary addresses we should be printing -(i + 1)
instead of i
src/vm/vm_memory/memory.rs
Outdated
@@ -300,6 +301,28 @@ impl Memory { | |||
} | |||
} | |||
|
|||
impl Display for Memory { | |||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { | |||
writeln!(f, "memory {{")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think this is necessary, the user already knows its the memory being displayed if they print the memory
} | ||
} | ||
} | ||
writeln!(f, "}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These symbols make it look like a Debug rather than a Display, we could avoid them
Codecov Report
@@ Coverage Diff @@
## main #812 +/- ##
=========================================
+ Coverage 0 97.81% +97.81%
=========================================
Files 0 69 +69
Lines 0 29410 +29410
=========================================
+ Hits 0 28767 +28767
- Misses 0 643 +643
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Add Display trait to Memory struct
Description
#799
Checklist