From 9b1cc6e94f061629d55db9f0baad46229d4fb755 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 8 Jun 2020 12:41:42 +0100 Subject: Update logic for slice literals, backing array to be on the stack if possible (LLVM C API) --- src/check_expr.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 21487c231..c38bec9b7 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -4347,17 +4347,27 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 case BuiltinProc_swizzle: { // swizzle :: proc(v: [N]T, ..int) -> [M]T Type *type = base_type(operand->type); - if (!is_type_array(type)) { + i64 max_count = 0; + Type *elem_type = nullptr; + + if (!is_type_array(type) && !is_type_simd_vector(type)) { gbString type_str = type_to_string(operand->type); error(call, - "You can only 'swizzle' an array, got '%s'", + "'swizzle' is only allowed on an array or #simd vector, got '%s'", type_str); gb_string_free(type_str); return false; } - - i64 max_count = type->Array.count; - Type *elem_type = type->Array.elem; + if (type->kind == Type_Array) { + max_count = type->Array.count; + elem_type = type->Array.elem; + } else if (type->kind == Type_SimdVector) { + max_count = type->SimdVector.count; + elem_type = type->SimdVector.elem; + if (!build_context.use_llvm_api) { + error(call, "'swizzle' with #simd vector is not supported on this backend"); + } + } i64 arg_count = 0; for_array(i, ce->args) { -- cgit v1.2.3