From 379637f214021c8f5c905872bc2a51892fc143c4 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 23 Jul 2024 12:22:31 +0200 Subject: [PATCH] Scalar -> vector not implicit in call or assign. --- lib/std/math/math_vector.c3 | 2 +- releasenotes.md | 2 + src/build/build.h | 8 ++ src/build/build_internal.h | 5 ++ src/build/build_options.c | 7 ++ src/build/builder.c | 1 + src/compiler/compiler_internal.h | 13 +++- src/compiler/sema_builtins.c | 44 +++++------ src/compiler/sema_casts.c | 30 ++++++-- src/compiler/sema_decls.c | 8 +- src/compiler/sema_expr.c | 76 +++++++++++-------- src/compiler/sema_initializers.c | 14 ++-- src/compiler/sema_stmts.c | 28 +++---- .../vector/vector_conversion_scalar.c3 | 14 ++++ 14 files changed, 159 insertions(+), 93 deletions(-) create mode 100644 test/test_suite/vector/vector_conversion_scalar.c3 diff --git a/lib/std/math/math_vector.c3 b/lib/std/math/math_vector.c3 index 5604e0624..5b8917fad 100644 --- a/lib/std/math/math_vector.c3 +++ b/lib/std/math/math_vector.c3 @@ -190,7 +190,7 @@ macro rotate_axis_angle(v, axis, angle) @private var w = axis * math::sin(angle); var wv = w.cross(v); var wwv = w.cross(wv); - wv *= math::cos(angle) * 2; + wv *= math::cos(($typeof(v))angle) * 2; wwv *= 2; return v + wv + wwv; diff --git a/releasenotes.md b/releasenotes.md index bf066e22f..23798f64b 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -5,6 +5,8 @@ ### Changes / improvements - Updated LLVM passes - Added `is_substruct` type property. +- Scalar -> vector not implicit in call or assign. +- Added `--vector-conv` to enable the old scalar->vector conversion behaviour. ### Fixes None diff --git a/src/build/build.h b/src/build/build.h index 34b707552..f06e97d04 100644 --- a/src/build/build.h +++ b/src/build/build.h @@ -278,6 +278,12 @@ typedef enum WIN_CRT_STATIC = 2, } WinCrtLinking; +typedef enum +{ + VECTOR_CONV_DEFAULT = 0, + VECTOR_CONV_OLD = 1, +} VectorConv; + typedef enum { RELOC_DEFAULT = -1, @@ -341,6 +347,7 @@ typedef struct BuildOptions_ const char* linker_libs[MAX_LIB_DIRS]; int linker_lib_count; const char* std_lib_dir; + VectorConv vector_conv; struct { const char *sdk; const char *def; @@ -515,6 +522,7 @@ typedef struct TrustLevel trust_level; OptimizationSetting optsetting; OptimizationLevel optlevel; + VectorConv vector_conv; MemoryEnvironment memory_environment; SizeOptimizationLevel optsize; SingleModule single_module; diff --git a/src/build/build_internal.h b/src/build/build_internal.h index 482a15e1b..88a53b2ee 100644 --- a/src/build/build_internal.h +++ b/src/build/build_internal.h @@ -27,6 +27,11 @@ static const char *wincrt_linking[3] = { [WIN_CRT_STATIC] = "static", }; +static const char *vector_conv[2] = { + [VECTOR_CONV_DEFAULT] = "default", + [VECTOR_CONV_OLD] = "old", +}; + static const char *optsizes[3] = { [SIZE_OPTIMIZATION_NONE] = "none", [SIZE_OPTIMIZATION_SMALL] = "small", diff --git a/src/build/build_options.c b/src/build/build_options.c index 1ebeed223..7d4f530d5 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -182,6 +182,8 @@ static void usage(void) PRINTF(""); PRINTF(" --linux-crt - Set the directory to use for finding crt1.o and related files."); PRINTF(" --linux-crtbegin - Set the directory to use for finding crtbegin.o and related files."); + PRINTF(""); + PRINTF(" --vector-conv=