mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Fix polymorphic matrix element with a minor hack
This commit is contained in:
@@ -287,10 +287,10 @@ array_cast :: proc(v: $A/[$N]$T, $Elem_Type: typeid) -> (w: [N]Elem_Type) #no_bo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix_cast :: proc(v: $A/[$M][$N]$T, $Elem_Type: typeid) -> (w: [M][N]Elem_Type) #no_bounds_check {
|
matrix_cast :: proc(v: $A/matrix[$M, $N]$T, $Elem_Type: typeid) -> (w: matrix[M, N]Elem_Type) #no_bounds_check {
|
||||||
for i in 0..<M {
|
for j in 0..<N {
|
||||||
for j in 0..<N {
|
for i in 0..<M {
|
||||||
w[i][j] = Elem_Type(v[i][j])
|
w[i, j] = Elem_Type(v[i, j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2284,10 +2284,21 @@ void check_matrix_type(CheckerContext *ctx, Type **type, Ast *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_type_valid_for_matrix_elems(elem)) {
|
if (!is_type_valid_for_matrix_elems(elem)) {
|
||||||
|
if (elem == t_typeid) {
|
||||||
|
Entity *e = entity_of_node(mt->elem);
|
||||||
|
if (e && e->kind == Entity_TypeName && e->TypeName.is_type_alias) {
|
||||||
|
// HACK TODO(bill): This is to allow polymorphic parameters for matrix elements
|
||||||
|
// proc($T: typeid) -> matrix[2, 2]T
|
||||||
|
//
|
||||||
|
// THIS IS NEEDS TO BE FIXED AND NOT USE THIS HACK
|
||||||
|
goto type_assign;
|
||||||
|
}
|
||||||
|
}
|
||||||
gbString s = type_to_string(elem);
|
gbString s = type_to_string(elem);
|
||||||
error(column.expr, "Matrix elements types are limited to integers, floats, and complex, got %s", s);
|
error(column.expr, "Matrix elements types are limited to integers, floats, and complex, got %s", s);
|
||||||
gb_string_free(s);
|
gb_string_free(s);
|
||||||
}
|
}
|
||||||
|
type_assign:;
|
||||||
|
|
||||||
*type = alloc_type_matrix(elem, row_count, column_count, generic_row, generic_column);
|
*type = alloc_type_matrix(elem, row_count, column_count, generic_row, generic_column);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user