mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-26 13:48:23 +00:00
Support s: [2]u16 = "hi"
This commit is contained in:
@@ -3449,10 +3449,23 @@ gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type
|
||||
|
||||
if (is_constant && is_type_untyped(src) && is_type_string(src)) {
|
||||
if (is_type_u8_array(dst)) {
|
||||
GB_ASSERT(operand->value.kind == ExactValue_String);
|
||||
String s = operand->value.value_string;
|
||||
return s.len == dst->Array.count;
|
||||
}
|
||||
if (is_type_u16_array(dst)) {
|
||||
if (operand->value.kind == ExactValue_String16) {
|
||||
String16 s = operand->value.value_string16;
|
||||
return s.len == dst->Array.count;
|
||||
}
|
||||
GB_ASSERT(operand->value.kind == ExactValue_String);
|
||||
String16 s = string_to_string16(heap_allocator(), operand->value.value_string);
|
||||
defer (gb_free(heap_allocator(), s.text));
|
||||
|
||||
return s.len == dst->Array.count;
|
||||
}
|
||||
if (is_type_rune_array(dst)) {
|
||||
GB_ASSERT(operand->value.kind == ExactValue_String);
|
||||
String s = operand->value.value_string;
|
||||
return gb_utf8_strnlen(s.text, s.len) == dst->Array.count;
|
||||
}
|
||||
@@ -4963,6 +4976,12 @@ gb_internal void convert_to_typed(CheckerContext *c, Operand *operand, Type *tar
|
||||
if (rune_count == t->Array.count) {
|
||||
break;
|
||||
}
|
||||
} else if (is_type_u16_array(t)) {
|
||||
String16 s = string_to_string16(heap_allocator(), operand->value.value_string);
|
||||
defer (gb_free(heap_allocator(), s.text));
|
||||
if (s.len == t->Array.count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (operand->value.kind == ExactValue_String16) {
|
||||
String16 s = operand->value.value_string16;
|
||||
|
||||
@@ -1026,6 +1026,27 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
|
||||
}
|
||||
GB_ASSERT(offset == s.len);
|
||||
|
||||
res.value = llvm_const_array(m, et, elems, cast(unsigned)count);
|
||||
return res;
|
||||
} else if (is_type_u16_array(type) && (value.kind == ExactValue_String || value.kind == ExactValue_String16) && !is_type_u8(core_array_type(type))) {
|
||||
i64 count = type->Array.count;
|
||||
Type *elem = type->Array.elem;
|
||||
LLVMTypeRef et = lb_type(m, elem);
|
||||
|
||||
String16 s = {};
|
||||
if (value.kind == ExactValue_String16) {
|
||||
s = value.value_string16;
|
||||
} else {
|
||||
s = string_to_string16(temporary_allocator(), value.value_string);
|
||||
}
|
||||
|
||||
LLVMValueRef *elems = gb_alloc_array(permanent_allocator(), LLVMValueRef, cast(isize)count);
|
||||
|
||||
for (isize i = 0; i < s.len; i++) {
|
||||
elems[i] = LLVMConstInt(et, s.text[i], false);
|
||||
|
||||
}
|
||||
|
||||
res.value = llvm_const_array(m, et, elems, cast(unsigned)count);
|
||||
return res;
|
||||
} else if (is_type_u8_array(type) && value.kind == ExactValue_String) {
|
||||
|
||||
Reference in New Issue
Block a user