@@ -168,15 +168,24 @@ fn fetch_printable_type(
168
168
fn to_string ( value : & PrintableValue , typ : & PrintableType ) -> Option < String > {
169
169
let mut output = String :: new ( ) ;
170
170
match ( value, typ) {
171
- (
172
- PrintableValue :: Field ( f) ,
173
- PrintableType :: Field
174
- // TODO(#2401): We should print the sign for these and probably print normal integers instead of field strings
175
- | PrintableType :: SignedInteger { .. }
176
- | PrintableType :: UnsignedInteger { .. } ,
177
- ) => {
171
+ ( PrintableValue :: Field ( f) , PrintableType :: Field ) => {
178
172
output. push_str ( & format_field_string ( * f) ) ;
179
173
}
174
+ ( PrintableValue :: Field ( f) , PrintableType :: UnsignedInteger { width } ) => {
175
+ let uint_cast = f. to_u128 ( ) & ( ( 1 << width) - 1 ) ; // Retain the lower 'width' bits
176
+ output. push_str ( & uint_cast. to_string ( ) ) ;
177
+ }
178
+ ( PrintableValue :: Field ( f) , PrintableType :: SignedInteger { width } ) => {
179
+ let mut uint = f. to_u128 ( ) ; // Interpret as uint
180
+
181
+ // Extract sign relative to width of input
182
+ if ( uint >> ( width - 1 ) ) == 1 {
183
+ output. push ( '-' ) ;
184
+ uint = ( uint ^ ( ( 1 << width) - 1 ) ) + 1 ; // Two's complement relative to width of input
185
+ }
186
+
187
+ output. push_str ( & uint. to_string ( ) ) ;
188
+ }
180
189
( PrintableValue :: Field ( f) , PrintableType :: Boolean ) => {
181
190
if f. is_one ( ) {
182
191
output. push_str ( "true" ) ;
@@ -187,8 +196,11 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
187
196
( PrintableValue :: Vec ( vector) , PrintableType :: Array { typ, .. } ) => {
188
197
output. push ( '[' ) ;
189
198
let mut values = vector. iter ( ) . peekable ( ) ;
190
- while let Some ( value) = values. next ( ) {
191
- output. push_str ( & format ! ( "{}" , PrintableValueDisplay :: Plain ( value. clone( ) , * typ. clone( ) ) ) ) ;
199
+ while let Some ( value) = values. next ( ) {
200
+ output. push_str ( & format ! (
201
+ "{}" ,
202
+ PrintableValueDisplay :: Plain ( value. clone( ) , * typ. clone( ) )
203
+ ) ) ;
192
204
if values. peek ( ) . is_some ( ) {
193
205
output. push_str ( ", " ) ;
194
206
}
@@ -204,9 +216,12 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
204
216
output. push_str ( & format ! ( "{name} {{ " ) ) ;
205
217
206
218
let mut fields = fields. iter ( ) . peekable ( ) ;
207
- while let Some ( ( key, field_type) ) = fields. next ( ) {
219
+ while let Some ( ( key, field_type) ) = fields. next ( ) {
208
220
let value = & map[ key] ;
209
- output. push_str ( & format ! ( "{key}: {}" , PrintableValueDisplay :: Plain ( value. clone( ) , field_type. clone( ) ) ) ) ;
221
+ output. push_str ( & format ! (
222
+ "{key}: {}" ,
223
+ PrintableValueDisplay :: Plain ( value. clone( ) , field_type. clone( ) )
224
+ ) ) ;
210
225
if fields. peek ( ) . is_some ( ) {
211
226
output. push_str ( ", " ) ;
212
227
}
@@ -215,7 +230,7 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
215
230
output. push_str ( " }" ) ;
216
231
}
217
232
218
- _ => return None
233
+ _ => return None ,
219
234
} ;
220
235
221
236
Some ( output)
0 commit comments