Skip to content
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

Implement Repl tool in Miden VM #440

Merged
merged 2 commits into from
Nov 2, 2022
Merged

Implement Repl tool in Miden VM #440

merged 2 commits into from
Nov 2, 2022

Conversation

0xkanekiken
Copy link
Contributor

@0xkanekiken 0xkanekiken commented Oct 20, 2022

Describe your changes

This PR addresses #423 and is in continuation to the work done by the scribe team here.
The following tasks are addressed in this PR:

  • Print out instructions message on startup
  • Use a prefix for REPL commands to avoid future potential collisions with assembly instructions (e.g., maybe something like !stack or :stack instead of just stack).
  • Add memory (or just mem) command to print out state of memory with support for indexing. For example, mem prints out the whole state of memory, but mem[1] prints out memory at address 1.
  • When printing out stack state, include data from the overflow table (maybe separated by | from the top 16 values).
  • When an instruction is entered, maybe print out stack state immediately. Or maybe have an option for two different modes.

Checklist before requesting a review

  • Repo forked and branch created from next according to naming convention.
  • Commit messages and codestyle follow conventions.
  • Relevant issues are linked in the PR description.
  • Tests added for new functionality.
  • Documentation/comments updated according to changes.

@bobbinth bobbinth changed the title Repl tool in Miden VM Implement Repl tool in Miden VM Oct 21, 2022
@bobbinth bobbinth mentioned this pull request Oct 21, 2022
26 tasks
@frisitano
Copy link
Contributor

When I implemented the cli I put all cli specific dependencies and logic behind a feature flag - executable. By doing this the cli dependencies and logic are only included in the binary if the executable feature is specified at compile time - cargo build --release --features executable. This means that cli logic and dependencies are not leaked in with the library code when it is not required. This can be done by specifying the dependencies as optional and then associating them with the executable feature as seen here. Maybe something to consider for this PR.

@bobbinth
Copy link
Contributor

Thank you! I tested it a bit - so, these are comments based on usage not a code review:

Upon launch, the printout looks a bit odd:

============================================================
Launching Miden Repl Tool
============================================================
========================== Miden REPL ============================

Available commands:

We probably don't need the part "Launching Miden Repl Tool".

Then, for some reason only the stack command is prefixed with !:

!stack: displays the complete state of the stack
mem: displays the state of the entire memory
mem[i]: displays the state of the memory at index i
undo: remove the last instruction
program: display the program

All command should be prefixed so that they are not confused with assembly instructions. For !mem[i] command, we should say "at address i" instead of "at index i". Also, we should probably add !help command which prints out these instructions again.

Next, when we execute a command, we print out top 16 elements of the stack and stack helper registers.

>> push.1

1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | 17 1 1

What's the reason for printing stack helper registers? I think they are pretty meaningless from the user's standpoint. Instead, in place of stack helper registers we should print out values in the stack overflow table. We also probably should get rid of the blank line between the input and stack state printout (i.e., in the example above the blank line between >> push.1 and 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | 17 1 1).

Next, when we print out the state of memory, we print elements in debug mode:

>> mem

[(0, [BaseElement(2), BaseElement(0), BaseElement(0), BaseElement(0)]), (2, [BaseElement(0), BaseElement(0), BaseElement(1), BaseElement(2)])]

Instead, we should print them out as integers, and generally improve formatting to be more like this:

>> mem
0: [2, 0, 0, 0]
2: [0, 0, 1, 2]

Next, when printing out individual memory location we currently show something like this:

>> mem[2]

The memory value at index 2 is [BaseElement(0), BaseElement(0), BaseElement(1), BaseElement(2)]

Instead, we should show something like this:

>> mem[2]
[0, 0, 1, 2]

Lastly, when printing out an empty memory slot, we should something like this:

>> mem[1]

The memory value is empty at index 1

Instead, it could be something like this:

>> mem[1]
Memory at address 1 is empty.

@0xkanekiken
Copy link
Contributor Author

Thanks for the review! I've actioned on your suggestions.

============================================================
Launching Miden Repl Tool
============================================================
========================== Miden REPL ============================

I've updated it to

 ========================== Miden REPL ============================

I've now prefixed all the REPL commands with ! so that one doesn't confuse them with regular assembly instruction. It now looks like following:

!stack: displays the complete state of the stack
!mem: displays the state of the entire memory
!mem[i]: displays the state of the memory at address i
!undo: remove the last instruction
!program: display the program
!help: prints out all the available commands

What's the reason for printing stack helper registers? I think they are pretty meaningless from the user's standpoint. Instead, in place of stack helper registers we should print out values in the stack overflow table. We also probably should get rid of the blank line between the input and stack state printout (i.e., in the example above the blank line between >> push.1 and 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | 17 1 1).

Agreed and I've removed the overflow part and the extra line in between the commands and the output.

>> !stack
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 3 82 7 6 5 4 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The output of !mem and !mem[i] are as follows:

>> !mem
2: [5, 6, 7, 82]
3: [5, 6, 7, 82]
>> !mem[4]
Memory at address 4 is empty
>> !mem[2]
2: [5, 6, 7, 82]

Although I feel that we should display the memory values in reverse order as then it will be inline with the order we have in stack.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left some comments inline.

miden/src/cli/repl.rs Outdated Show resolved Hide resolved
miden/src/main.rs Show resolved Hide resolved
miden/src/main.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
@0xkanekiken 0xkanekiken marked this pull request as ready for review November 1, 2022 20:28
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Thank you! I left more small comments inline.

miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/repl/mod.rs Outdated Show resolved Hide resolved
miden/src/cli/repl.rs Outdated Show resolved Hide resolved
miden/src/main.rs Outdated Show resolved Hide resolved
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

All looks good! Thank you!

@bobbinth bobbinth merged commit 4553652 into 0xPolygonMiden:next Nov 2, 2022
@bobbinth bobbinth mentioned this pull request Nov 3, 2022
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