Selaa lähdekoodia

Add intrinsics `type_is_matrix_row_major` & `type_is_matrix_column_major`

gingerBill 1 vuosi sitten
vanhempi
commit
5473758467
3 muutettua tiedostoa jossa 37 lisäystä ja 0 poistoa
  1. 3 0
      base/intrinsics/intrinsics.odin
  2. 28 0
      src/check_builtin.cpp
  3. 6 0
      src/checker_builtin_procs.hpp

+ 3 - 0
base/intrinsics/intrinsics.odin

@@ -167,6 +167,9 @@ type_is_matrix           :: proc($T: typeid) -> bool ---
 
 
 type_has_nil :: proc($T: typeid) -> bool ---
 type_has_nil :: proc($T: typeid) -> bool ---
 
 
+type_is_matrix_row_major    :: proc($T: typeid) -> bool where type_is_matrix(T) ---
+type_is_matrix_column_major :: proc($T: typeid) -> bool where type_is_matrix(T) ---
+
 type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
 type_is_specialization_of :: proc($T, $S: typeid) -> bool ---
 
 
 type_is_variant_of        :: proc($U, $V: typeid)          -> bool    where type_is_union(U) ---
 type_is_variant_of        :: proc($U, $V: typeid)          -> bool    where type_is_union(U) ---

+ 28 - 0
src/check_builtin.cpp

@@ -5221,6 +5221,34 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
 		operand->type = t_untyped_bool;
 		operand->type = t_untyped_bool;
 		break;
 		break;
 
 
+
+	case BuiltinProc_type_is_matrix_row_major:
+	case BuiltinProc_type_is_matrix_column_major:
+		{
+			Operand op = {};
+			Type *bt = check_type(c, ce->args[0]);
+			Type *type = base_type(bt);
+			if (type == nullptr || type == t_invalid) {
+				error(ce->args[0], "Expected a type for '%.*s'", LIT(builtin_name));
+				return false;
+			}
+			if (type->kind != Type_Matrix) {
+				gbString s = type_to_string(bt);
+				error(ce->args[0], "Expected a matrix type for '%.*s', got '%s'", LIT(builtin_name), s);
+				gb_string_free(s);
+				return false;
+			}
+
+			if (id == BuiltinProc_type_is_matrix_row_major) {
+				operand->value = exact_value_bool(bt->Matrix.is_row_major == true);
+			} else {
+				operand->value = exact_value_bool(bt->Matrix.is_row_major == false);
+			}
+			operand->mode = Addressing_Constant;
+			operand->type = t_untyped_bool;
+			break;
+		}
+
 	case BuiltinProc_type_has_field:
 	case BuiltinProc_type_has_field:
 		{
 		{
 			Operand op = {};
 			Operand op = {};

+ 6 - 0
src/checker_builtin_procs.hpp

@@ -256,6 +256,9 @@ BuiltinProc__type_simple_boolean_begin,
 
 
 BuiltinProc__type_simple_boolean_end,
 BuiltinProc__type_simple_boolean_end,
 
 
+	BuiltinProc_type_is_matrix_row_major,
+	BuiltinProc_type_is_matrix_column_major,
+
 	BuiltinProc_type_has_field,
 	BuiltinProc_type_has_field,
 	BuiltinProc_type_field_type,
 	BuiltinProc_type_field_type,
 
 
@@ -567,6 +570,9 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
 	{STR_LIT("type_has_nil"),              1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT("type_has_nil"),              1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
 	{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
 
 
+	{STR_LIT("type_is_matrix_row_major"),    1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
+	{STR_LIT("type_is_matrix_column_major"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
+
 	{STR_LIT("type_has_field"),            2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT("type_has_field"),            2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT("type_field_type"),           2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT("type_field_type"),           2, false, Expr_Expr, BuiltinProcPkg_intrinsics},