mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-21 05:45:19 +00:00
ODIN_ALLOW_128_BIT support in encoding/json; Keep -vet happy
This commit is contained in:
@@ -100,18 +100,32 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
||||
|
||||
case runtime.Type_Info_Integer:
|
||||
buf: [40]byte
|
||||
u := cast_any_int_to_u128(a)
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
u := cast_any_int_to_u128(a)
|
||||
} else {
|
||||
u := cast_any_int_to_u64(a)
|
||||
}
|
||||
|
||||
s: string
|
||||
|
||||
// allow uints to be printed as hex
|
||||
if opt.write_uint_as_hex && (opt.spec == .JSON5 || opt.spec == .MJSON) {
|
||||
switch i in a {
|
||||
case u8, u16, u32, u64, u128:
|
||||
s = strconv.append_bits_128(buf[:], u, 16, info.signed, 8*ti.size, "0123456789abcdef", { .Prefix })
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
switch i in a {
|
||||
case u8, u16, u32, u64, u128:
|
||||
s = strconv.append_bits_128(buf[:], u, 16, info.signed, 8*ti.size, "0123456789abcdef", { .Prefix })
|
||||
|
||||
case:
|
||||
s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil)
|
||||
case:
|
||||
s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil)
|
||||
}
|
||||
} else {
|
||||
switch i in a {
|
||||
case u8, u16, u32, u64:
|
||||
s = strconv.append_bits(buf[:], u, 8, info.signed, 8*ti.size, "0123456789abcdef", { .Prefix })
|
||||
|
||||
case:
|
||||
s = strconv.append_bits(buf[:], u, 8, info.signed, 8*ti.size, "0123456789", nil)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s = strconv.append_bits_128(buf[:], u, 10, info.signed, 8*ti.size, "0123456789", nil)
|
||||
@@ -631,40 +645,79 @@ opt_write_indentation :: proc(w: io.Writer, opt: ^Marshal_Options) -> (err: io.E
|
||||
return
|
||||
}
|
||||
|
||||
@(private)
|
||||
cast_any_int_to_u128 :: proc(any_int_value: any) -> u128 {
|
||||
u: u128 = 0
|
||||
switch i in any_int_value {
|
||||
case i8: u = u128(i)
|
||||
case i16: u = u128(i)
|
||||
case i32: u = u128(i)
|
||||
case i64: u = u128(i)
|
||||
case i128: u = u128(i)
|
||||
case int: u = u128(i)
|
||||
case u8: u = u128(i)
|
||||
case u16: u = u128(i)
|
||||
case u32: u = u128(i)
|
||||
case u64: u = u128(i)
|
||||
case u128: u = u128(i)
|
||||
case uint: u = u128(i)
|
||||
case uintptr: u = u128(i)
|
||||
|
||||
case i16le: u = u128(i)
|
||||
case i32le: u = u128(i)
|
||||
case i64le: u = u128(i)
|
||||
case u16le: u = u128(i)
|
||||
case u32le: u = u128(i)
|
||||
case u64le: u = u128(i)
|
||||
case u128le: u = u128(i)
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
@(private)
|
||||
cast_any_int_to_u128 :: proc(any_int_value: any) -> u128 {
|
||||
u: u128 = 0
|
||||
switch i in any_int_value {
|
||||
case i8: u = u128(i)
|
||||
case i16: u = u128(i)
|
||||
case i32: u = u128(i)
|
||||
case i64: u = u128(i)
|
||||
case i128: u = u128(i)
|
||||
case int: u = u128(i)
|
||||
case u8: u = u128(i)
|
||||
case u16: u = u128(i)
|
||||
case u32: u = u128(i)
|
||||
case u64: u = u128(i)
|
||||
case u128: u = u128(i)
|
||||
case uint: u = u128(i)
|
||||
case uintptr: u = u128(i)
|
||||
|
||||
case i16be: u = u128(i)
|
||||
case i32be: u = u128(i)
|
||||
case i64be: u = u128(i)
|
||||
case u16be: u = u128(i)
|
||||
case u32be: u = u128(i)
|
||||
case u64be: u = u128(i)
|
||||
case u128be: u = u128(i)
|
||||
case i16le: u = u128(i)
|
||||
case i32le: u = u128(i)
|
||||
case i64le: u = u128(i)
|
||||
case u16le: u = u128(i)
|
||||
case u32le: u = u128(i)
|
||||
case u64le: u = u128(i)
|
||||
case u128le: u = u128(i)
|
||||
|
||||
case i16be: u = u128(i)
|
||||
case i32be: u = u128(i)
|
||||
case i64be: u = u128(i)
|
||||
case u16be: u = u128(i)
|
||||
case u32be: u = u128(i)
|
||||
case u64be: u = u128(i)
|
||||
case u128be: u = u128(i)
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
} else {
|
||||
@(private)
|
||||
cast_any_int_to_u64 :: proc(any_int_value: any) -> u64 {
|
||||
u: u64 = 0
|
||||
switch i in any_int_value {
|
||||
case i8: u = u64(i)
|
||||
case i16: u = u64(i)
|
||||
case i32: u = u64(i)
|
||||
case i64: u = u64(i)
|
||||
case i128: u = u64(i)
|
||||
case int: u = u64(i)
|
||||
case u8: u = u64(i)
|
||||
case u16: u = u64(i)
|
||||
case u32: u = u64(i)
|
||||
case u64: u = u64(i)
|
||||
case uint: u = u64(i)
|
||||
case uintptr: u = u64(i)
|
||||
|
||||
case i16le: u = u64(i)
|
||||
case i32le: u = u64(i)
|
||||
case i64le: u = u64(i)
|
||||
case u16le: u = u64(i)
|
||||
case u32le: u = u64(i)
|
||||
case u64le: u = u64(i)
|
||||
|
||||
case i16be: u = u64(i)
|
||||
case i32be: u = u64(i)
|
||||
case i64be: u = u64(i)
|
||||
case u16be: u = u64(i)
|
||||
case u32be: u = u64(i)
|
||||
case u64be: u = u64(i)
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
return u
|
||||
}
|
||||
@@ -97,9 +97,6 @@ assign_int :: proc(val: any, i: $T) -> bool {
|
||||
case i64: dst = i64 (i)
|
||||
case i64le: dst = i64le (i)
|
||||
case i64be: dst = i64be (i)
|
||||
case i128: dst = i128 (i)
|
||||
case i128le: dst = i128le (i)
|
||||
case i128be: dst = i128be (i)
|
||||
case u8: dst = u8 (i)
|
||||
case u16: dst = u16 (i)
|
||||
case u16le: dst = u16le (i)
|
||||
@@ -110,13 +107,21 @@ assign_int :: proc(val: any, i: $T) -> bool {
|
||||
case u64: dst = u64 (i)
|
||||
case u64le: dst = u64le (i)
|
||||
case u64be: dst = u64be (i)
|
||||
case u128: dst = u128 (i)
|
||||
case u128le: dst = u128le (i)
|
||||
case u128be: dst = u128be (i)
|
||||
case int: dst = int (i)
|
||||
case uint: dst = uint (i)
|
||||
case uintptr: dst = uintptr(i)
|
||||
case:
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
switch &dst in v {
|
||||
case i128: dst = i128 (i); return true
|
||||
case i128le: dst = i128le (i); return true
|
||||
case i128be: dst = i128be (i); return true
|
||||
case u128: dst = u128 (i); return true
|
||||
case u128le: dst = u128le (i); return true
|
||||
case u128be: dst = u128be (i); return true
|
||||
}
|
||||
}
|
||||
|
||||
ti := type_info_of(v.id)
|
||||
if _, ok := ti.variant.(runtime.Type_Info_Bit_Set); ok {
|
||||
do_byte_swap := !reflect.bit_set_is_big_endian(v)
|
||||
|
||||
@@ -3203,15 +3203,15 @@ fmt_arg :: proc(fi: ^Info, arg: any, verb: rune) {
|
||||
|
||||
case:
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
switch a in base_arg {
|
||||
case i128: fmt_int_128(fi, u128(a), true, 128, verb)
|
||||
case u128: fmt_int_128(fi, a, false, 128, verb)
|
||||
switch a2 in base_arg {
|
||||
case i128: fmt_int_128(fi, u128(a2), true, 128, verb)
|
||||
case u128: fmt_int_128(fi, (a2), false, 128, verb)
|
||||
|
||||
case i128le: fmt_int_128(fi, u128(a), true, 128, verb)
|
||||
case u128le: fmt_int_128(fi, u128(a), false, 128, verb)
|
||||
case i128le: fmt_int_128(fi, u128(a2), true, 128, verb)
|
||||
case u128le: fmt_int_128(fi, u128(a2), false, 128, verb)
|
||||
|
||||
case i128be: fmt_int_128(fi, u128(a), true, 128, verb)
|
||||
case u128be: fmt_int_128(fi, u128(a), false, 128, verb)
|
||||
case i128be: fmt_int_128(fi, u128(a2), true, 128, verb)
|
||||
case u128be: fmt_int_128(fi, u128(a2), false, 128, verb)
|
||||
case:
|
||||
fmt_value(fi, arg, verb)
|
||||
}
|
||||
|
||||
@@ -1178,13 +1178,13 @@ as_i64 :: proc(a: any) -> (value: i64, valid: bool) {
|
||||
case i64be: value = i64(v)
|
||||
case:
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
switch v in a {
|
||||
case i128: value = i64(v)
|
||||
case u128: value = i64(v)
|
||||
case u128le: value = i64(v)
|
||||
case i128le: value = i64(v)
|
||||
case u128be: value = i64(v)
|
||||
case i128be: value = i64(v)
|
||||
switch v2 in a {
|
||||
case i128: value = i64(v2)
|
||||
case u128: value = i64(v2)
|
||||
case u128le: value = i64(v2)
|
||||
case i128le: value = i64(v2)
|
||||
case u128be: value = i64(v2)
|
||||
case i128be: value = i64(v2)
|
||||
case: valid = false
|
||||
}
|
||||
} else {
|
||||
@@ -1293,13 +1293,13 @@ as_u64 :: proc(a: any) -> (value: u64, valid: bool) {
|
||||
case i64be: value = u64(v)
|
||||
case:
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
switch v in a {
|
||||
case i128: value = u64(v)
|
||||
case u128: value = u64(v)
|
||||
case u128le: value = u64(v)
|
||||
case i128le: value = u64(v)
|
||||
case u128be: value = u64(v)
|
||||
case i128be: value = u64(v)
|
||||
switch v2 in a {
|
||||
case i128: value = u64(v2)
|
||||
case u128: value = u64(v2)
|
||||
case u128le: value = u64(v2)
|
||||
case i128le: value = u64(v2)
|
||||
case u128be: value = u64(v2)
|
||||
case i128be: value = u64(v2)
|
||||
case: valid = false
|
||||
}
|
||||
} else {
|
||||
@@ -1407,13 +1407,13 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) {
|
||||
case i64be: value = f64(v)
|
||||
case:
|
||||
when ODIN_ALLOW_128_BIT {
|
||||
switch v in a {
|
||||
case i128: value = f64(v)
|
||||
case u128: value = f64(v)
|
||||
case u128le: value = f64(v)
|
||||
case i128le: value = f64(v)
|
||||
case u128be: value = f64(v)
|
||||
case i128be: value = f64(v)
|
||||
switch v2 in a {
|
||||
case i128: value = f64(v2)
|
||||
case u128: value = f64(v2)
|
||||
case u128le: value = f64(v2)
|
||||
case i128le: value = f64(v2)
|
||||
case u128be: value = f64(v2)
|
||||
case i128be: value = f64(v2)
|
||||
case: valid = false
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user