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

feat(#3): Derive FromStr for OpCode using strum dependency #4

Merged
merged 2 commits into from Mar 19, 2021

Conversation

Hasenn
Copy link

@Hasenn Hasenn commented Mar 12, 2021

This will allow my assembler to depend on do-core for its OpCode parsing

I added a dependency to strum and strum_macros to automatically generate the FromStr implementation, which doesn't introduce any overhead to adding new opcodes.

Copy link
Collaborator

@sameo sameo left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Hasenn

Could you please:

  • Add an SOB to your commit message,
  • Add a commit message, not just a title. Explain why this is needed
  • Follow the existing commit subject pattern. Here it should be :do-core: Instruction: Implement FromStr
  • Add a Fixes #3 to your commit message in order to link it to the issue.

@@ -5,3 +5,5 @@ authors = ["Samuel Ortiz <sameo@linux.intel.com>"]
edition = "2018"

[dependencies]
strum = "0.20.0" # enum utils with a derive for FromStr
strum_macros = "0.20.1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This brings 6 new dependent crates.
If we only need the FromStr trait, I would prefer that we implement it instead.

Copy link
Author

Choose a reason for hiding this comment

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

Ok we can do that, i tried to pick the least evil between those dependencies and failing DRY

Copy link
Collaborator

Choose a reason for hiding this comment

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

Trying is not failing :) A lot of projects are using strum so it is a good option. But if we need only one struct to implement FromStr, then we're talking about 20 lines of codes or so, vs 6 new crates. Security and maintenance wise, it makes more sense to implement our own. As the golang proverb says: "A little copying is better than a little dependency."

@Hasenn
Copy link
Author

Hasenn commented Mar 19, 2021

Should i use super::* in the test module ?

@sameo
Copy link
Collaborator

sameo commented Mar 19, 2021

Should i use super::* in the test module ?

That's a wildcard that's typically used in test modules, yes. Fine by me.

@Hasenn
Copy link
Author

Hasenn commented Mar 19, 2021

@sameo Changes done, ready for review

"ST" => Ok(OpCode::ST),
"ADD" => Ok(OpCode::ADD),
"XOR" => Ok(OpCode::XOR),
_ => Err(Error::ParseOpError),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs some formatting love. cargo fmt will help you.

Copy link
Author

Choose a reason for hiding this comment

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

i ran it earlier and it unaligns everything even more :

            "LD" => Ok(OpCode::LD),
            "ST" => Ok(OpCode::ST),
            "ADD" => Ok(OpCode::ADD),
            "XOR" => Ok(OpCode::XOR),
            _ => Err(Error::ParseOpError),

@sameo
Copy link
Collaborator

sameo commented Mar 19, 2021

@sameo Changes done, ready for review

Much better. Could you also add you Signed-off-by to the commit message (git commit --amend -s)

Related issue: dev-sys-do#3
This is for do-core-asm to be able to depend on us for its opcodes needs

Signed-off-by: Eliott Veyrier <eliott.veyrier@umontpellier.fr>
Signed-off-by: Eliott Veyrier <eliott.veyrier@umontpellier.fr>
@sameo sameo merged commit 90bc5b7 into dev-sys-do:main Mar 19, 2021
@Hasenn
Copy link
Author

Hasenn commented Mar 19, 2021

this closes #3

sameo pushed a commit that referenced this pull request Feb 6, 2022
With naive pattern matching check.

Live exercice #4.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
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