Support string literals for fixed arrays of runes; Add %q support for arrays/slices of bytes

This commit is contained in:
gingerBill
2020-11-20 16:24:23 +00:00
parent 6416a6f39c
commit 63e4a2341f
6 changed files with 96 additions and 29 deletions
+22
View File
@@ -734,6 +734,28 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
if (is_type_array(type) && value.kind == ExactValue_String && !is_type_u8(core_array_type(type))) {
i64 count = type->Array.count;
Type *elem = type->Array.elem;
if (is_type_rune_array(type)) {
Rune rune;
isize offset = 0;
isize width = 1;
String s = value.value_string;
ir_write_byte(f, '[');
for (i64 i = 0; i < count && offset < s.len; i++) {
width = gb_utf8_decode(s.text+offset, s.len-offset, &rune);
if (i > 0) ir_write_str_lit(f, ", ");
ir_print_type(f, m, elem);
ir_write_byte(f, ' ');
ir_print_exact_value(f, m, exact_value_i64(rune), elem);
offset += width;
}
GB_ASSERT(offset == s.len);
ir_write_byte(f, ']');
return;
}
ir_write_byte(f, '[');
for (i64 i = 0; i < count; i++) {