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 parsing of pushw and env io operations #40

Merged
merged 5 commits into from Jan 7, 2022

Conversation

grjte
Copy link
Collaborator

@grjte grjte commented Jan 7, 2022

I added a few tests to check error cases and couldn't assert_eq the exact errors. I guess this is because the PartialEq trait isn't implemented for AssemblyError, but maybe there's another way around this that I'm not aware of yet..? For the moment, I just asserted that the result gave an error without checking to see which one. Let me know if you have any thoughts on this.

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 great! Thank you! I left a couple of notes for the future in-line. Regarding checking for exact errors: I actually don't know what the best practice on this is - but yes, I agree, ideally we should be checking against exact errors. Could you create an issue for investigating this?

Comment on lines +208 to +224
/// This is a helper function that validates the length of the assembly io instruction and returns
/// an error if params are missing or there are extras.
///
/// The minimum and maximum number of valid instruction parts for the op are provided by the
/// caller.
///
/// # Errors
///
/// This function will return an AssemblyError if the assembly op has too many or too few parts.
fn validate_op_len(op: &Token, min_parts: usize, max_parts: usize) -> Result<(), AssemblyError> {
match op.num_parts() {
too_few if too_few < min_parts => Err(AssemblyError::missing_param(op)),
too_many if too_many > max_parts => Err(AssemblyError::extra_param(op)),
_ => Ok(()),
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but I wonder if we should move this out to be used in other modules as well.

Copy link
Collaborator Author

@grjte grjte Jan 9, 2022

Choose a reason for hiding this comment

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

Yes, I think we should. Otherwise we're either duplicating code or we're under-validating. Pulling this logic out & calling the function instead of using match should make all of the op parsing implementations more readable.

fn pushw() {
// pushes a word of 4 immediate values in decimal or hexadecimal onto the stack
let mut span_ops: Vec<Operation> = Vec::new();
let op = Token::new("pushw.1.23.0x1C8.0", 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR: now that I'm seeing how this actually looks, I wonder if we should change the format of pushw instruction to always take a single hexadecimal value of 32 bytes. Or maybe making this as an additional allowed format. So, for example, possible formats could be:

  • pushw.1.2.3.4
  • pushw.0x13244... (32 bytes)

Let's create an issue to think this through later on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I opened an issue here: #44

@bobbinth bobbinth merged commit c07f98a into 0xPolygonMiden:next Jan 7, 2022
@bobbinth bobbinth mentioned this pull request Jan 7, 2022
39 tasks
@grjte
Copy link
Collaborator Author

grjte commented Jan 9, 2022

Errors issue with the result of my investigation is here: #43

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.

None yet

2 participants