-
Notifications
You must be signed in to change notification settings - Fork 89
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
Rewrite fuel_asm::impl_instructions! to a proc macro #804
base: master
Are you sure you want to change the base?
Conversation
fuel-derive/src/asm.rs
Outdated
let name = &arg.name; | ||
if arg.is_imm() { | ||
quote! { | ||
packed_integer |= (#name.to_smallest_int() as u32); |
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.
Places like this would be better with a single-use helper function.
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.
Moved most of these to smaller functions.
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 stuff! While I still find macros hard to read in general, the code after the refactor is much easier to follow than the previous implementation of this macro. Thanks for making this improvement!
fuel-derive/src/asm.rs
Outdated
.0 | ||
.iter() | ||
.map( | ||
|Instruction { |
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.
It would be nice for each closure that we use inside of the map
to have a named function like make_constructor_for_opcode
. Name is up to you=)
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've simplified the code quite a bit and each map has only a small block of code inside. Let me know if you still feel we need to have the closures as separate functions as well.
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.
LGTM
What it says on the tin. No exteranal functional changes, just refactoring.
Crate-internal
test_construct
function has been removed, as the associated test didn't seem to catch any errors. It has been rewritten to use a fuzzing-style property-based testing.The purpose of this PR is to allow more complex instruction definitions in the future. This should allow moving some validity checks to instruction parsing level, and to improve type safety.
Checklist
Before requesting review