-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Customize format for I32/U32 (issue #1920) #1927
Conversation
There was a TravisCI failure that was unrelated to code, it was during dependency install. Restarted that one job. |
packages/format/_format_int.pony
Outdated
@@ -65,6 +65,40 @@ primitive _FormatInt | |||
s.reverse_in_place() | |||
end | |||
|
|||
fun u32(x: U32, neg: Bool, fmt: FormatInt, prefix: PrefixNumber, | |||
prec: USize, width: USize, align: Align, fill: U32 | |||
): String iso^ => |
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.
see the style guide that is in progress for formatting on this.
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.
Updated the PR. Something like this?
That would fit the forthcoming style guide @krig. Yes. |
Alright, great. Fixed one small formatting mistake in the previous update. |
packages/format/format.pony
Outdated
@@ -96,8 +96,10 @@ primitive Format | |||
_FormatInt.u128(x.u128(), false, fmt, prefix, prec, width, align, fill) | |||
elseif x is I128 then | |||
_FormatInt.u128(abs.u128(), neg, fmt, prefix, prec, width, align, fill) | |||
else | |||
elseif (x is U64) or (x is I64) then |
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.
there's a bug that predates your code @krig. These should be using a match expression or an iftype
. The latter is preferred.
The is
doesn't work as it compares identity rather than checking the type.
So x is I128
will only be triggered for the value 0. otherwise the else will always be used.
iftype A <: U128 then
_FormatInt.u128(x.u128(), false, fmt, prefix, prec, width, align, fill)
elseif A <: I128 then
_FormatInt.u128(abs.u128(), neg, fmt, prefix, prec, width, align, fill)
else
_FormatInt.u64(abs.u64(), neg, fmt, prefix, prec, width, align, fill)
end
Can you make that update @krig?
@SeanTAllen I fixed the if/iftype bug, at least I think so. At the same time I thought to test if formatting min_value works for I8/I16 as well, since I suspected it didn't. And it didn't. So I implemented those as well. Ideas for how to reduce the duplication across the various int functions are welcome, I'm still very much a pony newbie :) |
Hm. It also doesn't work properly for |
@krig Thanks for digging into this! For implementing the variable-sized types ( |
@jemc Ah, perfect! I'll update it. |
packages/format/format.pony
Outdated
_FormatInt.u16(abs.u16(), neg, fmt, prefix, prec, width, align, fill) | ||
elseif A <: (U8 | I8) then | ||
_FormatInt.u8(abs.u8(), neg, fmt, prefix, prec, width, align, fill) | ||
elseif A <: (USize | ISize | ULong | ILong) then |
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.
Sorry, this isn't quite right - the *Size
types have different bitwidth semantics from the *Long
types. Please see the definition of ISize.bitwidth()
.
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.
Ah, I see, thanks.
Sorry, looks like there's one more issue in the tests, where you're testing It's causing failures on the windows CI builds. |
Fixes formatting of I32.min_value(), I16.min_value(), etc. TODO: the various type-specific funs in _format_int.pony could probably be largely re-unified. Update formatting to follow style guide proposal (ponylang#1894). Fixes: ponylang#1920
Good thing I added the test.. alright, this should do it. |
This is meant to prevent confusion with respect to other primitives whose value can be compared using `is ${PrimitiveName}`. Machine words are special primitives that can have multiple values, and comparing with `is ${MachineWord}` is currently equivalent to comparing to zero. Incidentally, fixing this also alerts us to the bug in #1920. We should hold off on merging this PR until after #1927 is merged.
Great, thanks for bringing this one home! |
Cool, thank you both! |
Awesome to see this merged! Thanks @krig. You rock. |
This is meant to prevent confusion with respect to other primitives whose value can be compared using `is ${PrimitiveName}`. Machine words are special primitives that can have multiple values, and comparing with `is ${MachineWord}` is currently equivalent to comparing to zero. Incidentally, fixing this also alerts us to the bug in #1920. We should hold off on merging this PR until after #1927 is merged.
This is meant to prevent confusion with respect to other primitives whose value can be compared using `is ${PrimitiveName}`. Machine words are special primitives that can have multiple values, and comparing with `is ${MachineWord}` is currently equivalent to comparing to zero. Incidentally, fixing this also alerts us to the bug in #1920. We should hold off on merging this PR until after #1927 is merged.
Fixes formatting of I32.min_value().
TODO: the u32 and u64 funs in
_format_int.pony
could probably be largely re-unified.Fixes: #1920