diff options
| author | gingerBill <bill@gingerbill.org> | 2021-10-20 15:33:23 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-10-20 15:33:23 +0100 |
| commit | d3abc1a2b4fe024fed5f2b9f5371fc2b7fb029be (patch) | |
| tree | 2901f887403f103693868fc5862f2de30f69f099 /src/check_builtin.cpp | |
| parent | 465c87bd5a38488ae7b177a10ecf93f05ec18e9d (diff) | |
Add `matrix_flatten` - `matrix[R, C]T` -> `[R*C]T`
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index a9427d4e0..b60509c03 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -2131,6 +2131,36 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 break; } + case BuiltinProc_matrix_flatten: { + Operand x = {}; + check_expr(c, &x, ce->args[0]); + if (x.mode == Addressing_Invalid) { + return false; + } + if (!is_operand_value(x)) { + error(call, "'%.*s' expects a matrix or array", LIT(builtin_name)); + return false; + } + Type *t = base_type(x.type); + if (!is_type_matrix(t) && !is_type_array(t)) { + gbString s = type_to_string(x.type); + error(call, "'%.*s' expects a matrix or array, got %s", LIT(builtin_name), s); + gb_string_free(s); + return false; + } + + operand->mode = Addressing_Value; + if (is_type_array(t)) { + // Do nothing + operand->type = x.type; + } else { + GB_ASSERT(t->kind == Type_Matrix); + operand->type = alloc_type_array(t->Matrix.elem, t->Matrix.row_count*t->Matrix.column_count); + } + operand->type = check_matrix_type_hint(operand->type, type_hint); + break; + } + case BuiltinProc_simd_vector: { Operand x = {}; |